Class: Postmaster::Shipment

Inherits:
APIResource show all
Includes:
APIOperations::List
Defined in:
lib/postmaster/shipment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::List

included

Methods inherited from APIResource

class_name, #refresh, retrieve, url, #url

Methods inherited from PostmasterObject

#[], #[]=, construct_from, #delete, #each, #has_key?, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Postmaster::PostmasterObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Postmaster::PostmasterObject

Class Method Details

.create(params = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/postmaster/shipment.rb', line 6

def self.create(params={})
  Util.normalize_address(params[:to])
  Util.normalize_address(params[:from])
  response = Postmaster.request(:post, self.url, params)
  self.construct_from(response)
end

Instance Method Details

#trackObject



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

def track
  response = Postmaster.request(:get, url('track'))
  if response[:results].nil?
    return nil
  end
  response[:results].map { |i| Postmaster::Tracking.construct_from(i) }
end

#voidObject



21
22
23
24
25
# File 'lib/postmaster/shipment.rb', line 21

def void
  response = Postmaster.request(:post, url('void'))
  refresh_from({})
  response[:message] == 'OK'
end