Class: USPS::Request::DeliveryConfirmation

Inherits:
Base
  • Object
show all
Defined in:
lib/usps/request/delivery_confirmation.rb

Direct Known Subclasses

DeliveryConfirmationCertify

Constant Summary collapse

DEFAULTS =
{
  :type    => 1,
  :format  => 'TIF',
  :service => 'Priority'
}.freeze
OPTIONS =

List of valid options and their mapping to their tag

{
  :type               => 'Option',
  :service            => 'ServiceType',
  :po_zip_code        => 'PoZipCode',
  :label_date         => 'LabelDate',
  :customer_reference => 'CustomerRefNo',
  :separate_receipt   => 'SeparateReceiptPage',
  :address_service    => 'AddressServiceRequested',
  :sender_name        => 'SenderName',
  :sender_email       => 'SenderEMail',
  :recipient_name     => 'RecipientName',
  :recipient_email    => 'RecipientEMail'
}.freeze
FORMATS =
%w(TIF PDF).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api, config, #response_for, #secure?, #send!

Constructor Details

#initialize(to, from, weight, options = {}) ⇒ DeliveryConfirmation

Options:

  • <tt>:



37
38
39
40
41
42
43
44
45
# File 'lib/usps/request/delivery_confirmation.rb', line 37

def initialize(to, from, weight, options = {})
  @to = to
  @from = from
  @weight = weight
  @options = DEFAULTS.merge(options)

  @type = @options.delete(:type)
  self.format = @options.delete(:format)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



10
11
12
# File 'lib/usps/request/delivery_confirmation.rb', line 10

def format
  @format
end

#fromObject (readonly)

Returns the value of attribute from.



10
11
12
# File 'lib/usps/request/delivery_confirmation.rb', line 10

def from
  @from
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/usps/request/delivery_confirmation.rb', line 10

def options
  @options
end

#toObject (readonly)

Returns the value of attribute to.



10
11
12
# File 'lib/usps/request/delivery_confirmation.rb', line 10

def to
  @to
end

#weightObject (readonly)

Returns the value of attribute weight.



10
11
12
# File 'lib/usps/request/delivery_confirmation.rb', line 10

def weight
  @weight
end

Instance Method Details

#buildObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/usps/request/delivery_confirmation.rb', line 57

def build
  super do |builder|
    builder.tag!('Option', @type)
    builder.tag!('ImageParameters')

    [
      [self.from, 'From'],
      [self.to,   'To']
    ].each do |address, prefix|
      builder.tag!("#{prefix}Name",  address.name)
      builder.tag!("#{prefix}Firm",  address.company)
      builder.tag!("#{prefix}Address1", address.extra_address)
      builder.tag!("#{prefix}Address2", address.address)
      builder.tag!("#{prefix}City",  address.city)
      builder.tag!("#{prefix}State", address.state)
      builder.tag!("#{prefix}Zip5",  address.zip5)
      builder.tag!("#{prefix}Zip4",  address.zip4)
    end

    builder.tag!('WeightInOunces', self.weight)

    @options.each_pair do |k,v|
      OPTIONS[k].tap do |tag|
        builder.tag!(tag, v.to_s) if tag
      end
    end

    builder.tag!('ImageType', @format)
  end
end