The official Ruby gem for the Patch API
For detailed documentation and examples, see the Patch API docs.
Add the gem to your Gemfile:
gem 'patch_ruby'
Then run:
bundle
Or install it directly with
gem install patch_ruby
- Ruby 1.9+
After installing the gem, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:
require 'patch_ruby'
Patch.configure do |config|
# Configure the Patch gem with your API key here
config.access_token = ENV['PATCH_RUBY_API_KEY']
end
Once configured, you can test it out:
begin
orders_response = Patch::Order.retrieve_orders
orders_response.data.each do |order|
puts "Order ID: #{order.id}, Order State: #{order.state}"
end
# Rescue from any Patch API errors
rescue Patch::ApiError => e
puts "Failed to retrieve Orders with status code #{e.code}: #{e.message}"
end