Class: PostNordAPI::Client

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

Constant Summary collapse

BASE_URL =
'https://api2.postnord.com/rest'
SANDBOX_BASE_URL =
'https://atapi2.postnord.com/rest'

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, test_mode: false) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/post_nord_api/client.rb', line 11

def initialize(api_key:, test_mode: false)
  @api_key = api_key
  @test_mode = test_mode
end

Instance Method Details

#connectionObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/post_nord_api/client.rb', line 16

def connection
  @connection ||=
    Faraday.new do |conn|
      conn.url_prefix = url_prefix
      conn.request :json
      conn.headers = { 'Content-Type' => 'application/json' }
      conn.params[:apikey] = api_key
      conn.response :json, content_type: 'application/json'
    end
end

#shipmentObject



27
28
29
# File 'lib/post_nord_api/client.rb', line 27

def shipment
  @shipment ||= ShipmentResource.new(self)
end