Skip to main content

Ruby SDK

Official Ruby client for the Huntrecht Platform API v1.

Installation​

gem install huntrecht-sdk

Or in your Gemfile:

gem 'huntrecht-sdk'

Quick Start​

require 'huntrecht'

client = Huntrecht::Client.new(
client_id: 'hnt_your_client_id',
client_secret: 'your_secret'
)

# Authenticate (automatic on first request)
tokens = client.auth.token
puts "Authenticated (expires in #{tokens['expires_in']}s)"

# List orders
orders = client.orders.list(status: 'pending')
orders['data'].each do |order|
puts "Order #{order['id']}: #{order['commodity']} - #{order['quantity']}"
end

# Get credit score
score = client.credit.score('customer@example.com')
puts "Credit score: #{score['data']['credit_score']} (#{score['data']['risk_level']})"

Authentication​

# Using environment variables
client = Huntrecht::Client.new

# Using explicit credentials
client = Huntrecht::Client.new(
client_id: 'hnt_abc',
client_secret: 'secret'
)

# With custom base URL
client = Huntrecht::Client.new(
base_url: 'https://api.huntrecht.com',
client_id: 'hnt_abc',
client_secret: 'secret'
)

Resource Modules​

Orders​

orders = client.orders.list(page: 1, per_page: 20, status: 'pending')
order = client.orders.get('ord_abc123')
order = client.orders.create(
commodity: 'Gold',
quantity: 100,
delivery_terms: 'FOB',
destination: 'New York'
)

Payments​

payments = client.payments.list(status: 'completed')
payment = client.payments.get('pay_abc123')
payment = client.payments.create(
subscription_id: 123,
amount: 2500.00,
currency: 'USD'
)

Subscriptions​

subs = client.subscriptions.list(status: 'active')
sub = client.subscriptions.get('sub_abc123')

Credit​

score = client.credit.score('customer@example.com')
assessment = client.credit.assess(
customer_email: 'customer@example.com',
include_recommendations: true
)

KYC​

kycs = client.kyc.list(status: 'pending')
result = client.kyc.submit(
company_name: 'Acme Corp',
company_type: 'LLC'
)

Quotes​

quotes = client.quotes.list
quote = client.quotes.create(
commodity: 'Copper',
quantity: 500,
unit: 'kg'
)

Storefront​

collections = client.storefront.collections(include_products: true)
products = client.storefront.products(b2b_only: true)
results = client.storefront.search('copper wire')

Price Drops (Public)​

drops = client.price_drops.list(limit: 10)
featured = client.price_drops.featured

Error Handling​

begin
orders = client.orders.list
rescue Huntrecht::AuthenticationError => e
puts "Auth failed: #{e.message}"
rescue Huntrecht::RateLimitError => e
puts "Rate limited. Retry after #{e.retry_after}s"
rescue Huntrecht::APIError => e
puts "API error: #{e.message} (status=#{e.status_code})"
end

Environment Variables​

VariableDescription
HUNTRECHT_BASE_URLAPI base URL (default: https://api.huntrecht.com)
HUNTRECHT_CLIENT_IDOAuth2 client ID
HUNTRECHT_CLIENT_SECRETOAuth2 client secret