Class: Sayso
- Inherits:
-
Object
- Object
- Sayso
- Defined in:
- lib/sayso.rb
Overview
sayso.get(“/users/current”)
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#request_token ⇒ Object
readonly
Returns the value of attribute request_token.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#authorize_access_token(oauth_verifier) ⇒ Object
Go to the given url (see authorize_url) and you get redirected to, eg: localhost:3000/?oauth_token=DGJb7aPa1XrY82a8hmJVp6IbF0qLZ9Je0pO4B7qF&oauth_verifier=iWhKZfIjPDjozBRhSDoA Call this method with the correct oauth_verifier as argument.
-
#authorize_url ⇒ Object
Returns the url where to send the user to authenticate himself.
-
#get(path, params = {}) ⇒ Object
Gets from the Sayso API and returns the parsed XML.
-
#initialize(options = {}) ⇒ Sayso
constructor
A new instance of Sayso.
- #initialize_access_token ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Sayso
Returns a new instance of Sayso.
18 19 20 21 22 23 24 |
# File 'lib/sayso.rb', line 18 def initialize( = {}) = {:version => 1, :base_url => 'http://api.sayso.com', :callback => nil}.merge() .each do |attr, value| instance_variable_set(:"@#{attr}", value) end self.initialize_access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
16 17 18 |
# File 'lib/sayso.rb', line 16 def access_token @access_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/sayso.rb', line 15 def base_url @base_url end |
#callback ⇒ Object
Returns the value of attribute callback.
15 16 17 |
# File 'lib/sayso.rb', line 15 def callback @callback end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
15 16 17 |
# File 'lib/sayso.rb', line 15 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
15 16 17 |
# File 'lib/sayso.rb', line 15 def consumer_secret @consumer_secret end |
#request_token ⇒ Object (readonly)
Returns the value of attribute request_token.
16 17 18 |
# File 'lib/sayso.rb', line 16 def request_token @request_token end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/sayso.rb', line 16 def response @response end |
#version ⇒ Object
Returns the value of attribute version.
15 16 17 |
# File 'lib/sayso.rb', line 15 def version @version end |
Instance Method Details
#authorize_access_token(oauth_verifier) ⇒ Object
Go to the given url (see authorize_url) and you get redirected to, eg:
http://localhost:3000/?oauth_token=DGJb7aPa1XrY82a8hmJVp6IbF0qLZ9Je0pO4B7qF&oauth_verifier=iWhKZfIjPDjozBRhSDoA
Call this method with the correct oauth_verifier as argument.
48 49 50 |
# File 'lib/sayso.rb', line 48 def (oauth_verifier) @access_token = @request_token.get_access_token(:oauth_verifier => oauth_verifier) end |
#authorize_url ⇒ Object
Returns the url where to send the user to authenticate himself. After this call the authorize_access_token method to authenticate the session and be able to use write access and current_user methods.
41 42 43 |
# File 'lib/sayso.rb', line 41 def @request_token. end |
#get(path, params = {}) ⇒ Object
Gets from the Sayso API and returns the parsed XML. Access the unparsed response using the response method. Examples:
get("/places/search?what=restaurant&where=antwerpen")
56 57 58 59 60 61 62 |
# File 'lib/sayso.rb', line 56 def get(path, params = {}) path = "/api#{self.version}#{path}" path += "?#{params.to_query}" unless params.blank? @response = @access_token.get(path) result = Crack::XML.parse(@response.body) HashWithIndifferentAccess.new(result) end |
#initialize_access_token ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sayso.rb', line 26 def initialize_access_token return @access_token unless @access_token.nil? @consumer = OAuth::Consumer.new(self.consumer_key, self.consumer_secret, { :site => self.base_url, :request_token_path => "/api#{self.version}/oauth/request_token", :authorize_path => "/api#{self.version}/oauth/authorize", :access_token_path => "/api#{self.version}/oauth/access_token" }) @request_token = @consumer.get_request_token(:oauth_callback => "http://localhost:3000") # Just make it using the request token (and a user that has given access ?!) @access_token = OAuth::AccessToken.new(@consumer, @request_token.token, @request_token.secret) end |