Ruby - Dwolla Developer Portal
Getting Started
Installation
To begin using this SDK, you will first need to download it to your machine. We use RubyGems to distribute this package. Add this line to your application’s Gemfile:
gem 'dwolla_v2', '~> 3.1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dwolla_v2
Initialization
Before any API requests can be made, you must first determine which environment you will be using, as well as fetch the application key and secret. To fetch your application key and secret, please visit one of the following links:
- Production: https://dashboard.dwolla.com/applications
- Sandbox: https://dashboard-sandbox.dwolla.com/applications
Finally, you can create an instance of Client with key and secret replaced with the application key and secret that you fetched from one of the aforementioned links, respectively.
# config/initializers/dwolla.rb
$dwolla = DwollaV2::Client.new(
key: ENV["DWOLLA_APP_KEY"],
secret: ENV["DWOLLA_APP_SECRET"],
environment: :sandbox # defaults to :production
)
Configure Faraday (Optional)
Dwolla for Ruby uses Faraday to make HTTP requests. You can configure your own Faraday middleware and adapter when configuring your client. Remember to always include an adapter last, even if you want to use the default adapter.
# config/initializers/dwolla.rb
$dwolla = DwollaV2::Client.new(
key: ENV["DWOLLA_APP_KEY"],
secret: ENV["DWOLLA_APP_SECRET"
) do |config|
config.faraday do |faraday|
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
end
Making Requests
Once you’ve created a Client, currently, you can make low-level HTTP requests.
Low-level Requests
To make low-level HTTP requests, you can use the get(), post(), and delete() methods.
GET
# GET api.dwolla.com/resource?foo=bar
$dwolla.get "resource", foo: "bar"
POST
# POST api.dwolla.com/resource {"foo":"bar"}
$dwolla.post "resource", foo: "bar"
# POST api.dwolla.com/resource multipart/form-data foo=...
$dwolla.post "resource", foo: Faraday::UploadIO.new("/path/to/bar.png", "image/png")
DELETE
# DELETE api.dwolla.com/resource
$dwolla.delete "resource"
Setting Headers
To set additional headers on a request, you can pass a Hash of headers as the 3rd argument. For example:
$dwolla.post "customers", { firstName: "John", lastName: "Doe", email: "jd@doe.com" },
{ 'Idempotency-Key': 'a52fcf63-0730-41c3-96e8-7147b5d1fb01' }
Responses
The following snippets demonstrate successful and errored responses from the Dwolla API. An errored response is returned when Dwolla’s servers respond with a status code that is greater than or equal to 400, whereas a successful response is when Dwolla’s servers respond with a 200-level status code.
Success
Successful requests return a DwollaV2::Response.
res = $dwolla.get "/"
# => #<DwollaV2::Response response_status=200 response_headers={...}>
res.response_status
# => 200
res.response_headers
# => {...}
res._links.events.href
# => "https://api-sandbox.dwolla.com/events"
Error
If the server returns an error, a DwollaV2::Error (or one of its subclasses) will be raised. DwollaV2::Errors are similar to DwollaV2::Responses.
begin
$dwolla.get "/not-found"
rescue DwollaV2::NotFoundError => e
# => #<DwollaV2::NotFoundError ...>
end
DwollaV2::Error subclasses:
DwollaV2::AccessDeniedErrorDwollaV2::InvalidCredentialsErrorDwollaV2::NotFoundErrorDwollaV2::BadRequestErrorDwollaV2::InvalidGrantErrorDwollaV2::RequestTimeoutErrorDwollaV2::ExpiredAccessTokenErrorDwollaV2::InvalidRequestErrorDwollaV2::ServerErrorDwollaV2::ForbiddenErrorDwollaV2::InvalidResourceStateErrorDwollaV2::TemporarilyUnavailableErrorDwollaV2::InvalidAccessTokenErrorDwollaV2::InvalidScopeErrorDwollaV2::UnauthorizedClientErrorDwollaV2::InvalidAccountStatusErrorDwollaV2::InvalidScopesErrorDwollaV2::UnsupportedGrantTypeErrorDwollaV2::InvalidApplicationStatusErrorDwollaV2::InvalidVersionErrorDwollaV2::UnsupportedResponseTypeErrorDwollaV2::InvalidClientErrorDwollaV2::MethodNotAllowedErrorDwollaV2::ValidationErrorDwollaV2::TooManyRequestsErrorDwollaV2::ConflictError
Community
If you have any feedback, please reach out to us on our forums or by creating a GitHub issue.
If you would like to contribute to this library, bug reports and pull requests are always appreciated!
After checking out the repo, run
bin/setupto install dependencies. Then, runrake specto run the tests. You can also runbin/consolefor an interactive prompt that will allow you to experiment.- To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number inversion.rb, and then runbundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the.gemfile to rubygems.org.
- To install this gem onto your local machine, run
Docker
If you prefer to use Docker to run dwolla-v2-python locally, a Dockerfile is included at the root directory. Follow these instructions from Docker’s website to create a Docker image from the Dockerfile, and run it.