Class: MarketplaceKit::Services::ApiDriver

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/marketplace_kit/services/api_driver.rb

Instance Method Summary collapse

Methods included from Loggable

#log

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, options)
  @request_type = request_type
  @url = url
  @hash_body = hash_body
  @options = options
end

Instance Method Details

#send_requestObject



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