Class: Checkbook::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/checkbook/api/card.rb,
lib/checkbook/models/card.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Card

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



79
80
81
# File 'lib/checkbook/models/card.rb', line 79

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/checkbook/api/card.rb', line 17

def api_client
  @api_client
end

#card_numberObject

Last 4 of card number



19
20
21
# File 'lib/checkbook/models/card.rb', line 19

def card_number
  @card_number
end

#dateObject

Card creation timestamp



22
23
24
# File 'lib/checkbook/models/card.rb', line 22

def date
  @date
end

#defaultObject

Indicates the default card



25
26
27
# File 'lib/checkbook/models/card.rb', line 25

def default
  @default
end

#expiration_dateObject

Card expiration date



28
29
30
# File 'lib/checkbook/models/card.rb', line 28

def expiration_date
  @expiration_date
end

#idObject

Unique identifier for card



31
32
33
# File 'lib/checkbook/models/card.rb', line 31

def id
  @id
end

#nameObject

Name of the card



34
35
36
# File 'lib/checkbook/models/card.rb', line 34

def name
  @name
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/checkbook/models/card.rb', line 270

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = ::Checkbook.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



49
50
51
# File 'lib/checkbook/models/card.rb', line 49

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



54
55
56
# File 'lib/checkbook/models/card.rb', line 54

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



37
38
39
40
41
42
43
44
45
46
# File 'lib/checkbook/models/card.rb', line 37

