Class: Adcloud::Authentication
- Inherits:
-
Object
- Object
- Adcloud::Authentication
- Defined in:
- lib/adcloud/authentication.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #authenticate! ⇒ Object
-
#initialize(attr) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(attr) ⇒ Authentication
Returns a new instance of Authentication.
9 10 11 12 |
# File 'lib/adcloud/authentication.rb', line 9 def initialize(attr) @client_id = attr[:client_id] @client_secret = attr[:client_secret] end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/adcloud/authentication.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/adcloud/authentication.rb', line 7 def client_secret @client_secret end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/adcloud/authentication.rb', line 7 def token @token end |
Instance Method Details
#authenticate! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/adcloud/authentication.rb', line 14 def authenticate! response = Connection.new.connection(false).post "oauth/access_token", {:client_id => self.client_id, :client_secret => self.client_secret, :grant_type => "none"} if response.success? @token = response.body['_meta']["access_token"] else raise AuthenticationError.new(@client_id => "Could not authenticate") end end |