Class: Prodigi::Client
- Inherits:
-
Object
- Object
- Prodigi::Client
- 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.
Constant Summary collapse
- BASE_URL_DEFAULT =
"https://api.sandbox.prodigi.com/v4.0"- BASE_URL_ENV_VAR =
"PRODIGI_API_URL"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(api_key:, **options) ⇒ Client
constructor
Initializes a new Prodigi API client.
- #orders ⇒ Object
- #products ⇒ Object
- #quotes ⇒ Object
Constructor Details
#initialize(api_key:, **options) ⇒ Client
Initializes a new Prodigi API client
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/prodigi/client.rb', line 46 def initialize(api_key:, **) @api_key = api_key @adapter = .fetch(:adapter, Faraday.default_adapter) @base_url = [:base_url] || ENV.fetch(BASE_URL_ENV_VAR, BASE_URL_DEFAULT) @debug = .fetch(:debug, false) @logger = [:logger] || Logger.new($stdout).tap do |log| log.progname = self.class.name end # Tests stubs for requests @stubs = [:stubs] end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
28 29 30 |
# File 'lib/prodigi/client.rb', line 28 def adapter @adapter end |
#api_key ⇒ Object (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_url ⇒ Object (readonly)
Returns the value of attribute base_url.
28 29 30 |
# File 'lib/prodigi/client.rb', line 28 def base_url @base_url end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
28 29 30 |
# File 'lib/prodigi/client.rb', line 28 def debug @debug end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
28 29 30 |
# File 'lib/prodigi/client.rb', line 28 def logger @logger end |
Instance Method Details
#connection ⇒ Object
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 |
#orders ⇒ Object
59 60 61 |
# File 'lib/prodigi/client.rb', line 59 def orders OrderResource.new(self) end |
#products ⇒ Object
67 68 69 |
# File 'lib/prodigi/client.rb', line 67 def products ProductResource.new(self) end |
#quotes ⇒ Object
63 64 65 |
# File 'lib/prodigi/client.rb', line 63 def quotes QuoteResource.new(self) end |