Class: Fedex::Label
- Inherits:
-
Object
- Object
- Fedex::Label
- Defined in:
- lib/fedex/label.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
Returns the value of attribute image.
-
#options ⇒ Object
Returns the value of attribute options.
-
#response_details ⇒ Object
Returns the value of attribute response_details.
Instance Method Summary collapse
- #file_name ⇒ Object
- #format ⇒ Object
- #has_image? ⇒ Boolean
-
#initialize(label_details = {}) ⇒ Label
constructor
Initialize Fedex::Label Object.
- #name ⇒ Object
- #save(path, append_name = true) ⇒ Object
- #tracking_number ⇒ Object
Constructor Details
#initialize(label_details = {}) ⇒ Label
Initialize Fedex::Label Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fedex/label.rb', line 10 def initialize(label_details = {}) @response_details = label_details[:process_shipment_reply] package_details = label_details[:process_shipment_reply][:completed_shipment_detail][:completed_package_details] @options = package_details[:label] @options[:format] = label_details[:format] @options[:tracking_number] = package_details[:tracking_ids][:tracking_number] @options[:file_name] = label_details[:file_name] @image = Base64.decode64([:parts][:image]) if has_image? if file_name = @options[:file_name] save(file_name, false) end end |
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
6 7 8 |
# File 'lib/fedex/label.rb', line 6 def image @image end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/fedex/label.rb', line 6 def @options end |
#response_details ⇒ Object
Returns the value of attribute response_details.
6 7 8 |
# File 'lib/fedex/label.rb', line 6 def response_details @response_details end |
Instance Method Details
#file_name ⇒ Object
33 34 35 |
# File 'lib/fedex/label.rb', line 33 def file_name [:file_name] end |
#format ⇒ Object
29 30 31 |
# File 'lib/fedex/label.rb', line 29 def format [:format] end |
#has_image? ⇒ Boolean
41 42 43 |
# File 'lib/fedex/label.rb', line 41 def has_image? [:parts] && [:parts][:image] end |
#name ⇒ Object
25 26 27 |
# File 'lib/fedex/label.rb', line 25 def name [tracking_number, format].join('.') end |
#save(path, append_name = true) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fedex/label.rb', line 45 def save(path, append_name = true) return unless has_image? full_path = Pathname.new(path) full_path = full_path.join(name) if append_name File.open(full_path, 'wb') do|f| f.write(@image) end end |
#tracking_number ⇒ Object
37 38 39 |
# File 'lib/fedex/label.rb', line 37 def tracking_number [:tracking_number] end |