### Get Plaid Institutions Data in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Demonstrates how to fetch a list of financial institutions supported by Plaid. The example shows how to use pagination parameters (count and offset) and filter by country codes. ```ruby institutions_get_request = Plaid::InstitutionsGetRequest.new({ :count => 3, :offset => 1, :country_codes => ["US"] }) response = client.institutions_get(institutions_get_request) ``` -------------------------------- ### Install Plaid Gem Directly (Shell) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Use this command to install the Plaid gem globally or outside of a Bundler-managed project. It installs the gem directly from RubyGems. ```shell $ gem install plaid ``` -------------------------------- ### Install Gems with Bundler (Shell) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Run this command in your terminal after updating the Gemfile. Bundler resolves and installs all required gems, including the Plaid gem. ```shell $ bundle ``` -------------------------------- ### Configuring Plaid Ruby Gem (v2.0.0+) Source: https://github.com/plaid/plaid-ruby/blob/master/UPGRADING.md This snippet shows the updated configuration block for the Plaid Ruby gem starting from version 2.0.0. It demonstrates the new parameter names `client_id` (formerly `customer_id`) and `env` (formerly `environment_location`) within the `Plaid.config` block. The `secret` parameter remains unchanged. ```ruby Plaid.config do |p| p.client_id = '<<< Plaid provided client ID >>>' # WAS: customer_id p.secret = '<<< Plaid provided secret key >>>' # No change p.env = :tartan # or :api for production # WAS: environment_location end ``` -------------------------------- ### Parsing Time and Date in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Demonstrates basic parsing of date and time strings into Ruby DateTime objects using the Time and Date classes. This is a general Ruby example, not specific to the Plaid API. ```ruby # Not an exhaustive list of possible options a = Time.parse("2022-05-06T22:35:49Z").to_datetime b = Date.parse("2022-05-06T22:35:49Z").to_datetime ``` -------------------------------- ### Get Paginated Plaid Transactions (Sync) in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows the preferred method for retrieving transactions using the Plaid 'sync' endpoint. It demonstrates how to handle pagination by repeatedly calling the endpoint with the updated cursor until all transactions are retrieved. Requires an access_token. ```ruby request = Plaid::ItemPublicTokenExchangeRequest.new request.public_token = public_token response = client.item_public_token_exchange(request) access_token = response.access_token transactions_sync_request = Plaid::TransactionsSyncRequest.new transactions_sync_request.access_token = access_token transaction_response = client.transactions_sync(transactions_sync_request) transactions = transaction_response.added # the transactions in the response are paginated, so make multiple calls while # updating the cursor to retrieve all transactions while transaction_response.has_more transactions_sync_request = Plaid::TransactionsSyncRequest.new transactions_sync_request.access_token = access_token transactions_sync_request.cursor = transaction_response.next_cursor transaction_response = client.transactions_sync(transactions_sync_request) transactions += transaction_response.added end ``` -------------------------------- ### Get Paginated Plaid Transactions (Older Get) in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Illustrates an older method for retrieving transactions using the Plaid 'get' endpoint with date ranges and offset-based pagination. It shows how to loop and increment the offset to fetch all transactions. Requires an access_token. ```ruby request = Plaid::ItemPublicTokenExchangeRequest.new request.public_token = public_token response = client.item_public_token_exchange(request) access_token = response.access_token transactions_get_request = Plaid::TransactionsGetRequest.new transactions_get_request.access_token = access_token transactions_get_request.start_date = "2020-01-01" transactions_get_request.end_date = "2021-01-01" transaction_response = client.transactions_get(transactions_get_request) transactions = transaction_response.transactions # the transactions in the response are paginated, so make multiple calls while # increasing the offset to retrieve all transactions while transactions.length < transaction_response.total_transactions options_payload = {} options_payload[:offset] = transactions.length transactions_get_request = Plaid::TransactionsGetRequest.new transactions_get_request.access_token = access_token transactions_get_request.start_date = "2020-01-01" transactions_get_request.end_date = "2021-01-01" transactions_get_request.options = options_payload transaction_response = client.transactions_get(transactions_get_request) transactions += transaction_response.transactions end ``` -------------------------------- ### Get Plaid Auth Data in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows how to retrieve Plaid Auth data (account and routing numbers) for an Item. This requires an access_token for the specific Item. The example includes the preceding step of exchanging a public_token for an access_token. ```ruby request = Plaid::ItemPublicTokenExchangeRequest.new request.public_token = public_token response = client.item_public_token_exchange(request) access_token = response.access_token auth_get_request = Plaid::AuthGetRequest.new auth_get_request.access_token = access_token auth_response = client.auth_get(auth_get_request) auth = auth_response.auth ``` -------------------------------- ### Initialize Plaid Client (Ruby) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Configure and create an instance of the Plaid API client. This involves setting the environment (sandbox or production) and providing your Plaid API keys (client ID and secret). ```ruby require 'plaid' configuration = Plaid::Configuration.new configuration.server_index = Plaid::Configuration::Environment["sandbox"] configuration.api_key["PLAID-CLIENT-ID"] = "***" configuration.api_key["PLAID-SECRET"] = "***" api_client = Plaid::ApiClient.new( configuration ) client = Plaid::PlaidApi.new(api_client) ``` -------------------------------- ### Client Initialization - Pre-v14.0.0 - Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows the method for initializing the Plaid Ruby client library before version 14.0.0, directly passing environment, client_id, and secret to the Plaid::Client.new constructor. ```Ruby client = Plaid::Client.new(env: :sandbox, client_id: client_id, secret: secret) ``` -------------------------------- ### Client Initialization - v14.0.0+ - Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows the updated method for initializing the Plaid Ruby client library from version 14.0.0 onwards, using Plaid::Configuration, Plaid::ApiClient, and Plaid::PlaidApi. ```Ruby configuration = Plaid::Configuration.new configuration.server_index = Plaid::Configuration::Environment["sandbox"] configuration.api_key["PLAID-CLIENT-ID"] = ENV["PLAID_RUBY_CLIENT_ID"] configuration.api_key["PLAID-SECRET"] = ENV["PLAID_RUBY_SECRET"] configuration.api_key["Plaid-Version"] = "2020-09-14" api_client = Plaid::ApiClient.new( configuration ) client = Plaid::PlaidApi.new(api_client) ``` -------------------------------- ### Building Docker Image for Tests - Shell Source: https://github.com/plaid/plaid-ruby/blob/master/CONTRIBUTING.md Builds the Docker image required to run the client tests for the plaid-ruby library. Tags the image as 'plaid-ruby'. ```Shell docker build -t plaid-ruby . ``` -------------------------------- ### Endpoint Call - Pre-v14.0.0 - Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Demonstrates how endpoint methods were called before version 14.0.0, accessing methods via nested objects (e.g., client.auth.get) and passing parameters directly. ```Ruby response = client.auth.get(access_token) ``` -------------------------------- ### Create Plaid Link Token in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows how to generate a Plaid Link token using the Plaid Ruby client. This token is required to initialize Plaid Link on the client-side. It requires a client user ID and configuration options like client name, products, country codes, and language. ```ruby # Grab the client_user_id by searching for the current user in your database user = User.find_by!(email: '***') client_user_id = user.id # Create the link_token with all of your configurations link_token_create_request = Plaid::LinkTokenCreateRequest.new({ :user => { :client_user_id => client_user_id.to_s }, :client_name => 'My app', :products => %w[auth transactions], :country_codes => ['US'], :language => 'en' }) link_token_response = client.link_token_create( link_token_create_request ) # Pass the result to your client-side app to initialize Link # and retrieve a public_token link_token = link_token_response.link_token ``` -------------------------------- ### Running Dockerized Tests with Credentials - Shell Source: https://github.com/plaid/plaid-ruby/blob/master/CONTRIBUTING.md Runs the plaid-ruby client tests inside a Docker container. It removes the container after execution (--rm) and passes the Plaid client ID and secret as environment variables. ```Shell docker run --rm -e PLAID_RUBY_CLIENT_ID=$CLIENT_ID -e PLAID_RUBY_SECRET=$SECRET plaid-ruby ``` -------------------------------- ### Add Custom Faraday Middleware (Ruby) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Customize the Faraday connection builder to integrate middleware. This allows adding functionality like logging, caching, or custom request/response processing. ```ruby configuration = Plaid::Configuration.new api_client = Plaid::ApiClient.new(configuration) api_client.create_connection do |builder| builder.use Faraday::Response::Logger end ``` -------------------------------- ### Error Handling - Pre-v14.0.0 - Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Illustrates the error handling pattern used before version 14.0.0, catching Plaid::PlaidAPIError and checking the error_code property directly on the exception object. ```Ruby begin client.auth.get(auth_get_request) rescue Plaid::PlaidAPIError => e raise e if e.error_code != 'PRODUCT_NOT_READY' sleep 1 end ``` -------------------------------- ### Endpoint Call - v14.0.0+ - Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows the updated method for calling endpoint methods from version 14.0.0 onwards, which now take a request model object as a parameter and have method names ending with an underscore. Includes two ways to instantiate the request object. ```Ruby auth_get_request = Plaid::AuthGetRequest.new auth_get_request.access_token = access_token ``` ```Ruby auth_get_request = Plaid::AuthGetRequest.new({:access_token => access_token}) ``` ```Ruby response = client.auth_get(auth_get_request) ``` -------------------------------- ### Add Plaid Gem to Gemfile (Ruby) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Include the official Plaid Ruby gem in your project's Gemfile. This is the standard way to manage dependencies using Bundler. ```ruby gem 'plaid' ``` -------------------------------- ### Error Handling - v14.0.0+ - Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Shows the updated error handling pattern from version 14.0.0 onwards, catching Plaid::ApiError and parsing the JSON response body from the exception object to access the error_code. ```Ruby begin client.auth_get(auth_get_request) rescue Plaid::ApiError => e json_response = JSON.parse(e.response_body) if json_response["error_code"] != "PRODUCT_NOT_READY" end ``` -------------------------------- ### Exchange Plaid Public Token for Access Token in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Illustrates the process of exchanging a Plaid Link public_token, obtained from the client-side Link flow, for a persistent access_token. The access_token is necessary for subsequent API calls to retrieve financial data. ```ruby request = Plaid::ItemPublicTokenExchangeRequest.new request.public_token = public_token response = client.item_public_token_exchange(request) access_token = response.access_token ``` -------------------------------- ### Use Date Objects for API Requests (Ruby) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Illustrates how to represent date values using Ruby's `Date` class for API request parameters. The Plaid Ruby client expects `Date` or `DateTime` objects with timezone information where applicable. ```ruby require 'date' # Not an exhaustive list of possible options a = Date.new(2022, 5, 5) b = Date.new(2022, 5, 5).to_date c = Date.parse('2022-05-05') d = Date.parse('2022-05-05').to_date e = Date.today ``` -------------------------------- ### Delete Plaid Item in Ruby Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Demonstrates how to remove a Plaid Item using its access_token. This process typically follows obtaining an access_token by exchanging a public_token. Deleting an Item revokes access to the associated financial account data. ```ruby request = Plaid::ItemPublicTokenExchangeRequest.new request.public_token = public_token response = client.item_public_token_exchange(request) access_token = response.access_token # Provide the access_token for the Item you want to remove item_remove_request = Plaid::ItemRemoveRequest.new item_remove_request.access_token = access_token client.item_remove(item_remove_request) ``` -------------------------------- ### Configure Faraday Timeout (Ruby) Source: https://github.com/plaid/plaid-ruby/blob/master/README.md Modify the default request timeout for the HTTP connection. This is useful for operations that might take longer than the default, such as large data retrievals. ```ruby configuration = Plaid::Configuration.new api_client = Plaid::ApiClient.new( configuration ) api_client.connection.options[:timeout] = 60*20 # 20 minutes ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.