Class: SmartyStreets::InternationalStreet::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/smartystreets_ruby_sdk/international_street/lookup.rb

Overview

In addition to holding all of the input data for this lookup, this class also will contain the result of the lookup after it comes back from the API.

Note: Lookups must have certain required fields set with non-blank values. These can be found at the URL below.

See "https://smartystreets.com/docs/cloud/international-street-api#http-input-fields"

@geocode

Disabled by default. Set to true to enable.

@language

When not set, the output language will match the language of the input values. When set to language_mode.NATIVE, the results will always be in the language of the output country. When set to language_mode.LATIN, the results will always be provided using a Latin character set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(freeform = nil, country = nil) ⇒ Lookup

Returns a new instance of Lookup.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 23

def initialize(freeform=nil, country=nil)
  @result = []

  @input_id = nil
  @country = country
  @geocode = nil
  @language = nil
  @freeform = freeform
  @address1 = nil
  @address2 = nil
  @address3 = nil
  @address4 = nil
  @organization = nil
  @locality = nil
  @administrative_area = nil
  @postal_code = nil
  @features = nil
  @custom_param_hash = {}
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def address2
  @address2
end

#address3Object

Returns the value of attribute address3.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def address3
  @address3
end

#address4Object

Returns the value of attribute address4.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def address4
  @address4
end

#administrative_areaObject

Returns the value of attribute administrative_area.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def administrative_area
  @administrative_area
end

#countryObject

Returns the value of attribute country.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def country
  @country
end

#custom_param_hashObject

Returns the value of attribute custom_param_hash.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def custom_param_hash
  @custom_param_hash
end

#featuresObject

Returns the value of attribute features.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def features
  @features
end

#freeformObject

Returns the value of attribute freeform.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def freeform
  @freeform
end

#geocodeObject

Returns the value of attribute geocode.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def geocode
  @geocode
end

#input_idObject

Returns the value of attribute input_id.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def input_id
  @input_id
end

#inputIdObject

Returns the value of attribute inputId.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def inputId
  @inputId
end

#languageObject

Returns the value of attribute language.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def language
  @language
end

#localityObject

Returns the value of attribute locality.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def locality
  @locality
end

#organizationObject

Returns the value of attribute organization.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def organization
  @organization
end

#postal_codeObject

Returns the value of attribute postal_code.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def postal_code
  @postal_code
end

#resultObject

Returns the value of attribute result.



19
20
21
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 19

def result
  @result
end

Instance Method Details

#add_custom_parameter(parameter, value) ⇒ Object



43
44
45
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 43

def add_custom_parameter(parameter, value)
  @custom_param_hash[parameter] = value
end

#ensure_enough_infoObject



75
76
77
78
79
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 75

def ensure_enough_info
  raise UnprocessableEntityError, 'Country field is required.' if field_is_missing(@country)
  raise UnprocessableEntityError, 'Either freeform or address1 is required.' if field_is_missing(@freeform) && field_is_missing(@address1)
  LanguageMode.from_value(@language) unless @language.nil?
end

#field_is_missing(field) ⇒ Object



67
68
69
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 67

def field_is_missing(field)
  field.nil? or field.empty?
end

#field_is_set(field) ⇒ Object



71
72
73
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 71

def field_is_set(field)
  not field_is_missing(field)
end

#has_freeformObject



51
52
53
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 51

def has_freeform
  field_is_set(@freeform)
end

#has_postal_codeObject



59
60
61
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 59

def has_postal_code
  field_is_set(@postal_code)
end

#missing_address1Object



55
56
57
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 55

def missing_address1
  field_is_missing(@address1)
end

#missing_countryObject



47
48
49
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 47

def missing_country
  field_is_missing(@country)
end

#missing_locality_or_administrative_areaObject



63
64
65
# File 'lib/smartystreets_ruby_sdk/international_street/lookup.rb', line 63

def missing_locality_or_administrative_area
  field_is_missing(@locality) or field_is_missing(@administrative_area)
end