Class: WeShipClient::Interactors::ProcessOrders

Inherits:
Object
  • Object
show all
Defined in:
lib/we_ship_client/interactors/process_orders.rb

Overview

Class to interact with the /process_orders API endpoint.

Instance Method Summary collapse

Constructor Details

#initialize(auth_token:, process_orders_request:) ⇒ ProcessOrders

Returns a new instance of ProcessOrders.

Parameters:



13
14
15
16
# File 'lib/we_ship_client/interactors/process_orders.rb', line 13

def initialize(auth_token:, process_orders_request:)
  @auth_token = auth_token
  @process_orders_request = process_orders_request
end

Instance Method Details

#callEntities::Responses::ProcessOrders

Sends orders to be processed.

Returns:

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/we_ship_client/interactors/process_orders.rb', line 23

def call
  json_response = client.http_client.post(
    "#{client.base_url}/process_orders",
    data: process_orders_request.to_h,
    headers: {
      Authorization: "JWT #{auth_token}"
    }
  )

  handle_exception(json_response) unless json_response.status == 200
  response_hash = JSON.parse(json_response.body, symbolize_names: true)
  response_class.new(response_hash[:response])
end