Class: Plaid::TransactionLocation

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/plaid/models/transaction_location.rb

Overview

A representation of where a transaction took place

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(address:, city:, region:, postal_code:, country:, lat:, lon:, store_number:, additional_properties: nil) ⇒ TransactionLocation

Returns a new instance of TransactionLocation.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/plaid/models/transaction_location.rb', line 77

def initialize(address:, city:, region:, postal_code:, country:, lat:, lon:,
               store_number:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @address = address
  @city = city
  @region = region
  @postal_code = postal_code
  @country = country
  @lat = lat
  @lon = lon
  @store_number = store_number
  @additional_properties = additional_properties
end

Instance Attribute Details

#addressString

The street address where the transaction occurred.

Returns:

  • (String)


14
15
16
# File 'lib/plaid/models/transaction_location.rb', line 14

def address
  @address
end

#cityString

The city where the transaction occurred.

Returns:

  • (String)


18
19
20
# File 'lib/plaid/models/transaction_location.rb', line 18

def city
  @city
end

#countryString

The ISO 3166-1 alpha-2 country code where the transaction occurred.

Returns:

  • (String)


30
31
32
# File 'lib/plaid/models/transaction_location.rb', line 30

def country
  @country
end

#latFloat

The latitude where the transaction occurred.

Returns:

  • (Float)


34
35
36
# File 'lib/plaid/models/transaction_location.rb', line 34

def lat
  @lat
end

#lonFloat

The longitude where the transaction occurred.

Returns:

  • (Float)


38
39
40
# File 'lib/plaid/models/transaction_location.rb', line 38

def lon
  @lon
end

#postal_codeString

The postal code where the transaction occurred.

Returns:

  • (String)


26
27
28
# File 'lib/plaid/models/transaction_location.rb', line 26

def postal_code
  @postal_code
end

#regionString

The region or state where the transaction occurred.

Returns:

  • (String)


22
23
24
# File 'lib/plaid/models/transaction_location.rb', line 22

def region
  @region
end

#store_numberString

The merchant defined store number where the transaction occurred.

Returns:

  • (String)


42
43
44
# File 'lib/plaid/models/transaction_location.rb', line 42

def store_number
  @store_number
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/plaid/models/transaction_location.rb', line 94

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  address = hash.key?('address') ? hash['address'] : nil
  city = hash.key?('city') ? hash['city'] : nil
  region = hash.key?('region') ? hash['region'] : nil
  postal_code = hash.key?('postal_code') ? hash['postal_code'] : nil
  country = hash.key?('country') ? hash['country'] : nil
  lat = hash.key?('lat') ? hash['lat'] : nil
  lon = hash.key?('lon') ? hash['lon'] : nil
  store_number = hash.key?('store_number') ? hash['store_number'] : nil

  # 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.
  TransactionLocation.new(address: address,
                          city: city,
                          region: region,
                          postal_code: postal_code,
                          country: country,
                          lat: lat,
                          lon: lon,
                          store_number: store_number,
                          additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/plaid/models/transaction_location.rb', line 45

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['address'] = 'address'
  @_hash['city'] = 'city'
  @_hash['region'] = 'region'
  @_hash['postal_code'] = 'postal_code'
  @_hash['country'] = 'country'
  @_hash['lat'] = 'lat'
  @_hash['lon'] = 'lon'
  @_hash['store_number'] = 'store_number'
  @_hash
end

.nullablesObject

An array for nullable fields



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/plaid/models/transaction_location.rb', line 64

def self.nullables
  %w[
    address
    city
    region
    postal_code
    country
    lat
    lon
    store_number
  ]
end

.optionalsObject

An array for optional fields



59
60
61
# File 'lib/plaid/models/transaction_location.rb', line 59

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



135
136
137
138
139
140
141
# File 'lib/plaid/models/transaction_location.rb', line 135

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} address: #{@address.inspect}, city: #{@city.inspect}, region:"\
  " #{@region.inspect}, postal_code: #{@postal_code.inspect}, country: #{@country.inspect},"\
  " lat: #{@lat.inspect}, lon: #{@lon.inspect}, store_number: #{@store_number.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



127
128
129
130
131
132
# File 'lib/plaid/models/transaction_location.rb', line 127

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} address: #{@address}, city: #{@city}, region: #{@region}, postal_code:"\
  " #{@postal_code}, country: #{@country}, lat: #{@lat}, lon: #{@lon}, store_number:"\
  " #{@store_number}, additional_properties: #{@additional_properties}>"
end