Class: Plaid::Statements::Client
- Inherits:
-
Object
- Object
- Plaid::Statements::Client
- Defined in:
- lib/plaid/statements/client.rb
Instance Method Summary collapse
-
#download(request_options: {}, **params) ⇒ String
The
/statements/downloadendpoint retrieves a single statement PDF in binary format. - #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Plaid::Types::StatementsListResponse
The
/statements/listendpoint retrieves a list of all statements associated with an Item. -
#refresh(request_options: {}, **params) ⇒ Plaid::Types::StatementsRefreshResponse
/statements/refreshinitiates an on-demand extraction to fetch the statements for the provided dates.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/plaid/statements/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#download(request_options: {}, **params) ⇒ String
The /statements/download endpoint retrieves a single statement PDF in binary format. The response will
contain a Plaid-Content-Hash header containing a SHA 256 checksum of the statement. This can be used to verify
that the file being sent by Plaid is the same file that was downloaded to your system.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/plaid/statements/client.rb', line 82 def download(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "statements/download", body: Plaid::Statements::Types::StatementsDownloadRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i return response.body if code.between?(200, 299) error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end |
#list(request_options: {}, **params) ⇒ Plaid::Types::StatementsListResponse
The /statements/list endpoint retrieves a list of all statements associated with an Item.
27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/plaid/statements/client.rb', line 27 def list(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "statements/list", body: Plaid::Statements::Types::StatementsListRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::StatementsListResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#refresh(request_options: {}, **params) ⇒ Plaid::Types::StatementsRefreshResponse
/statements/refresh initiates an on-demand extraction to fetch the statements for the provided dates.
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 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/plaid/statements/client.rb', line 130 def refresh(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "statements/refresh", body: Plaid::Statements::Types::StatementsRefreshRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::StatementsRefreshResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |