A class encapsulating HTTP requests to the Plaid API servers

Sections
Methods
D
G
M
N
P
Attributes
[R] body
[R] http
[R] request
[R] response
[R] uri
Internal
Constants
DEFAULT_TIMEOUT = 120
 

Default read timeout for HTTP calls.

Class Public methods
new(path, subpath = nil, auth: false, client: nil)

Prepare to run request.

path

The String path without leading slash. E.g. 'connect'

subpath

The String subpath. E.g. 'get'

auth

The Boolean flag indicating that client_id and secret should be included into the request payload.

client

The Plaid::Client instance used to connect (default: Plaid.client).

# File lib/plaid/connector.rb, line 21
def initialize(path, subpath = nil, auth: false, client: nil)
  @auth = auth
  @client = client || Plaid.client
  verify_configuration

  path = File.join(@client.env, path.to_s)
  path = File.join(path, subpath.to_s) if subpath

  @uri = URI.parse(path)

  @http = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl = true

  @http.read_timeout = Plaid.read_timeout || DEFAULT_TIMEOUT
end
Instance Public methods
delete(payload)

Run DELETE request.

Adds client_id and secret to the payload if @auth is true.

payload

The Hash with data.

Returns

Returns the parsed JSON response body.

# File lib/plaid/connector.rb, line 77
def delete(payload)
  post_like payload, Net::HTTP::Delete.new(@uri.path)
end
get(payload = {})

Run GET request.

Returns

Returns the parsed JSON response body.

# File lib/plaid/connector.rb, line 40
def get(payload = {})
  payload = with_credentials(payload)

  @uri.query = URI.encode_www_form(payload) unless payload.empty?

  run Net::HTTP::Get.new(@uri)
end
mfa?()

Check if MFA response received.

Returns

Returns true if response has code 201.

# File lib/plaid/connector.rb, line 84
def mfa?
  @response.is_a?(Net::HTTPCreated)
end
patch(payload)

Run PATCH request.

Adds client_id and secret to the payload if @auth is true.

payload

The Hash with data.

Returns

Returns the parsed JSON response body.

# File lib/plaid/connector.rb, line 66
def patch(payload)
  post_like payload, Net::HTTP::Patch.new(@uri.path)
end
post(payload)

Run POST request.

Adds client_id and secret to the payload if @auth is true.

payload

The Hash with data.

Returns

Returns the parsed JSON response body.

# File lib/plaid/connector.rb, line 55
def post(payload)
  post_like payload, Net::HTTP::Post.new(@uri.path)
end