Class: ArtirixDataModels::DataGateway

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

Defined Under Namespace

Modules: ConnectionLoader 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, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil) ⇒ DataGateway

Returns a new instance of DataGateway.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 4

def initialize(connection: nil,
               post_as_json: true,
               timeout: nil,
               authorization_bearer: nil,
               authorization_token_hash: nil)
  @connection               = connection || ConnectionLoader.default_connection
  @post_as_json             = !!post_as_json
  @authorization_bearer     = authorization_bearer
  @authorization_token_hash = authorization_token_hash
  @timeout                  = timeout
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, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, **_ignored_options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 32

def call(method,
         path,
         json_body: true,
         response_adaptor: nil,
         body: nil,
         fake: false,
         fake_response: nil,
         cache_adaptor: nil,
         timeout: nil,
         authorization_bearer: nil,
         authorization_token_hash: nil,
         **_ignored_options)
  if fake
    result = fake_response.respond_to?(:call) ? fake_response.call : fake_response

  elsif cache_adaptor.present?
    result = cache_adaptor.call do
      perform method,
              path:                     path,
              body:                     body,
              json_body:                json_body,
              timeout:                  timeout,
              authorization_bearer:     authorization_bearer,
              authorization_token_hash: authorization_token_hash
    end

  else
    result = perform method,
                     path:                     path,
                     body:                     body,
                     json_body:                json_body,
                     timeout:                  timeout,
                     authorization_bearer:     authorization_bearer,
                     authorization_token_hash: authorization_token_hash
  end

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

#delete(path, **opts) ⇒ Object



28
29
30
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 28

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

#get(path, **opts) ⇒ Object



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

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

#post(path, **opts) ⇒ Object



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

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

#put(path, **opts) ⇒ Object



24
25
26
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 24

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