Class: NzPostApi::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client_id, access_token, prod: false) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/nz_post_api/client.rb', line 7

def initialize(client_id, access_token, prod: false)
  @client_id = client_id
  @access_token = access_token
  @prod = prod
end

Instance Method Details

#base_url ⇒ Object



13
14
15
16
17
18
19
# File 'lib/nz_post_api/client.rb', line 13

def base_url
  if @prod
    "https://api.nzpost.co.nz"
  else
    "https://api.uat.nzpost.co.nz"
  end
end

#connection ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/nz_post_api/client.rb', line 21

def connection
  @connection ||= Faraday.new do |f|
    f.request :json
    f.response :json
    f.headers["client_id"] = @client_id
    f.headers["Authorization"] = "Bearer #{@access_token}"
    f.headers["Content-Type"] = "application/json"
  end
end

#parcel_address ⇒ Object



31
32
33
# File 'lib/nz_post_api/client.rb', line 31

def parcel_address
  Resources::ParcelAddress.new(self)
end

#parcel_label ⇒ Object



35
36
37
# File 'lib/nz_post_api/client.rb', line 35

def parcel_label
  Resources::ParcelLabel.new(self)
end

#parcel_track ⇒ Object



43
44
45
# File 'lib/nz_post_api/client.rb', line 43

def parcel_track
  Resources::ParcelTrack.new(self)
end

#shipping_options ⇒ Object



39
40
41
# File 'lib/nz_post_api/client.rb', line 39

def shipping_options
  Resources::ShippingOption.new(self)
end