Class: Plaid::Connector
- Inherits:
-
Object
- Object
- Plaid::Connector
- Defined in:
- lib/plaid/connector.rb
Overview
Internal: A class encapsulating HTTP requests to the Plaid API servers
Constant Summary collapse
- DEFAULT_TIMEOUT =
Internal: Default read timeout for HTTP calls.
120
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#delete(payload) ⇒ Object
Internal: Run DELETE request.
-
#get(payload = {}) ⇒ Object
Internal: Run GET request.
-
#initialize(path, subpath = nil, auth: false, client: nil) ⇒ Connector
constructor
Internal: Prepare to run request.
-
#mfa? ⇒ Boolean
Internal: Check if MFA response received.
-
#patch(payload) ⇒ Object
Internal: Run PATCH request.
-
#post(payload) ⇒ Object
Internal: Run POST request.
Constructor Details
#initialize(path, subpath = nil, auth: false, client: nil) ⇒ Connector
Internal: 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).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/plaid/connector.rb', line 8 def body @body end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
8 9 10 |
# File 'lib/plaid/connector.rb', line 8 def http @http end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/plaid/connector.rb', line 8 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/plaid/connector.rb', line 8 def response @response end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/plaid/connector.rb', line 8 def uri @uri end |
Instance Method Details
#delete(payload) ⇒ Object
Internal: Run DELETE request.
Adds client_id and secret to the payload if @auth is true.
payload - The Hash with data.
Returns the parsed JSON response body.
77 78 79 |
# File 'lib/plaid/connector.rb', line 77 def delete(payload) post_like payload, Net::HTTP::Delete.new(@uri.path) end |
#get(payload = {}) ⇒ Object
Internal: Run GET request.
Returns the parsed JSON response body.
40 41 42 43 44 45 46 |
# 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? ⇒ Boolean
Internal: Check if MFA response received.
Returns true if response has code 201.
84 85 86 |
# File 'lib/plaid/connector.rb', line 84 def mfa? @response.is_a?(Net::HTTPCreated) end |
#patch(payload) ⇒ Object
Internal: Run PATCH request.
Adds client_id and secret to the payload if @auth is true.
payload - The Hash with data.
Returns the parsed JSON response body.
66 67 68 |
# File 'lib/plaid/connector.rb', line 66 def patch(payload) post_like payload, Net::HTTP::Patch.new(@uri.path) end |
#post(payload) ⇒ Object
Internal: Run POST request.
Adds client_id and secret to the payload if @auth is true.
payload - The Hash with data.
Returns the parsed JSON response body.
55 56 57 |
# File 'lib/plaid/connector.rb', line 55 def post(payload) post_like payload, Net::HTTP::Post.new(@uri.path) end |