Class: Finnegans::Client
- Inherits:
-
Object
- Object
- Finnegans::Client
- Defined in:
- lib/finnegans/client.rb
Instance Attribute Summary collapse
-
#api_catalog_path ⇒ Object
readonly
Returns the value of attribute api_catalog_path.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #catalog_detail(id) ⇒ Object
-
#initialize(client_id:, client_secret:, base_url:, access_token: nil, api_catalog_path: Finnegans.api_catalog_path, namespace: Finnegans.resources_namespace) ⇒ Client
constructor
A new instance of Client.
- #initialize_namespaced_resources(refresh: false) ⇒ Object
- #inspect ⇒ Object
- #request(resource, request_params = {}) ⇒ Object
Constructor Details
#initialize(client_id:, client_secret:, base_url:, access_token: nil, api_catalog_path: Finnegans.api_catalog_path, namespace: Finnegans.resources_namespace) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/finnegans/client.rb', line 11 def initialize(client_id:, client_secret:, base_url:, access_token: nil, api_catalog_path: Finnegans.api_catalog_path, namespace: Finnegans.resources_namespace) @client_id = client_id.to_s @client_secret = client_secret.to_s @base_url = base_url.to_s.gsub(/\/+$/, '') @access_token = access_token @api_catalog_path = api_catalog_path namespace = namespace.to_s @namespace = (namespace.empty? ? nil : namespace) self end |
Instance Attribute Details
#api_catalog_path ⇒ Object (readonly)
Returns the value of attribute api_catalog_path.
9 10 11 |
# File 'lib/finnegans/client.rb', line 9 def api_catalog_path @api_catalog_path end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/finnegans/client.rb', line 9 def base_url @base_url end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/finnegans/client.rb', line 9 def client_id @client_id end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
9 10 11 |
# File 'lib/finnegans/client.rb', line 9 def namespace @namespace end |
Instance Method Details
#catalog_detail(id) ⇒ Object
53 54 55 |
# File 'lib/finnegans/client.rb', line 53 def catalog_detail(id) request("/#{@api_catalog_path}/#{id}") end |
#initialize_namespaced_resources(refresh: false) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/finnegans/client.rb', line 28 def initialize_namespaced_resources(refresh: false) remove_previous_resources if refresh _namespaced_catalog = namespaced_catalog(refresh: refresh) _namespaced_catalog.each do |catalog_item| define_resource(catalog_item) end end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/finnegans/client.rb', line 24 def inspect self end |
#request(resource, request_params = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/finnegans/client.rb', line 38 def request(resource, request_params = {}) unless request_params.is_a?(Hash) raise ArgumentError, 'The second argument in the :request must be a Hash ({}) ' \ 'or nil. Definition -> request(resource, request_params = {})' end authenticated_request do request_params[:params] = (request_params[:params] || {}).merge(authenticated_param) response = request_call(resource, request_params) body = json_load(response.body) response.success? ? body : (raise RequestError.new(body), body['error']) end end |