Class: Smartsend::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/smartsend/label.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#pdfObject

Returns the value of attribute pdf.



2
3
4
# File 'lib/smartsend/label.rb', line 2

def pdf
  @pdf
end

#tracking_codeObject

Returns the value of attribute tracking_code.



2
3
4
# File 'lib/smartsend/label.rb', line 2

def tracking_code
  @tracking_code
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/smartsend/label.rb', line 2

def url
  @url
end

Class Method Details

.find_by_tracking_code(tracking_code, account: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/smartsend/label.rb', line 4

def self.find_by_tracking_code(tracking_code, account: nil)
  response = Smartsend::Client.new().get("shipments/tracking/#{tracking_code}/labels")

  if response.success?
    label = new
    label.tracking_code = tracking_code
    label.url = response.dig('data', 'pdf', 'link')
    label.pdf = response.dig('data', 'pdf', 'base_64_encoded')
    label
  end
end