Class: ShippyProAPI::Client
- Inherits:
-
Object
- Object
- ShippyProAPI::Client
- Defined in:
- lib/shippy_pro_api/client.rb
Constant Summary collapse
- BASE_URL =
"https://www.shippypro.com/api"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(api_key:, adapter: Faraday.default_adapter, config: {}) ⇒ Client
constructor
A new instance of Client.
- #shipment ⇒ Object
Constructor Details
#initialize(api_key:, adapter: Faraday.default_adapter, config: {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/shippy_pro_api/client.rb', line 9 def initialize(api_key:, adapter: Faraday.default_adapter, config: {}) @api_key = api_key @adapter = adapter @config = config end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/shippy_pro_api/client.rb', line 7 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/shippy_pro_api/client.rb', line 7 def api_key @api_key end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/shippy_pro_api/client.rb', line 7 def config @config end |
Instance Method Details
#connection ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/shippy_pro_api/client.rb', line 15 def connection @connection ||= Faraday.new(config) do |conn| conn.url_prefix = BASE_URL conn.headers["Authorization"] = "Basic #{encoded_credentials}" conn.request :json conn.response :json, content_type: "application/json" conn.adapter adapter end end |
#shipment ⇒ Object
26 27 28 |
# File 'lib/shippy_pro_api/client.rb', line 26 def shipment ShipmentResource.new(self) end |