<commit_before># plaid-ruby [![Circle CI](https://circleci.com/gh/plaid/plaid-ruby.svg?style=svg&circle-token=<PASSWORD>)](https://circleci.com/gh/plaid/plaid-ruby) [![Gem Version](https://badge.fury.io/rb/plaid.svg)](http://badge.fury.io/rb/plaid)

The official Ruby bindings for the [Plaid API](https://plaid.com/docs).

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'plaid'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install plaid

The gem supports Ruby 2.2+ only.

### Versioning

Each major version of `plaid-ruby` targets a specific version of the Plaid API:

| API version | plaid-ruby release |
| ----------- | ------------------ |
| [`2019-05-29`][api-version-2019-05-29] (**latest**) | `9.x.x`, `8.x.x`, `7.x.x` |
| [`2018-05-22`][api-version-2018-05-22] | `6.x.x` |
| `2017-03-08` | `5.x.x` |

For information about what has changed between versions and how to update your integration, head to the [version changelog][version-changelog].


## Usage

This gem wraps the Plaid API, which is fully described in the [documentation](https://plaid.com/docs/api).

The RubyDoc for the gem is available [here](http://plaid.github.io/plaid-ruby/).

### Creating a Plaid client

Create an instance of the client using the `client_id` and `secret` from your Plaid dashboard along with your environment of choice:

```ruby
require 'plaid'

client = Plaid::Client.new(env: :sandbox,
                           client_id: '***',
                           secret: '***')
```

The `env` field is the environment which the client will be running in. Your choices for the `env` field include:

- `:sandbox` allows you to do your initial integrations tests against preloaded data without being billed or making expensive API calls. More information about using the API sandbox can be found on the [API Sandbox documentation](https://plaid.com/docs/api#sandbox).
- `:development` allows you to test against both real and test accounts without being billed. More information about Plaid test accounts can be found in our [API documentation](https://plaid.com/docs/api/#sandbox).
- `:production` is the production environment where you can launch your production ready application and be charged for your Plaid usage.

### Tuning Faraday

The gem uses Faraday to wrap HTTPS connections, which allows you to tune certain params:

```ruby
client = Plaid::Client.new(env: :sandbox, client_id: '***', secret: '***') do |builder|
  Plaid::Client.build_default_connection(builder)

  # Increase network timeout
  builder.options[:timeout] = 60*20    # 20 minutes
end
```

## Examples

### Exchanging a Link public_token for a Plaid access_token

If you have a [Link](https://github.com/plaid/link) `public token`, use this function to get an `access_token`: `client.item.public_token.exchange(public_token)`

An example of the function's usage if you have a `public_token` in hand:

```ruby
response = client.item.public_token.exchange(public_token)
access_token = response.access_token
```

### Deleting an item

```ruby
require 'plaid'

client = Plaid::Client.new(env: :sandbox,
                           client_id: '***',<commit_msg>Update Readme with link token creation example (#299)<commit_after># plaid-ruby [![Circle CI](https://circleci.com/gh/plaid/plaid-ruby.svg?style=svg&circle-token=30<PASSWORD>2ac2021da5b5b5a701d45fe2888af124a5)](https://circleci.com/gh/plaid/plaid-ruby) [![Gem Version](https://badge.fury.io/rb/plaid.svg)](http://badge.fury.io/rb/plaid)

The official Ruby bindings for the [Plaid API](https://plaid.com/docs).

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'plaid'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install plaid

The gem supports Ruby 2.2+ only.

### Versioning

Each major version of `plaid-ruby` targets a specific version of the Plaid API:

| API version | plaid-ruby release |
| ----------- | ------------------ |
| [`2019-05-29`][api-version-2019-05-29] (**latest**) | `9.x.x`, `8.x.x`, `7.x.x` |
| [`2018-05-22`][api-version-2018-05-22] | `6.x.x` |
| `2017-03-08` | `5.x.x` |

For information about what has changed between versions and how to update your integration, head to the [version changelog][version-changelog].


## Usage

This gem wraps the Plaid API, which is fully described in the [documentation](https://plaid.com/docs/api).

The RubyDoc for the gem is available [here](http://plaid.github.io/plaid-ruby/).

### Creating a Plaid client

Create an instance of the client using the `client_id` and `secret` from your Plaid dashboard along with your environment of choice:

```ruby
require 'plaid'

client = Plaid::Client.new(env: :sandbox,
                           client_id: '***',
                           secret: '***')
```

The `env` field is the environment which the client will be running in. Your choices for the `env` field include:

- `:sandbox` allows you to do your initial integrations tests against preloaded data without being billed or making expensive API calls. More information about using the API sandbox can be found on the [API Sandbox documentation](https://plaid.com/docs/api#sandbox).
- `:development` allows you to test against both real and test accounts without being billed. More information about Plaid test accounts can be found in our [API documentation](https://plaid.com/docs/api/#sandbox).
- `:production` is the production environment where you can launch your production ready application and be charged for your Plaid usage.

### Tuning Faraday

The gem uses Faraday to wrap HTTPS connections, which allows you to tune certain params:

```ruby
client = Plaid::Client.new(env: :sandbox, client_id: '***', secret: '***') do |builder|
  Plaid::Client.build_default_connection(builder)

  # Increase network timeout
  builder.options[:timeout] = 60*20    # 20 minutes
end
```

## Examples

### Create a new link_token

```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_response = client.link_token.create(
  user: { client_user_id: client_user_id.to_s },
  client_name: 'My app',
  products: %w[auth transactions],
  country_codes: ['US'],
  language: 'en'
)

# Pass the result to your client-side app to initialize Link
#  and retrieve a public_token
link_token = link_token_response.link_token
```

### Exchanging a Link public_token for a Plaid access_token

If you have a [Link](https://github.com/plaid/link) `public token`, use this function to get an `access_token`: `client.item.public_token.exchange(public_token)`

An example of the function's usage if you have a `public_token` in hand:

```ruby
response = client.item.public_token.exchange(public_token)
access_token = response.access_token
```


### Deleting an item

```ruby
require 'plaid'

client = Plaid::Client.new(env: :sandbox,
                           client_id: '***',
{'fraction_non_alphanumeric': 0.13239276043893403, 'fraction_numerical': 0.01881145788798632, 'mean_word_length': 3.9527170077628795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1476610', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2125, 'n_words': 731}