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
- #associated_shipments ⇒ Object
- #file_name ⇒ Object
- #format ⇒ Object
- #has_image? ⇒ Boolean
-
#initialize(label_details = {}, associated_shipments = false) ⇒ Label
constructor
Initialize Fedex::Label Object.
- #name ⇒ Object
- #save(path, append_name = true) ⇒ Object
- #tracking_number ⇒ Object
Constructor Details
#initialize(label_details = {}, associated_shipments = false) ⇒ Label
Initialize Fedex::Label Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fedex/label.rb', line 10 def initialize(label_details = {}, associated_shipments = false) if associated_shipments package_details = label_details @options = package_details[:label] @options[:tracking_number] = package_details[:tracking_id] else @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[:tracking_number] = package_details[:tracking_ids][:tracking_number] end @options[:format] = label_details[:format] @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
#associated_shipments ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/fedex/label.rb', line 61 def associated_shipments if (label_details = @response_details[:completed_shipment_detail][:associated_shipments]) label_details[:format] = format label_details[:file_name] = file_name Label.new(label_details, true) else nil end end |
#file_name ⇒ Object
38 39 40 |
# File 'lib/fedex/label.rb', line 38 def file_name [:file_name] end |
#format ⇒ Object
34 35 36 |
# File 'lib/fedex/label.rb', line 34 def format [:format] end |
#has_image? ⇒ Boolean
46 47 48 |
# File 'lib/fedex/label.rb', line 46 def has_image? [:parts] && [:parts][:image] end |
#name ⇒ Object
30 31 32 |
# File 'lib/fedex/label.rb', line 30 def name [tracking_number, format].join('.') end |
#save(path, append_name = true) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fedex/label.rb', line 50 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
42 43 44 |
# File 'lib/fedex/label.rb', line 42 def tracking_number [:tracking_number] end |