Class: UspsApi::FilterProperties

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/filter_properties.rb

Overview

The filters that should be applied to the subscription. The structure of this property will change dependent on the type of subscription a client is signing up for.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(subscription_ttl: SKIP, crid: SKIP, name_address: SKIP, additional_properties: nil) ⇒ FilterProperties

Returns a new instance of FilterProperties.



49
50
51
52
53
54
55
56
57
58
# File 'lib/usps_api/models/filter_properties.rb', line 49

def initialize(subscription_ttl: SKIP, crid: SKIP, name_address: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @subscription_ttl = subscription_ttl unless subscription_ttl == SKIP
  @crid = crid unless crid == SKIP
  @name_address = name_address unless name_address == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#cridString

Customer Registration ID

Returns:

  • (String)


20
21
22
# File 'lib/usps_api/models/filter_properties.rb', line 20

def crid
  @crid
end

#name_addressSubscriptionsNcoaTheAddresseeInformation

The name and address of the user to search for.



24
25
26
# File 'lib/usps_api/models/filter_properties.rb', line 24

def name_address
  @name_address
end

#subscription_ttlInteger

Indicates how long to keep the subscription active.

Returns:

  • (Integer)


16
17
18
# File 'lib/usps_api/models/filter_properties.rb', line 16

def subscription_ttl
  @subscription_ttl
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/usps_api/models/filter_properties.rb', line 61

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  subscription_ttl =
    hash.key?('subscriptionTTL') ? hash['subscriptionTTL'] : SKIP
  crid = hash.key?('crid') ? hash['crid'] : SKIP
  name_address = SubscriptionsNcoaTheAddresseeInformation.from_hash(hash['nameAddress']) if
    hash['nameAddress']

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  FilterProperties.new(subscription_ttl: subscription_ttl,
                       crid: crid,
                       name_address: name_address,
                       additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
33
# File 'lib/usps_api/models/filter_properties.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['subscription_ttl'] = 'subscriptionTTL'
  @_hash['crid'] = 'crid'
  @_hash['name_address'] = 'nameAddress'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/usps_api/models/filter_properties.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
41
42
# File 'lib/usps_api/models/filter_properties.rb', line 36

def self.optionals
  %w[
    subscription_ttl
    crid
    name_address
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



93
94
95
96
97
# File 'lib/usps_api/models/filter_properties.rb', line 93

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} subscription_ttl: #{@subscription_ttl.inspect}, crid: #{@crid.inspect},"\
  " name_address: #{@name_address.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



86
87
88
89
90
# File 'lib/usps_api/models/filter_properties.rb', line 86

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} subscription_ttl: #{@subscription_ttl}, crid: #{@crid}, name_address:"\
  " #{@name_address}, additional_properties: #{@additional_properties}>"
end