def self.attribute_map
  {
    :'card_number' => :'card_number',
    :'date' => :'date',
    :'default' => :'default',
    :'expiration_date' => :'expiration_date',
    :'id' => :'id',
    :'name' => :'name'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/checkbook/models/card.rb', line 246

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



71
72
73
74
75
# File 'lib/checkbook/models/card.rb', line 71

def self.openapi_nullable
  Set.new([
    :'name'
  ])
end

.openapi_typesObject

Attribute type mapping.



59
60
61
62
63
64
65
66
67
68
# File 'lib/checkbook/models/card.rb', line 59

def self.openapi_types
  {
    :'card_number' => :'String',
    :'date' => :'String',
    :'default' => :'Boolean',
    :'expiration_date' => :'String',
    :'id' => :'String',
    :'name' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



220
221
222
223
224
225
226
227
228
229
# File 'lib/checkbook/models/card.rb', line 220

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      card_number == o.card_number &&
      date == o.date &&
      default == o.default &&
      expiration_date == o.expiration_date &&
      id == o.id &&
      name == o.name
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/checkbook/models/card.rb', line 341

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#delete_card(card_id, opts = {}) ⇒ nil

Remove card Remove the specified card

Parameters:

  • card_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (nil)


27
28
29
30
# File 'lib/checkbook/api/card.rb', line 27

def delete_card(card_id, opts = {})
  delete_card_with_http_info(card_id, opts)
  nil
end

#delete_card_with_http_info(card_id, opts = {}) ⇒ Array<(nil, Integer, Hash)>

Remove card Remove the specified card

Parameters:

  • card_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(nil, Integer, Hash)>)

    nil, response status code and response headers



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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/checkbook/api/card.rb', line 37

def delete_card_with_http_info(card_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: Card.delete_card ...'
  end
  # verify the required parameter 'card_id' is set
  if @api_client.config.client_side_validation && card_id.nil?
    fail ArgumentError, "Missing the required parameter 'card_id' when calling Card.delete_card"
  end
  # resource path
  local_var_path = '/v3/account/card/{card_id}'.sub('{' + 'card_id' + '}', CGI.escape(card_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type]

  # auth_names
  auth_names = opts[:debug_auth_names] || ['token']

  new_options = opts.merge(
    :operation => :"Card.delete_card",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: Card#delete_card\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


233
234
235
# File 'lib/checkbook/models/card.rb', line 233

def eql?(o)
  self == o
end

#get_cards(opts = {}) ⇒ GetCardsResponse

Get cards Return the cards

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



89
90
91
92
# File 'lib/checkbook/api/card.rb', line 89

def get_cards(opts = {})
  data, _status_code, _headers = get_cards_with_http_info(opts)
  data
end

#get_cards_with_http_info(opts = {}) ⇒ Array<(GetCardsResponse, Integer, Hash)>

Get cards Return the cards

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(GetCardsResponse, Integer, Hash)>)

    GetCardsResponse data, response status code and response headers



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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/checkbook/api/card.rb', line 98

def get_cards_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: Card.get_cards ...'
  end
  # resource path
  local_var_path = '/v3/account/card'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'GetCardsResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['token']

  new_options = opts.merge(
    :operation => :"Card.get_cards",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: Card#get_cards\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



239
240
241
# File 'lib/checkbook/models/card.rb', line 239

def hash
  [card_number, date, default, expiration_date, id, name].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/checkbook/models/card.rb', line 130

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @card_number.nil?
    invalid_properties.push('invalid value for "card_number", card_number cannot be nil.')
  end

  if @date.nil?
    invalid_properties.push('invalid value for "date", date cannot be nil.')
  end

  if @default.nil?
    invalid_properties.push('invalid value for "default", default cannot be nil.')
  end

  if @expiration_date.nil?
    invalid_properties.push('invalid value for "expiration_date", expiration_date cannot be nil.')
  end

  if @id.nil?
    invalid_properties.push('invalid value for "id", id cannot be nil.')
  end

  invalid_properties
end

#post_card(create_card_request, opts = {}) ⇒ CreateCardResponse

Add card Add a new card

Parameters:

  • create_card_request (CreateCardRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



147
148
149
150
# File 'lib/checkbook/api/card.rb', line 147

def post_card(create_card_request, opts = {})
  data, _status_code, _headers = post_card_with_http_info(create_card_request, opts)
  data
end

#post_card_with_http_info(create_card_request, opts = {}) ⇒ Array<(CreateCardResponse, Integer, Hash)>

Add card Add a new card

Parameters:

  • create_card_request (CreateCardRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(CreateCardResponse, Integer, Hash)>)

    CreateCardResponse data, response status code and response headers



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/checkbook/api/card.rb', line 157

def post_card_with_http_info(create_card_request, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: Card.post_card ...'
  end
  # verify the required parameter 'create_card_request' is set
  if @api_client.config.client_side_validation && create_card_request.nil?
    fail ArgumentError, "Missing the required parameter 'create_card_request' when calling Card.post_card"
  end
  # resource path
  local_var_path = '/v3/account/card'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(create_card_request)

  # return_type
  return_type = opts[:debug_return_type] || 'CreateCardResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['token']

  new_options = opts.merge(
    :operation => :"Card.post_card",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: Card#post_card\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#put_card(card_id, update_card_request, opts = {}) ⇒ nil

Update card Update the specified card

Parameters:

  • card_id (String)
  • update_card_request (UpdateCardRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (nil)


216
217
218
219
# File 'lib/checkbook/api/card.rb', line 216

def put_card(card_id, update_card_request, opts = {})
  put_card_with_http_info(card_id, update_card_request, opts)
  nil
end

#put_card_with_http_info(card_id, update_card_request, opts = {}) ⇒ Array<(nil, Integer, Hash)>

Update card Update the specified card

Parameters:

  • card_id (String)
  • update_card_request (UpdateCardRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(nil, Integer, Hash)>)

    nil, response status code and response headers



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/checkbook/api/card.rb', line 227

def put_card_with_http_info(card_id, update_card_request, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: Card.put_card ...'
  end
  # verify the required parameter 'card_id' is set
  if @api_client.config.client_side_validation && card_id.nil?
    fail ArgumentError, "Missing the required parameter 'card_id' when calling Card.put_card"
  end
  # verify the required parameter 'update_card_request' is set
  if @api_client.config.client_side_validation && update_card_request.nil?
    fail ArgumentError, "Missing the required parameter 'update_card_request' when calling Card.put_card"
  end
  # resource path
  local_var_path = '/v3/account/card/{card_id}'.sub('{' + 'card_id' + '}', CGI.escape(card_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(update_card_request)

  # return_type
  return_type = opts[:debug_return_type]

  # auth_names
  auth_names = opts[:debug_auth_names] || ['token']

  new_options = opts.merge(
    :operation => :"Card.put_card",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: Card#put_card\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



317
318
319
# File 'lib/checkbook/models/card.rb', line 317

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/checkbook/models/card.rb', line 323

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



311
312
313
# File 'lib/checkbook/models/card.rb', line 311

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



158
159
160
161
162
163
164
165
166
# File 'lib/checkbook/models/card.rb', line 158

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @card_number.nil?
  return false if @date.nil?
  return false if @default.nil?
  return false if @expiration_date.nil?
  return false if @id.nil?
  true
end