Class: Plaid::Client

Inherits:
Object
  • Object
show all
Extended by:
SubproductMixin
Defined in:
lib/plaid/client.rb

Overview

Public: The main interface to Plaid API.

Constant Summary collapse

ENVIRONMENTS =

Public: All possible environments for the client to use.

%i[sandbox development production].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubproductMixin

subproduct

Constructor Details

#initialize(env:, client_id:, secret:, public_key:, &block) ⇒ Client

Public: Construct a Client instance

Optionally takes a block to allow overriding the default Faraday connection options.

env - The Symbol (:sandbox, :development, :production) client_id - The String Plaid account client ID to authenticate requests secret - The String Plaid account secret to authenticate requests public_key - The String Plaid account public key to authenticate requests



20
21
22
23
24
25
26
27
28
# File 'lib/plaid/client.rb', line 20

def initialize(env:, client_id:, secret:, public_key:, &block)
  @env        = env.to_sym
  @api_host   = api_host
  @client_id  = client_id
  @secret     = secret
  @public_key = public_key

  create_connection(&block)
end

Instance Attribute Details

#envObject (readonly)

Public: The current environment in use (one of ENVIRONMENTS).



9
10
11
# File 'lib/plaid/client.rb', line 9

def env
  @env
end

Class Method Details

.build_default_connection(builder) ⇒ Object

Public: Set Plaid defaults on the Faraday connection.

builder - The Faraday builder object.



123
124
125
126
127
128
129
130
# File 'lib/plaid/client.rb', line 123

def self.build_default_connection(builder)
  builder.options[:timeout] = Plaid::Middleware::NETWORK_TIMEOUT
  builder.headers = Plaid::Middleware::NETWORK_HEADERS
  builder.request :json
  builder.use Plaid::Middleware
  builder.response :json, content_type: /\bjson$/
  builder.adapter Faraday.default_adapter
end

Instance Method Details

#accountsObject

:attr_reader: Public: The Plaid::Accounts product accessor.



35
# File 'lib/plaid/client.rb', line 35

subproduct :accounts

#authObject

:attr_reader: Public: The Plaid::Auth product accessor.



40
# File 'lib/plaid/client.rb', line 40

subproduct :auth

#categoriesObject

:attr_reader: Public: The Plaid::Categories product accessor.



45
# File 'lib/plaid/client.rb', line 45

subproduct :categories

#credit_detailsObject

:attr_reader: Public: The Plaid::CreditDetails product accessor.



50
# File 'lib/plaid/client.rb', line 50

subproduct :credit_details

#identityObject

:attr_reader: Public: The Plaid::Identity product accessor.



55
# File 'lib/plaid/client.rb', line 55

subproduct :identity

#incomeObject

:attr_reader: Public: The Plaid::Income product accessor.



60
# File 'lib/plaid/client.rb', line 60

subproduct :income

#institutionsObject

:attr_reader: Public: The Plaid::Institutions product accessor.



65
# File 'lib/plaid/client.rb', line 65

subproduct :institutions

#itemObject

:attr_reader: Public: The Plaid::Item product accessor.



70
# File 'lib/plaid/client.rb', line 70

subproduct :item

#post(path, payload) ⇒ Object

Public: Make a post request

path - Path or URL to make the request to payload - The payload or data to post

Returns the resulting parsed JSON of the request



93
94
95
# File 'lib/plaid/client.rb', line 93

def post(path, payload)
  @connection.post(path, payload).body
end

#post_with_auth(path, payload) ⇒ Object

Public: Make a post request with appended authentication fields

path - Path or URL to make the request to payload - The payload or data to post

Returns the resulting parsed JSON of the request



103
104
105
106
107
108
# File 'lib/plaid/client.rb', line 103

def post_with_auth(path, payload)
  @connection.post(
    path,
    payload.merge(client_id: @client_id, secret: @secret)
  ).body
end

#post_with_public_key(path, payload) ⇒ Object

Public: Make a post request with appended public key field.

path - Path or URL to make the request to. payload - The payload or data to post.

Returns the resulting parsed JSON of the request.



116
117
118
# File 'lib/plaid/client.rb', line 116

def post_with_public_key(path, payload)
  @connection.post(path, payload.merge(public_key: @public_key)).body
end

#processorObject

:attr_reader: Public: The Plaid::Processor product accessor.



75
# File 'lib/plaid/client.rb', line 75

subproduct :processor

#sandboxObject

:attr_reader: Public: The Plaid::Sandbox product accessor.



80
# File 'lib/plaid/client.rb', line 80

subproduct :sandbox

#transactionsObject

:attr_reader: Public: The Plaid::Transactions product accessor.



85
# File 'lib/plaid/client.rb', line 85

subproduct :transactions