Skip to content

Instantly share code, notes, and snippets.

@necrodome
Created July 19, 2010 19:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save necrodome/481902 to your computer and use it in GitHub Desktop.
Save necrodome/481902 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'json'
# sudo gem install json
# Usage example:
# putio = Putio.new("YOUR_API_KEY","YOUR_API_SECRET")
# puts JSON.parse(putio.user.friends.get)
# puts JSON.parse(putio.search :query => "massive attack"
class Putio
attr_accessor :proxy,:api_key,:api_secret
END_POINT = 'http://api.put.io/v1/%s'
def initialize(api_key,api_secret)
@api_key, @api_secret = api_key,api_secret
@proxy = Array.new
end
def method_missing(method, *args)
@proxy << method.to_s
if args.size > 0 || method.to_s.eql?("get")
endpoint = sprintf(END_POINT, @proxy[0])
res = Net::HTTP.post_form(URI.parse(endpoint),
{ 'method' => @proxy[1],
'request' => JSON.generate({:api_key => @api_key,
:api_secret => @api_secret,
:params => args.size == 0 ? Hash.new : args[0] })
})
@proxy = Array.new
res.body
else
self
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment