Class: CurrencyCloud::Session
- Inherits:
-
Object
- Object
- CurrencyCloud::Session
- Defined in:
- lib/currency_cloud/session.rb
Constant Summary collapse
- ENVIRONMENTS =
{ production: 'https://api.currencycloud.com', demonstration: 'https://devapi.currencycloud.com', uat: 'https://api-uat1.ccycloud.com' }.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#login_id ⇒ Object
readonly
Returns the value of attribute login_id.
-
#on_behalf_of ⇒ Object
Returns the value of attribute on_behalf_of.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate ⇒ Object
- #close ⇒ Object
- #environment_url ⇒ Object
-
#initialize(environment, login_id, api_key, token) ⇒ Session
constructor
A new instance of Session.
- #reauthenticate ⇒ Object
Constructor Details
#initialize(environment, login_id, api_key, token) ⇒ Session
Returns a new instance of Session.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/currency_cloud/session.rb', line 17 def initialize(environment, login_id, api_key, token) @environment = environment @login_id = login_id @api_key = api_key if token self.class.validate_environment(environment) @token = token else authenticate end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/currency_cloud/session.rb', line 9 def api_key @api_key end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
9 10 11 |
# File 'lib/currency_cloud/session.rb', line 9 def environment @environment end |
#login_id ⇒ Object (readonly)
Returns the value of attribute login_id.
9 10 11 |
# File 'lib/currency_cloud/session.rb', line 9 def login_id @login_id end |
#on_behalf_of ⇒ Object
Returns the value of attribute on_behalf_of.
10 11 12 |
# File 'lib/currency_cloud/session.rb', line 10 def on_behalf_of @on_behalf_of end |
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/currency_cloud/session.rb', line 10 def token @token end |
Class Method Details
.validate_environment(environment) ⇒ Object
12 13 14 15 |
# File 'lib/currency_cloud/session.rb', line 12 def self.validate_environment(environment) return if ENVIRONMENTS.key?(environment) raise "'#{environment}' is not a valid environment. Must be one of: #{ENVIRONMENTS.keys.join(', ')}" end |
Instance Method Details
#authenticate ⇒ Object
38 39 40 41 42 |
# File 'lib/currency_cloud/session.rb', line 38 def authenticate validate params = { login_id: login_id, api_key: api_key } CurrencyCloud.token = @token = request.post('authenticate/api', params, should_retry: false)['auth_token'] end |
#close ⇒ Object
34 35 36 |
# File 'lib/currency_cloud/session.rb', line 34 def close request.post('authenticate/close_session') end |
#environment_url ⇒ Object
30 31 32 |
# File 'lib/currency_cloud/session.rb', line 30 def environment_url ENVIRONMENTS[environment] end |
#reauthenticate ⇒ Object
44 45 46 47 |
# File 'lib/currency_cloud/session.rb', line 44 def reauthenticate CurrencyCloud.token = @token = nil authenticate end |