Class: Bandwidth::Result

Inherits:
BaseModel show all
Defined in:
lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb

Overview

Result Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(response_code = nil, message = nil, e_164_format = nil, formatted = nil, country = nil, line_type = nil, line_provider = nil, mobile_country_code = nil, mobile_network_code = nil) ⇒ Result

Returns a new instance of Result.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 83

def initialize(response_code = nil,
               message = nil,
               e_164_format = nil,
               formatted = nil,
               country = nil,
               line_type = nil,
               line_provider = nil,
               mobile_country_code = nil,
               mobile_network_code = nil)
  @response_code = response_code unless response_code == SKIP
  @message = message unless message == SKIP
  @e_164_format = e_164_format unless e_164_format == SKIP
  @formatted = formatted unless formatted == SKIP
  @country = country unless country == SKIP
  @line_type = line_type unless line_type == SKIP
  @line_provider = line_provider unless line_provider == SKIP
  @mobile_country_code = mobile_country_code unless mobile_country_code == SKIP
  @mobile_network_code = mobile_network_code unless mobile_network_code == SKIP
end

Instance Attribute Details

#countryString

The country of the telephone number.

Returns:

  • (String)


30
31
32
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 30

def country
  @country
end

#e_164_formatString

The telephone number in E.164 format.

Returns:

  • (String)


22
23
24
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 22

def e_164_format
  @e_164_format
end

#formattedString

The formatted version of the telephone number.

Returns:

  • (String)


26
27
28
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 26

def formatted
  @formatted
end

#line_providerString

The service provider of the telephone number.

Returns:

  • (String)


38
39
40
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 38

def line_provider
  @line_provider
end

#line_typeString

The line type of the telephone number.

Returns:

  • (String)


34
35
36
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 34

def line_type
  @line_type
end

#messageString

Message associated with the response code.

Returns:

  • (String)


18
19
20
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 18

def message
  @message
end

#mobile_country_codeString

The first half of the Home Network Identity (HNI).

Returns:

  • (String)


42
43
44
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 42

def mobile_country_code
  @mobile_country_code
end

#mobile_network_codeString

The second half of the HNI.

Returns:

  • (String)


46
47
48
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 46

def mobile_network_code
  @mobile_network_code
end

#response_codeInteger

Our vendor’s response code.

Returns:

  • (Integer)


14
15
16
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 14

def response_code
  @response_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 104

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  response_code = hash.key?('Response Code') ? hash['Response Code'] : SKIP
  message = hash.key?('Message') ? hash['Message'] : SKIP
  e_164_format = hash.key?('E.164 Format') ? hash['E.164 Format'] : SKIP
  formatted = hash.key?('Formatted') ? hash['Formatted'] : SKIP
  country = hash.key?('Country') ? hash['Country'] : SKIP
  line_type = hash.key?('Line Type') ? hash['Line Type'] : SKIP
  line_provider = hash.key?('Line Provider') ? hash['Line Provider'] : SKIP
  mobile_country_code =
    hash.key?('Mobile Country Code') ? hash['Mobile Country Code'] : SKIP
  mobile_network_code =
    hash.key?('Mobile Network Code') ? hash['Mobile Network Code'] : SKIP

  # Create object from extracted values.
  Result.new(response_code,
             message,
             e_164_format,
             formatted,
             country,
             line_type,
             line_provider,
             mobile_country_code,
             mobile_network_code)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['response_code'] = 'Response Code'
  @_hash['message'] = 'Message'
  @_hash['e_164_format'] = 'E.164 Format'
  @_hash['formatted'] = 'Formatted'
  @_hash['country'] = 'Country'
  @_hash['line_type'] = 'Line Type'
  @_hash['line_provider'] = 'Line Provider'
  @_hash['mobile_country_code'] = 'Mobile Country Code'
  @_hash['mobile_network_code'] = 'Mobile Network Code'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



79
80
81
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 79

def nullables
  []
end

#optionalsObject

An array for optional fields



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb', line 64

def optionals
  %w[
    response_code
    message
    e_164_format
    formatted
    country
    line_type
    line_provider
    mobile_country_code
    mobile_network_code
  ]
end