Class: MarketplaceKit::Services::ApiDriver
- Inherits:
-
Object
- Object
- MarketplaceKit::Services::ApiDriver
- Includes:
- Loggable
- Defined in:
- lib/marketplace_kit/services/api_driver.rb
Instance Method Summary collapse
-
#initialize(request_type, url, hash_body, options) ⇒ ApiDriver
constructor
A new instance of ApiDriver.
- #send_request ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(request_type, url, hash_body, options) ⇒ ApiDriver
Returns a new instance of ApiDriver.
6 7 8 9 10 11 |
# File 'lib/marketplace_kit/services/api_driver.rb', line 6 def initialize(request_type, url, hash_body, ) @request_type = request_type @url = url @hash_body = hash_body @options = end |
Instance Method Details
#send_request ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/marketplace_kit/services/api_driver.rb', line 13 def send_request url = "api/marketplace_builder/#{@url}" body = prepare_body_to_send response = connection.method(@request_type).call(url, body) parsed_response = JSON.parse(response.body) raise Errors::ApiError.new(parsed_response) unless response.success? OpenStruct.new(status: response.status, body: parsed_response, success?: true) rescue StandardError => e log_error(e, response) OpenStruct.new(status: (response && response.status), body: parsed_response, success?: false) end |