Class: Usps::Imis::Properties

Inherits:
Object
  • Object
show all
Defined in:
lib/usps/imis/properties.rb

Overview

Constructor for the Properties field

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.buildObject

Build the data for a new Properties field



10
# File 'lib/usps/imis/properties.rb', line 10

def self.build(&) = new.build(&)

.wrap(value) ⇒ Object

Wrap value in the API-internal type structure



14
15
16
17
18
19
20
21
22
23
# File 'lib/usps/imis/properties.rb', line 14

def self.wrap(value)
  case value
  when String then value
  when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
  when Integer then { '$type' => 'System.Int32', '$value' => value }
  when true, false then { '$type' => 'System.Boolean', '$value' => value }
  else
    raise Errors::UnexpectedPropertyTypeError.from(value)
  end
end

Instance Method Details

#add(name, value) ⇒ Object

Add an individual property to the field



40
41
42
43
44
45
46
47
# File 'lib/usps/imis/properties.rb', line 40

def add(name, value)
  @properties ||= []
  @properties << {
    '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
    'Name' => name,
    'Value' => self.class.wrap(value)
  }
end

#build {|_self| ... } ⇒ Object

Build the data for the Properties field

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
32
33
34
35
36
# File 'lib/usps/imis/properties.rb', line 27

def build
  yield(self)

  {
    'Properties' => {
      '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
      '$values' => @properties
    }
  }
end