Trade Balance API - Ruby Gem
Trade Balance provides monthly US international trade data - exports, imports, and the resulting goods-and-services trade balance (deficit or surplus) on a Balance of Payments basis.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_tradebalance'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_tradebalance
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_tradebalance'
# Initialize the client
client = APIVerve::Tradebalance::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ date: "2023-06" })
# Print the response
puts response
Error Handling
begin
response = client.execute({ date: "2023-06" })
puts response["data"]
rescue APIVerve::Tradebalance::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Tradebalance::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Tradebalance::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"yearMonth": "2024-01",
"year": 2024,
"month": 1,
"customsDuties": 8234567890,
"updatedAt": "2024-02-01T00:00:00.000Z"
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/tradebalance?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.