Class: RememberTheRuby::RPC::Transport
- Inherits:
-
Object
- Object
- RememberTheRuby::RPC::Transport
- Defined in:
- lib/remember-the-ruby/rpc.rb
Constant Summary collapse
- TRANSPORT_URI =
'http://api.rememberthemilk.com'
Instance Attribute Summary collapse
-
#frob ⇒ Object
Returns the value of attribute frob.
-
#key ⇒ Object
Returns the value of attribute key.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#auth ⇒ Object
rpc types ###############################################################.
- #auth_path(params) ⇒ Object
-
#build_transport_http ⇒ Object
private #################################################################.
- #clear_empty_parameters(params) ⇒ Object
- #flatten_parameters(params) ⇒ Object
- #hash_from_element(element) ⇒ Object
-
#initialize(params) ⇒ Transport
constructor
A new instance of Transport.
- #lists ⇒ Object
- #request(method, params = {}) ⇒ Object
- #rest_path(params) ⇒ Object
- #service_path(service, params) ⇒ Object
- #settings ⇒ Object
- #sign_parameters(params) ⇒ Object
- #tasks ⇒ Object
- #timeline ⇒ Object
Constructor Details
#initialize(params) ⇒ Transport
Returns a new instance of Transport.
14 15 16 17 18 19 20 21 |
# File 'lib/remember-the-ruby/rpc.rb', line 14 def initialize(params) @key = params[:key] @secret = params[:secret] @frob = params[:frob] @token = params[:token] @transport_http = build_transport_http end |
Instance Attribute Details
#frob ⇒ Object
Returns the value of attribute frob.
12 13 14 |
# File 'lib/remember-the-ruby/rpc.rb', line 12 def frob @frob end |
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/remember-the-ruby/rpc.rb', line 12 def key @key end |
#secret ⇒ Object
Returns the value of attribute secret.
12 13 14 |
# File 'lib/remember-the-ruby/rpc.rb', line 12 def secret @secret end |
#token ⇒ Object
Returns the value of attribute token.
12 13 14 |
# File 'lib/remember-the-ruby/rpc.rb', line 12 def token @token end |
Instance Method Details
#auth ⇒ Object
rpc types ###############################################################
37 38 39 |
# File 'lib/remember-the-ruby/rpc.rb', line 37 def auth @auth ||= Auth.new(self) end |
#auth_path(params) ⇒ Object
70 71 72 |
# File 'lib/remember-the-ruby/rpc.rb', line 70 def auth_path(params) self.service_path('auth', params) end |
#build_transport_http ⇒ Object
private #################################################################
59 60 61 62 |
# File 'lib/remember-the-ruby/rpc.rb', line 59 def build_transport_http uri = URI::parse(TRANSPORT_URI) @transport_http = Net::HTTP.start(uri.host, uri.port) end |
#clear_empty_parameters(params) ⇒ Object
64 65 66 67 68 |
# File 'lib/remember-the-ruby/rpc.rb', line 64 def clear_empty_parameters(params) params.dup.each do |k, v| params.delete(k) if v.nil? || v == '' end end |
#flatten_parameters(params) ⇒ Object
95 96 97 |
# File 'lib/remember-the-ruby/rpc.rb', line 95 def flatten_parameters(params) params.map { |k, v| [k, v].join('=') }.join('&') end |
#hash_from_element(element) ⇒ Object
99 100 101 |
# File 'lib/remember-the-ruby/rpc.rb', line 99 def hash_from_element(element) element.attributes end |
#lists ⇒ Object
41 42 43 |
# File 'lib/remember-the-ruby/rpc.rb', line 41 def lists @lists ||= Lists.new(self) end |
#request(method, params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/remember-the-ruby/rpc.rb', line 25 def request(method, params={}) params[:method] = method uri = URI.encode(rest_path(params)) data = @transport_http.get(uri) doc = REXML::Document.new(data.body) doc.elements['rsp'] end |
#rest_path(params) ⇒ Object
74 75 76 |
# File 'lib/remember-the-ruby/rpc.rb', line 74 def rest_path(params) self.service_path('rest', params) end |
#service_path(service, params) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/remember-the-ruby/rpc.rb', line 78 def service_path(service, params) params[:frob] ||= @frob params[:api_key] ||= @key params[:auth_token] ||= @token clear_empty_parameters(params) params[:api_sig] = sign_parameters(params) "/services/#{service}/?#{flatten_parameters(params)}" end |
#settings ⇒ Object
45 46 47 |
# File 'lib/remember-the-ruby/rpc.rb', line 45 def settings @settings ||= Settings.new(self) end |
#sign_parameters(params) ⇒ Object
89 90 91 92 93 |
# File 'lib/remember-the-ruby/rpc.rb', line 89 def sign_parameters(params) signature = @secret signature += params.map { |k, v| [k, v].join('') }.sort.join('') Digest::MD5.hexdigest(signature) end |
#tasks ⇒ Object
49 50 51 |
# File 'lib/remember-the-ruby/rpc.rb', line 49 def tasks @tasks ||= Tasks.new(self) end |
#timeline ⇒ Object
53 54 55 |
# File 'lib/remember-the-ruby/rpc.rb', line 53 def timeline Timelines.new(self).create end |