Class: NzPostApi::Resources::ParcelLabel
- Inherits:
-
Object
- Object
- NzPostApi::Resources::ParcelLabel
- Defined in:
- lib/nz_post_api/resources/parcel_label.rb
Instance Method Summary collapse
- #base_url ⇒ Object
- #create(payload) ⇒ Object
- #download(consignment_id, format: "PDF") ⇒ Object
-
#initialize(client) ⇒ ParcelLabel
constructor
A new instance of ParcelLabel.
- #status(consignment_id) ⇒ Object
Constructor Details
#initialize(client) ⇒ ParcelLabel
Returns a new instance of ParcelLabel.
10 11 12 |
# File 'lib/nz_post_api/resources/parcel_label.rb', line 10 def initialize(client) @client = client end |
Instance Method Details
#base_url ⇒ Object
6 7 8 |
# File 'lib/nz_post_api/resources/parcel_label.rb', line 6 def base_url "#{@client.base_url}/parcellabel/v3/labels" end |
#create(payload) ⇒ Object
14 15 16 17 |
# File 'lib/nz_post_api/resources/parcel_label.rb', line 14 def create(payload) response = @client.connection.post(base_url, payload) handle_response(response) end |
#download(consignment_id, format: "PDF") ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nz_post_api/resources/parcel_label.rb', line 24 def download(consignment_id, format: "PDF") response = @client.connection.get("#{base_url}/#{consignment_id}", { format: format }) if response.success? response.body else raise NzPostApi::Error.new( "Failed to download label: #{response.status} - #{response.body}", response_http_code: response.status, response_body: response.body ) end end |
#status(consignment_id) ⇒ Object
19 20 21 22 |
# File 'lib/nz_post_api/resources/parcel_label.rb', line 19 def status(consignment_id) response = @client.connection.get("#{base_url}/#{consignment_id}/status") handle_response(response) end |