Class: FulfilApi::TplClient

Inherits:
Object
  • Object
show all
Defined in:
lib/fulfil_api/tpl_client.rb

Overview

The TplClient allows making proxy requests to Fulfil’s 3PL carrier API endpoint. It provides a simple interface for interacting with the 3PL supplier API using standard HTTP methods.

Examples:

Using the TPL client

FulfilApi.tpl_client.get("inbound-transfers", page: 1)
FulfilApi.tpl_client.post("inbound-transfers/receive.json", { tracking_number: "123" })

Defined Under Namespace

Classes: ConfigurationError

Constant Summary collapse

DEFAULT_API_VERSION =
"v1"

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ TplClient

Returns a new instance of TplClient.

Parameters:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fulfil_api/tpl_client.rb', line 20

def initialize(configuration)
  @configuration = configuration

  tpl_config = configuration.tpl || {}

  @auth_token = tpl_config[:auth_token].presence ||
                raise(ConfigurationError,
                      "Please provide a 3PL authentication token via config.tpl = { auth_token: ... }")
  @merchant_id = tpl_config[:merchant_id].presence || configuration.merchant_id.presence ||
                 raise(ConfigurationError, "Please provide a merchant ID")
  @api_version = tpl_config[:api_version].presence || DEFAULT_API_VERSION
end

Instance Method Details

#get(relative_path, **url_parameters) ⇒ Array, ...

Performs an HTTP GET request to a 3PL API endpoint.

Parameters:

  • relative_path (String)

    The relative path to the endpoint.

  • url_parameters (Hash)

    The optional URL parameters for the API endpoint.

Returns:

  • (Array, Hash, String)

    The parsed response body.



38
39
40
# File 'lib/fulfil_api/tpl_client.rb', line 38

def get(relative_path, **url_parameters)
  request(:get, relative_path, url_parameters.presence)
end

#patch(relative_path, body = {}) ⇒ Array, ...

Performs an HTTP PATCH request to a 3PL API endpoint.

Parameters:

  • relative_path (String)

    The relative path to the endpoint.

  • body (Array, Hash, nil) (defaults to: {})

    The request body for the PATCH HTTP request.

Returns:

  • (Array, Hash, String)

    The parsed response body.



47
48
49
# File 'lib/fulfil_api/tpl_client.rb', line 47

def patch(relative_path, body = {})
  request(:patch, relative_path, body)
end

#post(relative_path, body = {}) ⇒ Array, ...

Performs an HTTP POST request to a 3PL API endpoint.

Parameters:

  • relative_path (String)

    The relative path to the endpoint.

  • body (Array, Hash, nil) (defaults to: {})

    The request body for the POST HTTP request.

Returns:

  • (Array, Hash, String)

    The parsed response body.



56
57
58
# File 'lib/fulfil_api/tpl_client.rb', line 56

def post(relative_path, body = {})
  request(:post, relative_path, body)
end

#put(relative_path, body = nil) ⇒ Array, ...

Performs an HTTP PUT request to a 3PL API endpoint.

Parameters:

  • relative_path (String)

    The relative path to the endpoint.

  • body (Array, Hash, nil) (defaults to: nil)

    The optional request body for the PUT HTTP request.

Returns:

  • (Array, Hash, String)

    The parsed response body.



65
66
67
68
69
# File 'lib/fulfil_api/tpl_client.rb', line 65

def put(relative_path, body = nil)
  return request(:put, relative_path) if body.nil?

  request(:put, relative_path, body)
end