Class: ArtirixDataModels::DataGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/artirix_data_models/gateways/data_gateway.rb

Defined Under Namespace

Modules: DefaultConnectionLoader Classes: BadRequest, Conflict, ConnectionError, Error, Forbidden, GatewayError, NotAcceptable, NotFound, ParseError, RequestTimeout, ServerError, TooManyRequests, Unauthorized, UnprocessableEntity

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, post_as_json: true) ⇒ DataGateway



4
5
6
7
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 4

def initialize(connection: nil, post_as_json: true)
  @connection   = connection || DefaultConnectionLoader.default_connection
  @post_as_json = !!post_as_json
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



2
3
4
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 2

def connection
  @connection
end

#post_as_jsonObject (readonly)

Returns the value of attribute post_as_json.



2
3
4
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 2

def post_as_json
  @post_as_json
end

Instance Method Details

#call(method, path, json_body: true, response_adaptor: nil, body: nil, fake: false, fake_response: nil, cache_adaptor: nil, **_ignored_options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 25

def call(method, path, json_body: true, response_adaptor: nil, body: nil, fake: false, fake_response: nil, cache_adaptor: nil, **_ignored_options)
  if fake
    result = fake_response.respond_to?(:call) ? fake_response.call : fake_response
  elsif cache_adaptor.present?
    result = cache_adaptor.call { perform(method, path, body, json_body) }
  else
    result = perform(method, path, body, json_body)
  end

  parse_response result:           result,
                 response_adaptor: response_adaptor,
                 method:           method,
                 path:             path
end

#delete(path, **opts) ⇒ Object



21
22
23
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 21

def delete(path, **opts)
  call :delete, path, **opts
end

#get(path, **opts) ⇒ Object



9
10
11
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 9

def get(path, **opts)
  call :get, path, **opts
end

#post(path, **opts) ⇒ Object



13
14
15
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 13

def post(path, **opts)
  call :post, path, **opts
end

#put(path, **opts) ⇒ Object



17
18
19
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 17

def put(path, **opts)
  call :put, path, **opts
end