Class: Axel::ApiProxy

Inherits:
ServiceResource::Base show all
Defined in:
app/models/axel/api_proxy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServiceResource::Base

#reload

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

#default_request_options

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

#inspect

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, request_options = {})
  @endpoint = endpoint
  @request_options = {}
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



3
4
5
# File 'app/models/axel/api_proxy.rb', line 3

def endpoint
  @endpoint
end

#request_optionsObject (readonly)

Returns the value of attribute request_options.



5
6
7
# File 'app/models/axel/api_proxy.rb', line 5

def request_options
  @request_options
end

#servicesObject (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_dirObject



11
12
13
# File 'app/models/axel/api_proxy.rb', line 11

def self.cache_dir
  Rails.root.join("cache")
end

.cache_fileObject



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