Class: ArtirixDataModels::DataGateway
- Inherits:
-
Object
- Object
- ArtirixDataModels::DataGateway
- 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
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#post_as_json ⇒ Object
readonly
Returns the value of attribute post_as_json.
Instance Method Summary collapse
- #call(method, path, json_body: true, response_adaptor: nil, body: nil, fake: false, fake_response: nil, cache_adaptor: nil, timeout: nil, **_ignored_options) ⇒ Object
- #delete(path, **opts) ⇒ Object
- #get(path, **opts) ⇒ Object
-
#initialize(connection: nil, post_as_json: true) ⇒ DataGateway
constructor
A new instance of DataGateway.
- #post(path, **opts) ⇒ Object
- #put(path, **opts) ⇒ Object
Constructor Details
#initialize(connection: nil, post_as_json: true) ⇒ DataGateway
Returns a new instance of 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
#connection ⇒ Object (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_json ⇒ Object (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, **_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, timeout: nil, **) if fake result = fake_response.respond_to?(:call) ? fake_response.call : fake_response elsif cache_adaptor.present? result = cache_adaptor.call { perform(method, path: path, body: body, json_body: json_body, timeout: timeout) } else result = perform(method, path: path, body: body, json_body: json_body, timeout: timeout) 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 |