Class: Prodigi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/prodigi/client.rb

Overview

Main client for interacting with the Prodigi API

The client handles authentication, request configuration, and provides access to all API resources (orders, quotes, products). By default, it connects to the sandbox environment unless configured otherwise.

Examples:

Basic client setup

client = Prodigi::Client.new(api_key: "your_api_key")

Production environment

client = Prodigi::Client.new(
  api_key: "your_api_key",
  base_url: "https://api.prodigi.com/v4.0"
)

With debugging enabled

client = Prodigi::Client.new(
  api_key: "your_api_key",
  debug: true
)

Constant Summary collapse

BASE_URL_DEFAULT =
"https://api.sandbox.prodigi.com/v4.0"
BASE_URL_ENV_VAR =
"PRODIGI_API_URL"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, **options) ⇒ Client

Initializes a new Prodigi API client

Examples:

With options

client = Prodigi::Client.new(
  api_key: ENV["PRODIGI_API_KEY"],
  debug: true,
  base_url: "https://api.prodigi.com/v4.0"
)

Options Hash (**options):

  • :adapter (Symbol)

    Faraday adapter to use (default: Faraday.default_adapter)

  • :base_url (String)

    Custom API base URL (defaults to sandbox or PRODIGI_API_URL env var)

  • :stubs (Faraday::Adapter::Test::Stubs)

    Test stubs for mocking requests (for testing only)

  • :debug (Boolean)

    Enable debug logging (default: false)

  • :logger (Logger)

    Custom logger instance (default: stdout logger)



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/prodigi/client.rb', line 46

def initialize(api_key:, **options)
  @api_key = api_key
  @adapter = options.fetch(:adapter, Faraday.default_adapter)
  @base_url = options[:base_url] || ENV.fetch(BASE_URL_ENV_VAR, BASE_URL_DEFAULT)
  @debug = options.fetch(:debug, false)
  @logger = options[:logger] || Logger.new($stdout).tap do |log|
    log.progname = self.class.name
  end

  # Tests stubs for requests
  @stubs = options[:stubs]
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



28
29
30
# File 'lib/prodigi/client.rb', line 28

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



28
29
30
# File 'lib/prodigi/client.rb', line 28

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



28
29
30
# File 'lib/prodigi/client.rb', line 28

def base_url
  @base_url
end

#debugObject (readonly)

Returns the value of attribute debug.



28
29
30
# File 'lib/prodigi/client.rb', line 28

def debug
  @debug
end

#loggerObject (readonly)

Returns the value of attribute logger.



28
29
30
# File 'lib/prodigi/client.rb', line 28

def logger
  @logger
end

Instance Method Details

#connectionObject



71
72
73
74
75
76
77
78
79
# File 'lib/prodigi/client.rb', line 71

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = @base_url
    conn.request :json
    conn.response :json
    configure_debug_logging(conn) if @debug
    conn.adapter adapter, @stubs
  end
end

#ordersObject



59
60
61
# File 'lib/prodigi/client.rb', line 59

def orders
  OrderResource.new(self)
end

#productsObject



67
68
69
# File 'lib/prodigi/client.rb', line 67

def products
  ProductResource.new(self)
end

#quotesObject



63
64
65
# File 'lib/prodigi/client.rb', line 63

def quotes
  QuoteResource.new(self)
end