Class: ActiveShipping::ExternalReturnLabelRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shipping/external_return_label_request.rb

Constant Summary collapse

CAP_STRING_LEN =
100
USPS_EMAIL_REGEX =
/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
LABEL_FORMAT =
{
  'Instructions' => 'null',
  'No Instructions' => 'NOI',
  'Double Label' => 'TWO'
}
SERVICE_TYPE_CODE =
[
  '044', '019', '596', '020', '597','022', '024', '017', '018'
]
CALL_CENTER_OR_SELF_SERVICE =
['CallCenter', 'Customer']
LABEL_DEFINITION =
['4X6', 'Zebra-4X6', '4X4', '3X6']
IMAGE_TYPE =
['PDF', 'TIF']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ExternalReturnLabelRequest

Returns a new instance of ExternalReturnLabelRequest.



51
52
53
54
55
56
57
# File 'lib/active_shipping/external_return_label_request.rb', line 51

def initialize(options = {})
  options.each do |pair|
    self.public_send("#{pair[0]}=".to_sym, pair[1]) if self.respond_to?("#{pair[0]}=".to_sym)
  end

  verify_or_raise_required
end

Instance Attribute Details

#address_override_notificationObject

Returns the value of attribute address_override_notification.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def address_override_notification
  @address_override_notification
end

#address_validationObject

Returns the value of attribute address_validation.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def address_validation
  @address_validation
end

#attentionObject

Returns the value of attribute attention.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def attention
  @attention
end

#call_center_or_self_serviceObject

Returns the value of attribute call_center_or_self_service.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def call_center_or_self_service
  @call_center_or_self_service
end

#company_nameObject

Returns the value of attribute company_name.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def company_name
  @company_name
end

#customer_address1Object

Returns the value of attribute customer_address1.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_address1
  @customer_address1
end

#customer_address2Object

Returns the value of attribute customer_address2.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_address2
  @customer_address2
end

#customer_cityObject

Returns the value of attribute customer_city.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_city
  @customer_city
end

#customer_nameObject

Returns the value of attribute customer_name.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_name
  @customer_name
end

#customer_stateObject

Returns the value of attribute customer_state.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_state
  @customer_state
end

#customer_urbanizationObject

Returns the value of attribute customer_urbanization.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_urbanization
  @customer_urbanization
end

#customer_zipcodeObject

Returns the value of attribute customer_zipcode.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def customer_zipcode
  @customer_zipcode
end

#image_typeObject

Returns the value of attribute image_type.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def image_type
  @image_type
end

#insurance_amountObject

Returns the value of attribute insurance_amount.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def insurance_amount
  @insurance_amount
end

#label_definitionObject

Returns the value of attribute label_definition.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def label_definition
  @label_definition
end

#label_formatObject

Returns the value of attribute label_format.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def label_format
  @label_format
end

#merchandise_descriptionObject

Returns the value of attribute merchandise_description.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def merchandise_description
  @merchandise_description
end

#merchant_account_idObject

Returns the value of attribute merchant_account_id.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def 
  @merchant_account_id
end

#midObject

Returns the value of attribute mid.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def mid
  @mid
end

#packaging_informationObject

Returns the value of attribute packaging_information.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def packaging_information
  @packaging_information
end

#packaging_information2Object

Returns the value of attribute packaging_information2.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def packaging_information2
  @packaging_information2
end

#recipient_bccObject

Returns the value of attribute recipient_bcc.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def recipient_bcc
  @recipient_bcc
end

#recipient_emailObject

Returns the value of attribute recipient_email.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def recipient_email
  @recipient_email
end

#recipient_nameObject

Returns the value of attribute recipient_name.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def recipient_name
  @recipient_name
end

#sender_emailObject

Returns the value of attribute sender_email.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def sender_email
  @sender_email
end

#sender_nameObject

Returns the value of attribute sender_name.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def sender_name
  @sender_name
end

#service_type_codeObject

Returns the value of attribute service_type_code.



23
24
25
# File 'lib/active_shipping/external_return_label_request.rb', line 23

def service_type_code
  @service_type_code
end

Class Method Details

.from_hash(options = {}) ⇒ Object



59
60
61
# File 'lib/active_shipping/external_return_label_request.rb', line 59

def self.from_hash(options={})
  self.new(options)
end

Instance Method Details

#to_xmlObject



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/active_shipping/external_return_label_request.rb', line 313

def to_xml
  xml_builder = Nokogiri::XML::Builder.new do |xml|
    xml.ExternalReturnLabelRequest do
      xml.CustomerName { xml.text(customer_name) }
      xml.CustomerAddress1 { xml.text(customer_address1) }
      xml.CustomerAddress2 { xml.text(customer_address2) } if customer_address2
      xml.CustomerCity { xml.text(customer_city) }
      xml.CustomerState { xml.text(customer_state) }
      xml.CustomerZipCode { xml.text(customer_zipcode) } if customer_zipcode
      xml.CustomerUrbanization { xml.text(customer_urbanization) } if customer_urbanization

      xml.MerchantAccountID { xml.text() }
      xml.MID { xml.text(mid) }

      xml.SenderName { xml.text(sender_name) } if sender_name
      xml.SenderEmail { xml.text(sender_email) } if sender_email

      xml.RecipientName { xml.text(recipient_name) } if recipient_name
      xml.RecipientEmail { xml.text(recipient_email) } if recipient_email
      xml.RecipientBcc { xml.text(recipient_bcc) } if recipient_bcc

      xml.LabelFormat { xml.text(label_format) } if label_format
      xml.LabelDefinition { xml.text(label_definition) } if label_definition
      xml.ServiceTypeCode { xml.text(service_type_code) } if service_type_code

      xml.CompanyName { xml.text(company_name) } if company_name
      xml.Attention { xml.text(attention) } if attention

      xml.CallCenterOrSelfService { xml.text(call_center_or_self_service) }

      xml.MerchandiseDescription { xml.text(merchandise_description) } if merchandise_description
      xml.InsuranceAmount { xml.text(insurance_amount) } if insurance_amount

      xml.AddressOverrideNotification { xml.text(!!address_override_notification) }

      xml.PackageInformation { xml.text(packaging_information) } if packaging_information
      xml.PackageInformation2 { xml.text(packaging_information2) } if packaging_information2

      xml.ImageType { xml.text(image_type) } if image_type
      xml.AddressValidation { xml.text(!!address_validation) }

    end
  end
  xml_builder.to_xml
end

#verify_or_raise_requiredObject



302
303
304
305
306
307
308
309
310
311
# File 'lib/active_shipping/external_return_label_request.rb', line 302

def verify_or_raise_required
  %w(customer_name customer_address1 customer_city customer_state
     customer_zipcode label_format label_definition service_type_code
     call_center_or_self_service).each do |attr|
    raise USPSMissingRequiredTagError.new(attr.camelize, attr) unless send(attr.to_sym)
  end
  # Safer than using inflection acroynms
  raise USPSMissingRequiredTagError.new("MID", "mid") unless mid
  raise USPSMissingRequiredTagError.new("MerchantAccountID", "merchant_account_id") unless 
end