Class: Adcloud::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/adcloud/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

Returns the value of attribute client_id.



7
8
9
# File 'lib/adcloud/authentication.rb', line 7

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



7
8
9
# File 'lib/adcloud/authentication.rb', line 7

def client_secret
  @client_secret
end

#tokenObject

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