Class: Plaid::Item

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

Overview

Metadata about the Item.

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(item_id:, webhook:, error:, available_products:, billed_products:, consent_expiration_time:, update_type:, institution_id: SKIP, additional_properties: nil) ⇒ Item

Returns a new instance of Item.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/plaid/models/item.rb', line 94

def initialize(item_id:, webhook:, error:, available_products:,
               billed_products:, consent_expiration_time:, update_type:,
               institution_id: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @item_id = item_id
  @institution_id = institution_id unless institution_id == SKIP
  @webhook = webhook
  @error = error
  @available_products = available_products
  @billed_products = billed_products
  @consent_expiration_time = consent_expiration_time
  @update_type = update_type
  @additional_properties = additional_properties
end

Instance Attribute Details

#available_productsArray[Products]

A list of products available for the Item that have not yet been accessed.

Returns:



39
40
41
# File 'lib/plaid/models/item.rb', line 39

def available_products
  @available_products
end

#billed_productsArray[Products]

A list of products that have been billed for the Item. Note - ‘billed_products` is populated in all environments but only requests in Production are billed.

Returns:



45
46
47
# File 'lib/plaid/models/item.rb', line 45

def billed_products
  @billed_products
end

The RFC 3339 timestamp after which the consent provided by the end user will expire. Upon consent expiration, the item will enter the ‘ITEM_LOGIN_REQUIRED` error state. To circumvent the `ITEM_LOGIN_REQUIRED` error and maintain continuous consent, the end user can reauthenticate via Link’s update mode in advance of the consent expiration time. Note - This is only relevant for certain OAuth-based institutions. For all other institutions, this field will be null.

Returns:

  • (DateTime)


55
56
57
# File 'lib/plaid/models/item.rb', line 55

def consent_expiration_time
  @consent_expiration_time
end

#errorError

We use standard HTTP response codes for success and failure notifications, and our errors are further classified by ‘error_type`. In general, 200 HTTP codes correspond to success, 40X codes are for developer- or user-related failures, and 50X codes are for Plaid-related issues. Error fields will be `null` if no error has occurred.

Returns:



35
36
37
# File 'lib/plaid/models/item.rb', line 35

def error
  @error
end

#institution_idString

The Plaid Institution ID associated with the Item. Field is ‘null` for Items created via Same Day Micro-deposits.

Returns:

  • (String)


23
24
25
# File 'lib/plaid/models/item.rb', line 23

def institution_id
  @institution_id
end

#item_idString

The Plaid Item ID. The ‘item_id` is always unique; linking the same account at the same institution twice will result in two Items with different `item_id` values. Like all Plaid identifiers, the `item_id` is case-sensitive.

Returns:

  • (String)


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

def item_id
  @item_id
end

#update_typeUpdateType

Indicates whether an Item requires user interaction to be updated, which can be the case for Items with some forms of two-factor authentication. ‘background` - Item can be updated in the background `user_present_required` - Item requires user interaction to be updated

Returns:



62
63
64
# File 'lib/plaid/models/item.rb', line 62

def update_type
  @update_type
end

#webhookString

The URL registered to receive webhooks for the Item.

Returns:

  • (String)


27
28
29
# File 'lib/plaid/models/item.rb', line 27

def webhook
  @webhook
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/plaid/models/item.rb', line 112

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  item_id = hash.key?('item_id') ? hash['item_id'] : nil
  webhook = hash.key?('webhook') ? hash['webhook'] : nil
  error = Error.from_hash(hash['error']) if hash['error']
  available_products =
    hash.key?('available_products') ? hash['available_products'] : nil
  billed_products =
    hash.key?('billed_products') ? hash['billed_products'] : nil
  consent_expiration_time = if hash.key?('consent_expiration_time')
                              (DateTimeHelper.from_rfc3339(hash['consent_expiration_time']) if hash['consent_expiration_time'])
                            end
  update_type = hash.key?('update_type') ? hash['update_type'] : nil
  institution_id =
    hash.key?('institution_id') ? hash['institution_id'] : SKIP

  # 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.
  Item.new(item_id: item_id,
           webhook: webhook,
           error: error,
           available_products: available_products,
           billed_products: billed_products,
           consent_expiration_time: consent_expiration_time,
           update_type: update_type,
           institution_id: institution_id,
           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['item_id'] = 'item_id'
  @_hash['institution_id'] = 'institution_id'
  @_hash['webhook'] = 'webhook'
  @_hash['error'] = 'error'
  @_hash['available_products'] = 'available_products'
  @_hash['billed_products'] = 'billed_products'
  @_hash['consent_expiration_time'] = 'consent_expiration_time'
  @_hash['update_type'] = 'update_type'
  @_hash
end

.nullablesObject

An array for nullable fields



86
87
88
89
90
91
92
# File 'lib/plaid/models/item.rb', line 86

def self.nullables
  %w[
    institution_id
    webhook
    consent_expiration_time
  ]
end

.optionalsObject

An array for optional fields



79
80
81
82
83
# File 'lib/plaid/models/item.rb', line 79

def self.optionals
  %w[
    institution_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



164
165
166
167
168
169
170
171
# File 'lib/plaid/models/item.rb', line 164

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} item_id: #{@item_id.inspect}, institution_id: #{@institution_id.inspect},"\
  " webhook: #{@webhook.inspect}, error: #{@error.inspect}, available_products:"\
  " #{@available_products.inspect}, billed_products: #{@billed_products.inspect},"\
  " consent_expiration_time: #{@consent_expiration_time.inspect}, update_type:"\
  " #{@update_type.inspect}, additional_properties: #{@additional_properties}>"
end


149
150
151
# File 'lib/plaid/models/item.rb', line 149

def to_custom_consent_expiration_time
  DateTimeHelper.to_rfc3339(consent_expiration_time)
end

#to_sObject

Provides a human-readable string representation of the object.



154
155
156
157
158
159
160
161
# File 'lib/plaid/models/item.rb', line 154

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} item_id: #{@item_id}, institution_id: #{@institution_id}, webhook:"\
  " #{@webhook}, error: #{@error}, available_products: #{@available_products},"\
  " billed_products: #{@billed_products}, consent_expiration_time:"\
  " #{@consent_expiration_time}, update_type: #{@update_type}, additional_properties:"\
  " #{@additional_properties}>"
end