Class: Axel::ApiProxy
- Inherits:
-
ServiceResource::Base
- Object
- Typhoid::Resource
- ServiceResource::Base
- Axel::ApiProxy
- Defined in:
- app/models/axel/api_proxy.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#request_options ⇒ Object
readonly
Returns the value of attribute request_options.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(endpoint, request_options = {}) ⇒ ApiProxy
constructor
A new instance of ApiProxy.
- #register! ⇒ Object
Methods inherited from ServiceResource::Base
Methods included from CascadableAttribute
#_cascadable_attributes, #_cascadable_attributes=, #_instance_var_for, #cascade_attribute, #inherited
Methods included from ServiceResource::Attributes
#assign_attributes, #update_attributes
Methods included from ServiceResource::Requesters
Methods included from ServiceResource::TyphoidExtensions
#after_build, #attributes, #build_typhoid_request, #create_request, #default_request_options, #delete_request, #envelope?, #load_values, #merge_result, #object_request, #request_and_load, #resource_exception, #update_request
Methods included from ServiceResource::Inspects
Constructor Details
#initialize(endpoint, request_options = {}) ⇒ ApiProxy
Returns a new instance of ApiProxy.
25 26 27 28 |
# File 'app/models/axel/api_proxy.rb', line 25 def initialize(endpoint, = {}) @endpoint = endpoint @request_options = {} end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
3 4 5 |
# File 'app/models/axel/api_proxy.rb', line 3 def endpoint @endpoint end |
#request_options ⇒ Object (readonly)
Returns the value of attribute request_options.
5 6 7 |
# File 'app/models/axel/api_proxy.rb', line 5 def @request_options end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
4 5 6 |
# File 'app/models/axel/api_proxy.rb', line 4 def services @services end |
Class Method Details
.build(_, response) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/models/axel/api_proxy.rb', line 15 def self.build(_, response) if response.success? MultiJson.load(response.body) else {} end rescue MultiJson::DecodeError {} end |
.cache_dir ⇒ Object
11 12 13 |
# File 'app/models/axel/api_proxy.rb', line 11 def self.cache_dir Rails.root.join("cache") end |
.cache_file ⇒ Object
7 8 9 |
# File 'app/models/axel/api_proxy.rb', line 7 def self.cache_file cache_dir.join("api_registry_cache.json") end |
Instance Method Details
#register! ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/models/axel/api_proxy.rb', line 30 def register! resource_settings.each do |resource_setting| Axel.config do |config| config.add_resource extract_service_name(resource_setting["service"]), extract_resource_name(resource_setting["path"]), service: { url: resource_setting["service"] } end end end |