Class: Plaid::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/plaid/category.rb

Overview

Public: A class which encapsulates information about a Plaid category.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ Category

Internal: Initialize a Category with given fields.



15
16
17
18
19
# File 'lib/plaid/category.rb', line 15

def initialize(fields)
  @type = fields['type'].to_sym
  @hierarchy = fields['hierarchy']
  @id = fields['id']
end

Instance Attribute Details

#hierarchyObject (readonly)

Public: The Array of String hierarchy. E.g. [“Food and Drink”, “Nightlife”].



12
13
14
# File 'lib/plaid/category.rb', line 12

def hierarchy
  @hierarchy
end

#idObject (readonly)

Public: The String category ID, e.g. “21010006”.



5
6
7
# File 'lib/plaid/category.rb', line 5

def id
  @id
end

#typeObject (readonly)

Public: The Symbol category type. One of :special, :place, :digital.



8
9
10
# File 'lib/plaid/category.rb', line 8

def type
  @type
end

Class Method Details

.all(client: nil) ⇒ Object

Public: Get information about all available categories.

Does a GET /categories call.

client - The Plaid::Client instance used to connect

(default: Plaid.client).

Returns an Array of Category instances.



42
43
44
45
46
# File 'lib/plaid/category.rb', line 42

def self.all(client: nil)
  Connector.new(:categories, client: client).get.map do |category_data|
    new(category_data)
  end
end

.get(id, client: nil) ⇒ Object

Public: Get information about a given category.

Does a GET /categories/:id call.

id - the String category ID (e.g. “17001013”). client - The Plaid::Client instance used to connect

(default: Plaid.client).

Returns a Category instance or raises Plaid::NotFoundError if category with given id is not found.



58
59
60
# File 'lib/plaid/category.rb', line 58

def self.get(id, client: nil)
  new Connector.new(:categories, id, client: client).get
end

Instance Method Details

#inspectObject Also known as: to_s

Public: Get a String representation of Category.

Returns a String.



24
25
26
27
# File 'lib/plaid/category.rb', line 24

def inspect
  "#<Plaid::Category id=#{id.inspect}, type=#{type.inspect}, " \
  "hierarchy=#{hierarchy.inspect}>"
end