Skip to content

Instantly share code, notes, and snippets.

@kkung
Created September 29, 2010 01:51
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 kkung/602169 to your computer and use it in GitHub Desktop.
Save kkung/602169 to your computer and use it in GitHub Desktop.
The world smallest me2DAY API client library in ruby =3
require 'httparty'
class Me2dayApi
include HTTParty
base_uri 'me2day.net'
def initialize(appkey)
self.class.default_params :akey => appkey
end
def auth!(id,key)
nonces = Digest::MD5.hexdigest(rand.to_s)[0...8]
ukey = [ nonces, Digest::MD5.hexdigest("#{nonces}#{key}") ].join.to_s
self.class.default_params :uid => id, :ukey => ukey
end
def method_missing(meth, *args, &blk)
api_method = "/api/#{meth}"
api_method << "/" << args.shift if args.first.kind_of? String
api_method << ".xml"
options = {:query => {}}
args.each { |arg| options[:query].merge!(arg) }
if meth =~ /^create/
self.class.send(:post, api_method, options)
else
self.class.send(:get, api_method, options)
end
end
end
require 'me2day_api'
ME2DAY_APP_KEY = "ilovejb" #your application's key
api = Me2dayAPI.new(ME2DAY_APP_KEY)
posts = api.get_posts("kkung")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment