Class: Client
- Inherits:
-
Object
- Object
- Client
- Defined in:
- lib/client/client.rb
Constant Summary collapse
- @@bearer_token_retrieve_time =
3300
Instance Attribute Summary collapse
-
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#password ⇒ Object
Returns the value of attribute password.
-
#security_token ⇒ Object
Returns the value of attribute security_token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#retrieve_and_refresh_bearer_token ⇒ Object
def init(instance, client_id, client_secret, username, password, security_token) unless instance.nil? or client_id.nil? or client_secret.nil? or usenrame.nil? or password.nil? or security_token.nil? @instance = instance @client_id = client_id @client_secret = client_secret @username = username @password = password @security_token = security_token else raise “Unable to instantiate a client - instance, client_id, client_secret, username, password, or security_token are nil.” end.
Instance Attribute Details
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
3 4 5 |
# File 'lib/client/client.rb', line 3 def bearer_token @bearer_token end |
#client_id ⇒ Object
Returns the value of attribute client_id.
3 4 5 |
# File 'lib/client/client.rb', line 3 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
3 4 5 |
# File 'lib/client/client.rb', line 3 def client_secret @client_secret end |
#instance ⇒ Object
Returns the value of attribute instance.
3 4 5 |
# File 'lib/client/client.rb', line 3 def instance @instance end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/client/client.rb', line 3 def password @password end |
#security_token ⇒ Object
Returns the value of attribute security_token.
3 4 5 |
# File 'lib/client/client.rb', line 3 def security_token @security_token end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/client/client.rb', line 3 def username @username end |
Instance Method Details
#retrieve_and_refresh_bearer_token ⇒ Object
def init(instance, client_id, client_secret, username, password, security_token)
unless instance.nil? or client_id.nil? or client_secret.nil? or usenrame.nil? or password.nil? or security_token.nil?
@instance = instance
@client_id = client_id
@client_secret = client_secret
@username = username
@password = password
@security_token = security_token
else
raise "Unable to instantiate a client - instance, client_id, client_secret, username, password, or security_token are nil."
end
retrieve_and_refresh_bearer_token
end
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/client/client.rb', line 26 def retrieve_and_refresh_bearer_token oauth_url = "https://%s.salesforce.com/services/oauth2/token" % [@instance] data = { "grant_type": "password", "client_id": @client_id, "client_secret": @client_secret, "username": @username, "password": "%s%s" % [@password, @security_token] } response = RestClient.post oauth_url, data response_json = JSON.parse(response.body) @bearer_token = response_json["access_token"] end |