Add this line to your application's Gemfile:
gem "nango-ruby"
And then execute:
$ bundle install
Or install with:
$ gem install nango-ruby
and require with:
require "nango"
For a quick test you can pass your token directly to a new client:
client = Nango::Client.new(
access_token: "access_token_goes_here",
log_errors: true # Highly recommended in development, so you can see what errors Nango is returning. Not recommended in production because it could leak private data to your logs.
)
For a more robust setup, you can configure the gem with your API keys, for example in an nango.rb
initializer file. Never hardcode secrets into your codebase - instead use something like dotenv to pass the keys safely into your environments.
Nango.configure do |config|
config.access_token = ENV.fetch("NANGO_ACCESS_TOKEN")
config.log_errors = true # Highly recommended in development, so you can see what errors Nango is returning. Not recommended in production because it could leak private data to your logs.
end
Then you can create a client like this:
client = Nango::Client.new
You can still override the config defaults when making new clients; any options not included will fall back to any global config set with Nango.configure. e.g. in this example the organization_id, request_timeout, etc. will fallback to any set globally using Nango.configure, with only the access_token overridden:
client = Nango::Client.new(access_token: "access_token_goes_here")
You can dynamically pass headers per client object, which will be merged with any headers set globally with OpenAI.configure:
client = Nango::Client.new(access_token: "access_token_goes_here")
client.add_headers("X-Proxy-TTL" => "43200")
By default, nango-ruby
does not log any Faraday::Error
s encountered while executing a network request to avoid leaking data (e.g. 400s, 500s, SSL errors and more - see here for a complete list of subclasses of Faraday::Error
and what can cause them).
If you would like to enable this functionality, you can set log_errors
to true
when configuring the client:
client = Nango::Client.new(log_errors: true)
You can pass Faraday middleware to the client in a block, eg. to enable verbose logging with Ruby's Logger:
client = Nango::Client.new do |f|
f.response :logger, Logger.new($stdout), bodies: true
end