Created
July 19, 2010 19:54
-
-
Save necrodome/481902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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