Posted by Dan Sosedoff
on January 25, 2011
Need to figure out closed/private API? Not a problem. Its always fun and challenging. There are few tools i use for that:
Proxie is another project of mine, which i finally extracted from a script written a while ago and published it as a ruby gem.
I used it to track Grooveshark API and it worked out great. Here is the list of features:
- Bind proxy server to any port (default is 8080)
- Define output database. It uses SQLite3 by default, but you can extend it with any other types
- Sinatra-base web interface to browse all your collected data
Installation:
Start a server:
After data collection just run:
The web interface runs on localhost:4567 by default.
Usage summary:
Usage: proxie [options]
-i, --info Display this information.
-p, --port PORT Listen on port (8080 default)
-d, --db NAME Store results to database
-w, --web Start a Web UI for databases
-f, --flush Delete all local databases
Project on GitHub: http://github.com/sosedoff/proxie
Posted by Dan Sosedoff
on January 23, 2011
ActiveResource is a perfect tool to consume API’s based on Rails. Most examples are pretty much simple and understandable. But i got really confused with the way to get a single resource.
Example use case
I was working with Unfuddle API recently, and i needed to fetch account information. So, basically, core url is like this:
http://subdomain.unfuddle.com/api/v1
And for account:
http://subdomain.unfuddle.com/api/v1/account
Resources:
# api base for all resources
class APIBase < ActiveResource::Base
self.site = "http://subdomain.unfuddle.com/api/v1"
self.format = :json
self.user = 'YOUR_USERNAME'
self.password = 'YOUR_PASSWORD'
# for debug purposes you can setup logger
self.logger = LOGGER_CLASS
end
class Account < APIBase ; end
class Repository < APIBase ; end
To get all repositories you call as usual:
repos = Repository.all
# this will fetch URL_BASE/repositories.json
But account resource is a single resource, to fetch it you need to make a call like this:
# this will produce invalid url: /accounts
acc = Account.find(:one)
# and this is a correct way
acc = Account.find(:one, :from => '/account')
I wasted around 20 mins to figure out how to do that. This should be mentioned in the docs.
Posted by Dan Sosedoff
on September 30, 2010
I really like public paste service – pastie.org. Too bad it does not have public API.
The most common user case for me – drop some files. 1 or 2 usually. So i have to copy and paste file contents into the form, select private and then send link to someone. Too many actions i think.
I decided to spend some time and create console tool and simplified api based on html extractions.
Source: http://github.com/sosedoff/pastie
Just install it:
$ sudo gem install pastie-api
And use it (multiple files are supported):
$ pastie file
$ pastie file1 file2 ... fileN
Also, API access:
require 'rubygems'
require 'pastie-api'
# Create a new private paste
p = Pastie.create('Test string')
# Create a new public paste
p = Pastie.create('Hello!', false)
# View paste details
puts "Paste ID: #{p.id}"
puts "Paste Key: #{p.key}"
puts "URL: #{p.link}"
puts "Raw link: #{p.raw_link}"
# Find existing paste
p = Pastie.get(1234567) # find by paste's ID
p = Pastie.get('abcdefabcdef') # find by paste's private code
Planning to add local pastes history and auto-paste from clipboard.