Class: ShippyProAPI::Client

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

Constant Summary collapse

BASE_URL =
'https://www.shippypro.com/api'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, adapter: Faraday.default_adapter) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/shippy_pro_api/client.rb', line 9

def initialize(api_key:, adapter: Faraday.default_adapter)
  @api_key = api_key
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/shippy_pro_api/client.rb', line 7

def adapter
  @adapter
end

#api_keyObject (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

Instance Method Details

#connectionObject



14
15
16
17
18
19
20
21
22
# File 'lib/shippy_pro_api/client.rb', line 14

def connection
  @connection ||= Faraday.new 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

#shipmentObject



24
25
26
# File 'lib/shippy_pro_api/client.rb', line 24

def shipment
  ShipmentResource.new(self)
end