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, ensure_relative: false, 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
15
16
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 4

def initialize(connection: nil,
               post_as_json: true,
               ensure_relative: false,
               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
  @ensure_relative          = !!ensure_relative
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



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
73
74
75
76
77
78
79
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 38

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



34
35
36
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 34

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

#ensure_relative?Boolean

Returns:

  • (Boolean)


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

def ensure_relative?
  !!@ensure_relative
end

#get(path, **opts) ⇒ Object



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

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

#post(path, **opts) ⇒ Object



26
27
28
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 26

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

#put(path, **opts) ⇒ Object



30
31
32
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 30

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