class RTM::API

API class

Constants

AUTH_PATH
PERMS
REST_PATH
RTM_DOMAIN

Public Class Methods

auth_host() click to toggle source
# File lib/rtmilk/api.rb, line 29
def API.auth_host
  'http://www.' + RTM_DOMAIN
end
get_auth_url(perms, frob=nil) click to toggle source

get Auth URL (both desktop/webapp)

# File lib/rtmilk/api.rb, line 67
def API.get_auth_url(perms, frob=nil)
   param = { :api_key => @@key, :perms => perms }
   if frob
      param['frob'] = frob
   end

   sig = API.sign(param)

   r  = [auth_host, AUTH_PATH].join + '?'
   r += param.collect { |k, v| [k, v].join('=') }.sort.join('&')
   r += '&api_sig=' + sig
   r
end
init(key, sec, option=nil) click to toggle source

initialize the API context.

# File lib/rtmilk/api.rb, line 34
def API.init(key, sec, option=nil)
   @@key = key
   @@sec = sec

   if (option)
      begin
         @@token = option[:token] if option.has_key? :token
      rescue => e
         puts e.message
      end
   end

end
key() click to toggle source

getter methods

# File lib/rtmilk/api.rb, line 53
def API.key; @@key; end
new(method, token=nil, timeline=nil) click to toggle source
# File lib/rtmilk/api.rb, line 93
def initialize(method, token=nil, timeline=nil)
   @method   = method
   @token    = token ? token : nil
   @timeline = timeline ? timeline : nil
   @param = {}
end
token() click to toggle source
# File lib/rtmilk/api.rb, line 54
def API.token; @@token; end
token=(token) click to toggle source
# File lib/rtmilk/api.rb, line 48
def API.token=(token)
   @@token = token
end

Private Class Methods

sign(param) click to toggle source

sign parameters

# File lib/rtmilk/api.rb, line 87
def API.sign(param)
   sig = @@sec
   sig += param.collect { |k, v| [k, v].join('') }.sort.join('')
   Digest::MD5.hexdigest(sig)
end

Public Instance Methods

api_host() click to toggle source
# File lib/rtmilk/api.rb, line 25
def api_host
  'https://api.' + RTM_DOMAIN
end
invoke() click to toggle source

invoke a method

# File lib/rtmilk/api.rb, line 57
def invoke
   response = URI.join(api_host, make_url).read
   # puts '--------------------------------------------------'
   # puts response
   # puts '--------------------------------------------------'
   result = XmlSimple.new.xml_in(response)
   ret = parse_result(result)
end
sign() click to toggle source
# File lib/rtmilk/api.rb, line 81
def sign
   API.sign(@param)
end

Protected Instance Methods

parse_result(result) click to toggle source

parse result

# File lib/rtmilk/api.rb, line 115
def parse_result(result)
   unless result['stat'] == 'ok'
      raise RTM::Error, result['err'].first['msg']
   end
end

Private Instance Methods

make_url() click to toggle source
# File lib/rtmilk/api.rb, line 100
def make_url
   r  = REST_PATH + '?' 

   @param = {} if @param == nil
   @param['method'] = @method
   @param['auth_token'] = @token unless @token == nil
   @param['timeline'] = @timeline unless @timeline == nil
   @param['api_key'] = @@key
   r += @param.collect { |k, v| [k, v].join('=') }.sort.join('&')
   r += '&api_sig=' + sign
   URI.escape r
end