Class: Boomloop::Authentication::Client
- Inherits:
-
Object
- Object
- Boomloop::Authentication::Client
- Defined in:
- lib/boomloop/authentication/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#consumer ⇒ Object
Returns the value of attribute consumer.
-
#request_token ⇒ Object
Returns the value of attribute request_token.
-
#store ⇒ Object
Returns the value of attribute store.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #activate ⇒ Object
- #connect ⇒ Object
- #consume(key, secret) ⇒ Object
- #create_accesstoken ⇒ Object
- #create_consumer(key, secret) ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize(user, store) ⇒ Client
constructor
A new instance of Client.
- #post(url, params = "", headers = {}) ⇒ Object
- #raise_error_if_not_authenticated(credentials) ⇒ Object
Constructor Details
#initialize(user, store) ⇒ Client
Returns a new instance of Client.
32 33 34 35 |
# File 'lib/boomloop/authentication/client.rb', line 32 def initialize(user, store) self.user = user self.store = store end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
21 22 23 |
# File 'lib/boomloop/authentication/client.rb', line 21 def access_token @access_token end |
#connection ⇒ Object
Returns the value of attribute connection.
22 23 24 |
# File 'lib/boomloop/authentication/client.rb', line 22 def connection @connection end |
#consumer ⇒ Object
Returns the value of attribute consumer.
21 22 23 |
# File 'lib/boomloop/authentication/client.rb', line 21 def consumer @consumer end |
#request_token ⇒ Object
Returns the value of attribute request_token.
21 22 23 |
# File 'lib/boomloop/authentication/client.rb', line 21 def request_token @request_token end |
#store ⇒ Object
Returns the value of attribute store.
20 21 22 |
# File 'lib/boomloop/authentication/client.rb', line 20 def store @store end |
#user ⇒ Object
Returns the value of attribute user.
20 21 22 |
# File 'lib/boomloop/authentication/client.rb', line 20 def user @user end |
Instance Method Details
#activate ⇒ Object
44 45 46 47 48 49 |
# File 'lib/boomloop/authentication/client.rb', line 44 def activate if self.request_token self.access_token = self.request_token.get_access_token self.store.find(user).update(:access_key => self.access_token.token, :access_secret => self.access_token.secret) end end |
#connect ⇒ Object
28 29 30 |
# File 'lib/boomloop/authentication/client.rb', line 28 def connect @connection ||= create_accesstoken end |
#consume(key, secret) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/boomloop/authentication/client.rb', line 37 def consume(key, secret) self.create_consumer(key, secret) self.request_token = self.consumer.get_request_token self.store.find(user).update(:consumer_key => key, :consumer_secret => secret) self.request_token end |
#create_accesstoken ⇒ Object
55 56 57 58 59 60 |
# File 'lib/boomloop/authentication/client.rb', line 55 def create_accesstoken credentials = self.store.find(self.user) raise_error_if_not_authenticated(credentials) self.consumer ||= create_consumer(credentials[:consumer_key], credentials[:consumer_secret]) self.access_token ||= OAuth::AccessToken.new(self.consumer, credentials[:access_key], credentials[:access_secret]) end |
#create_consumer(key, secret) ⇒ Object
51 52 53 |
# File 'lib/boomloop/authentication/client.rb', line 51 def create_consumer(key, secret) self.consumer = OAuth::Consumer.new(key, secret, { :site => Boomloop::Resources::Base.api_base }) end |
#get(url, options = {}) ⇒ Object
62 63 64 |
# File 'lib/boomloop/authentication/client.rb', line 62 def get(url, = {}) connection.get(url, .merge({ "X-Consumer-Key" => self.consumer.key })) end |
#post(url, params = "", headers = {}) ⇒ Object
66 67 68 |
# File 'lib/boomloop/authentication/client.rb', line 66 def post(url, params = "", headers = {}) connection.post(url, params, { "X-Consumer-Key" => self.consumer.key, 'Accept'=>'application/xml', 'Content-Type' => 'application/xml' }.merge(headers)) end |
#raise_error_if_not_authenticated(credentials) ⇒ Object
70 71 72 |
# File 'lib/boomloop/authentication/client.rb', line 70 def raise_error_if_not_authenticated(credentials) raise Boomloop::ApiError.new("You need to authenticate the api before getting an access token. Do this by running the command 'boomloop'") unless credentials[:consumer_secret] end |