Class: Aspire::API::JSON
Overview
A wrapper class for the Aspire JSON API
Constant Summary collapse
- API_ROOT =
The default API root URL
"https://#{ASPIRE_DOMAIN}".freeze
- API_ROOT_AUTH =
The default authentication API root URL
"https://#{ASPIRE_AUTH_DOMAIN}/1/oauth/tokens".freeze
Constants inherited from Base
Base::ASPIRE_AUTH_DOMAIN, Base::ASPIRE_DOMAIN, Base::SCHEME, Base::SSL_OPTS, Base::TALIS_DOMAIN
Instance Attribute Summary collapse
-
#api_root ⇒ String
The base URL of the Aspire JSON APIs.
-
#api_root_auth ⇒ String
The base URL of the Aspire Persona authentication API.
-
#api_version ⇒ Integer
The version of the Aspire JSON APIs.
-
#rate_limit ⇒ Object
writeonly
Sets the attribute rate_limit.
-
#rate_remaining ⇒ Integer
The rate remaining value from the most recent API call (the number of calls remaining within the current limit period).
-
#rate_reset ⇒ Integer
The rate reset value from the most recent API call (the time in seconds since the Epoch until the next limit period).
Attributes inherited from Base
#logger, #ssl, #tenancy_code, #timeout
Instance Method Summary collapse
-
#api_url(path) ⇒ String
Returns a full Aspire JSON API URL.
-
#call(path, headers: nil, options: nil, payload: nil, **params) {|response, data| ... } ⇒ Hash
Calls an Aspire JSON API method and returns the parsed JSON response Additional keyword parameters are passed as query string parameters to the API call.
-
#initialize(api_client_id = nil, api_secret = nil, tenancy_code = nil, **opts) ⇒ void
constructor
Initialises a new API instance.
Constructor Details
#initialize(api_client_id = nil, api_secret = nil, tenancy_code = nil, **opts) ⇒ void
Initialises a new API instance
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/aspire/api/json.rb', line 53 def initialize(api_client_id = nil, api_secret = nil, tenancy_code = nil, **opts) super(tenancy_code, **opts) @api_client_id = api_client_id @api_secret = api_secret @api_token = nil self.api_root = opts[:api_root] || API_ROOT self.api_root_auth = opts[:api_root_auth] || API_ROOT_AUTH self.api_version = opts[:api_version] || 2 rate_limit end |
Instance Attribute Details
#api_root ⇒ String
Returns the base URL of the Aspire JSON APIs.
17 18 19 |
# File 'lib/aspire/api/json.rb', line 17 def api_root @api_root end |
#api_root_auth ⇒ String
Returns the base URL of the Aspire Persona authentication API.
21 22 23 |
# File 'lib/aspire/api/json.rb', line 21 def api_root_auth @api_root_auth end |
#api_version ⇒ Integer
Returns the version of the Aspire JSON APIs.
25 26 27 |
# File 'lib/aspire/api/json.rb', line 25 def api_version @api_version end |
#rate_limit=(value) ⇒ Object
Sets the attribute rate_limit
29 30 31 |
# File 'lib/aspire/api/json.rb', line 29 def rate_limit @rate_limit end |
#rate_remaining ⇒ Integer
Returns the rate remaining value from the most recent API call (the number of calls remaining within the current limit period).
34 35 36 |
# File 'lib/aspire/api/json.rb', line 34 def rate_remaining @rate_remaining end |
#rate_reset ⇒ Integer
Returns the rate reset value from the most recent API call (the time in seconds since the Epoch until the next limit period).
39 40 41 |
# File 'lib/aspire/api/json.rb', line 39 def rate_reset @rate_reset end |
Instance Method Details
#api_url(path) ⇒ String
Returns a full Aspire JSON API URL. Full URLs are returned as-is, partial endpoint paths are expanded with the API root, version and tenancy code.
70 71 72 73 |
# File 'lib/aspire/api/json.rb', line 70 def api_url(path) return path if path.include?('//') "#{api_root}/#{api_version}/#{tenancy_code}/#{path}" end |
#call(path, headers: nil, options: nil, payload: nil, **params) {|response, data| ... } ⇒ Hash
Calls an Aspire JSON API method and returns the parsed JSON response Additional keyword parameters are passed as query string parameters to the API call.
87 88 89 90 91 92 93 94 |
# File 'lib/aspire/api/json.rb', line 87 def call(path, headers: nil, options: nil, payload: nil, **params) = (path, headers: headers, options: , payload: payload, params: params) response, data = call_api_with_auth(**) yield(response, data) if block_given? data end |