Class: Octoparts::Client
- Inherits:
-
Object
- Object
- Octoparts::Client
- Defined in:
- lib/octoparts/client.rb
Constant Summary collapse
- OCTOPARTS_API_ENDPOINT_PATH =
'/octoparts/2'
- CACHE_API_ENDPOINT_PATH =
"#{OCTOPARTS_API_ENDPOINT_PATH}/cache"
Instance Method Summary collapse
- #get(path, params = {}, headers = {}) ⇒ Object
-
#initialize(endpoint: nil, headers: {}, timeout_sec: nil, open_timeout_sec: nil) ⇒ Client
constructor
A new instance of Client.
-
#invalidate_cache(part_id, param_name: nil, param_value: nil) ⇒ Object
TODO: doc.
-
#invalidate_cache_group(cache_group_name, param_value: nil) ⇒ Object
TODO: doc.
-
#invoke(params) ⇒ Octoparts::Response
Post an AggregateRequest and return AggregateResponse.
- #post(path, body = nil, headers = {}) ⇒ Object
Constructor Details
#initialize(endpoint: nil, headers: {}, timeout_sec: nil, open_timeout_sec: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/octoparts/client.rb', line 9 def initialize(endpoint: nil, headers: {}, timeout_sec: nil, open_timeout_sec: nil) @endpoint = endpoint || Octoparts.configuration.endpoint @timeout_sec = timeout_sec || Octoparts.configuration.timeout_sec @open_timeout_sec = open_timeout_sec || Octoparts.configuration.open_timeout_sec @headers = Octoparts.configuration.headers.merge(headers) end |
Instance Method Details
#get(path, params = {}, headers = {}) ⇒ Object
16 17 18 |
# File 'lib/octoparts/client.rb', line 16 def get(path, params = {}, headers = {}) process(:get, path, params, nil, headers) end |
#invalidate_cache(part_id, param_name: nil, param_value: nil) ⇒ Object
TODO: doc
39 40 41 42 43 44 45 46 |
# File 'lib/octoparts/client.rb', line 39 def invalidate_cache(part_id, param_name: nil, param_value: nil) cache_path = if param_name "/invalidate/part/#{part_id}/#{param_name}/#{param_value}" else "/invalidate/part/#{part_id}" end post_cache_api(cache_path) end |
#invalidate_cache_group(cache_group_name, param_value: nil) ⇒ Object
TODO: doc
49 50 51 52 53 54 55 56 |
# File 'lib/octoparts/client.rb', line 49 def invalidate_cache_group(cache_group_name, param_value: nil) cache_path = if param_value "/invalidate/cache-group/#{cache_group_name}/params/#{param_value}" else "/invalidate/cache-group/#{cache_group_name}/parts" end post_cache_api(cache_path) end |
#invoke(params) ⇒ Octoparts::Response
Post an AggregateRequest and return AggregateResponse.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/octoparts/client.rb', line 27 def invoke(params) body = create_request_body(params) headers = { content_type: 'application/json' } resp = post(OCTOPARTS_API_ENDPOINT_PATH, body, headers) Response.new( Model::AggregateResponse.new.extend(Representer::AggregateResponseRepresenter).from_json(resp.body), resp.headers, resp.status ) end |
#post(path, body = nil, headers = {}) ⇒ Object
20 21 22 |
# File 'lib/octoparts/client.rb', line 20 def post(path, body = nil, headers = {}) process(:post, path, {}, body, headers) end |