Overview
The Devdraft Ruby SDK provides a complete client library for integrating payment processing, customer management, and webhook functionality into your Ruby applications.
Ruby Idioms Follows Ruby conventions with blocks, symbols, and elegant syntax
Gem Package Easy installation via RubyGems package manager
Comprehensive Access to all Devdraft API endpoints and features
Rails Compatible Works seamlessly with Ruby on Rails applications
Installation
Using Bundler
Add to your Gemfile:
gem 'devdraft' , '~> 1.0.0'
Then run:
Using RubyGems
Install from Source
gem build devdraft.gemspec
gem install ./devdraft-1.0.0.gem
Requirements
Quick Start
require 'devdraft'
# Configure API credentials
Devdraft . configure do | config |
config. api_key [ 'x-client-key' ] = ENV [ 'DEVDRAFT_CLIENT_KEY' ]
config. api_key [ 'x-client-secret' ] = ENV [ 'DEVDRAFT_CLIENT_SECRET' ]
config. server_index = nil
config. base_url = 'https://api.devdraft.ai'
end
# Create API instances
transfers_api = Devdraft :: TransfersApi . new
webhooks_api = Devdraft :: WebhooksApi . new
begin
# Create a transfer
transfer_dto = Devdraft :: CreateDirectWalletTransferDto . new (
wallet_id: 'your-wallet-id' ,
network: 'solana' ,
stable_coin_currency: 'usdc' ,
amount: 100.00
)
transfer = transfers_api. transfer_controller_create_direct_wallet_transfer (transfer_dto)
puts "Transfer created: #{ transfer. id } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e. message } "
end
API Classes
The SDK is organized into API classes under the Devdraft module:
API Class Description APIHealthApi Service health checks and status monitoring AppBalancesApi Query application balances across stablecoins CustomersApi Customer management and KYC operations ExchangeRatesApi Real-time currency exchange rates InvoicesApi Invoice creation and management LiquidationAddressesApi Cryptocurrency liquidation addresses PaymentIntentsApi Payment intent creation for bank and stablecoin PaymentLinksApi Generate and manage payment links ProductsApi Product catalog management TaxesApi Tax configuration and management TestPaymentsApi Test payment processing in sandbox TransfersApi Initiate and manage fund transfers WalletsApi Wallet management and balances WebhooksApi Webhook configuration and management
API Health
Monitor service health and availability.
Methods
health_controller_check_v0()
Authenticated health check endpoint requiring API credentials.
require 'devdraft'
Devdraft . configure do | config |
config. api_key [ 'x-client-key' ] = ENV [ 'DEVDRAFT_CLIENT_KEY' ]
config. api_key [ 'x-client-secret' ] = ENV [ 'DEVDRAFT_CLIENT_SECRET' ]
end
api_instance = Devdraft :: APIHealthApi . new
begin
api_instance. health_controller_check_v0
puts 'Service is healthy and authenticated'
rescue Devdraft :: ApiError => e
puts "Health check failed: #{ e } "
end
Returns: nil
health_controller_public_health_check_v0()
Public health check endpoint (no authentication required).
status = api_instance. health_controller_public_health_check_v0
puts "Service status: #{ status. status } "
Returns: PublicHealthResponseDto
App Balances
Query your application’s stablecoin balances.
Methods
balance_controller_get_all_balances()
Get all stablecoin balances for your application.
require 'devdraft'
api_instance = Devdraft :: AppBalancesApi . new
begin
balances = api_instance. balance_controller_get_all_balances
puts "USDC Balance: #{ balances. usdc } "
puts "EURC Balance: #{ balances. eurc } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Returns: AllBalancesResponse
balance_controller_get_usdc_balance()
Get USDC balance only.
usdc_balance = api_instance. balance_controller_get_usdc_balance
puts "USDC: #{ usdc_balance. amount } "
Returns: AggregatedBalanceResponse
balance_controller_get_eurc_balance()
Get EURC balance only.
eurc_balance = api_instance. balance_controller_get_eurc_balance
puts "EURC: #{ eurc_balance. amount } "
Returns: AggregatedBalanceResponse
Customers
Manage customer records and KYC information.
Methods
customer_controller_create(create_customer_dto)
Create a new customer.
require 'devdraft'
api_instance = Devdraft :: CustomersApi . new
begin
customer_dto = Devdraft :: CreateCustomerDto . new (
first_name: 'John' ,
last_name: 'Doe' ,
email: 'john.doe@example.com' ,
type: 'INDIVIDUAL' ,
country: 'US'
)
customer = api_instance. customer_controller_create (customer_dto)
puts "Customer created: #{ customer. id } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_customer_dto: CreateCustomerDto - Customer details
Returns: Customer
customer_controller_find_all(opts = {})
Get all customers with optional filters.
opts = {
page: 1 ,
limit: 20 ,
status: 'ACTIVE'
}
customers = api_instance. customer_controller_find_all (opts)
customers. each do | customer |
puts " #{ customer. first_name } #{ customer. last_name } - #{ customer. email } "
end
Parameters:
opts: Hash - Optional parameters
page: Integer - Page number (default: 1)
limit: Integer - Items per page (default: 20)
status: String - Filter by status
Returns: Array<Customer>
customer_controller_find_one(id)
Get a customer by ID.
customer = api_instance. customer_controller_find_one ( 'customer-id-here' )
puts "Customer: #{ customer. first_name } #{ customer. last_name } "
Parameters:
Returns: Customer
customer_controller_update(id, update_customer_dto)
Update a customer’s information.
update_dto = Devdraft :: UpdateCustomerDto . new (
phone: '+1234567890' ,
address: '123 Main St'
)
updated = api_instance. customer_controller_update ( 'customer-id-here' , update_dto)
puts "Customer updated: #{ updated. id } "
Parameters:
id: String - Customer ID
update_customer_dto: UpdateCustomerDto - Fields to update
Returns: Customer
Exchange Rates
Get real-time currency exchange rates.
Methods
exchange_rate_controller_get_exchange_rate(opts = {})
Get exchange rate between any two supported currencies.
require 'devdraft'
api_instance = Devdraft :: ExchangeRatesApi . new
begin
opts = {
from: 'USD' ,
to: 'EUR'
}
rate = api_instance. exchange_rate_controller_get_exchange_rate (opts)
puts "1 USD = #{ rate. rate } EUR"
puts "Rate expires at: #{ rate. expires_at } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
opts: Hash - Optional parameters
from: String - Source currency code
to: String - Target currency code
Returns: ExchangeRateResponseDto
exchange_rate_controller_get_usdto_eur_rate()
Get USD to EUR exchange rate.
usd_to_eur = api_instance. exchange_rate_controller_get_usdto_eur_rate
puts "USD to EUR: #{ usd_to_eur. rate } "
Returns: ExchangeRateResponseDto
exchange_rate_controller_get_eurto_usd_rate()
Get EUR to USD exchange rate.
eur_to_usd = api_instance. exchange_rate_controller_get_eurto_usd_rate
puts "EUR to USD: #{ eur_to_usd. rate } "
Returns: ExchangeRateResponseDto
Invoices
Create and manage invoices for your customers.
Methods
invoice_controller_create(create_invoice_dto)
Create a new invoice.
require 'devdraft'
api_instance = Devdraft :: InvoicesApi . new
begin
invoice_dto = Devdraft :: CreateInvoiceDto . new (
customer_id: 'customer-id' ,
items: [
{
description: 'Premium Subscription' ,
quantity: 1 ,
price: 99.99 ,
currency: 'USD'
}
],
due_date: '2024-12-31'
)
invoice = api_instance. invoice_controller_create (invoice_dto)
puts "Invoice created: #{ invoice. id } "
puts "Total: #{ invoice. total } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_invoice_dto: CreateInvoiceDto - Invoice details
Returns: Invoice
invoice_controller_find_all(opts = {})
Get all invoices.
opts = {
page: 1 ,
limit: 50 ,
status: 'UNPAID'
}
invoices = api_instance. invoice_controller_find_all (opts)
invoices. each do | invoice |
puts "Invoice #{ invoice. id } : #{ invoice. total } "
end
Parameters:
opts: Hash - Optional parameters
page: Integer - Page number
limit: Integer - Items per page
status: String - Filter by status
Returns: Array<Invoice>
invoice_controller_find_one(id)
Get an invoice by ID.
invoice = api_instance. invoice_controller_find_one ( 'invoice-id' )
puts "Invoice total: #{ invoice. total } "
Parameters:
Returns: Invoice
invoice_controller_update(id, update_invoice_dto)
Update an invoice.
update_dto = {
status: 'PAID' ,
paid_at: Time . now . iso8601
}
updated = api_instance. invoice_controller_update ( 'invoice-id' , update_dto)
puts "Invoice updated: #{ updated. id } "
Parameters:
id: String - Invoice ID
update_invoice_dto: Hash - Fields to update
Returns: Invoice
Liquidation Addresses
Manage cryptocurrency liquidation addresses for customers.
Methods
liquidation_address_controller_create_liquidation_address(customer_id, create_liquidation_address_dto)
Create a new liquidation address for a customer.
require 'devdraft'
api_instance = Devdraft :: LiquidationAddressesApi . new
begin
address_dto = Devdraft :: CreateLiquidationAddressDto . new (
network: 'solana' ,
currency: 'usdc'
)
address = api_instance. liquidation_address_controller_create_liquidation_address (
'customer-id' ,
address_dto
)
puts "Liquidation address: #{ address. address } "
puts "Network: #{ address. network } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
customer_id: String - Customer ID
create_liquidation_address_dto: CreateLiquidationAddressDto - Address details
Returns: LiquidationAddressResponseDto
liquidation_address_controller_get_liquidation_addresses(customer_id)
Get all liquidation addresses for a customer.
addresses = api_instance. liquidation_address_controller_get_liquidation_addresses ( 'customer-id' )
addresses. each do | addr |
puts " #{ addr. network } : #{ addr. address } "
end
Parameters:
customer_id: String - Customer ID
Returns: Array<LiquidationAddressResponseDto>
liquidation_address_controller_get_liquidation_address(customer_id, liquidation_address_id)
Get a specific liquidation address.
address = api_instance. liquidation_address_controller_get_liquidation_address (
'customer-id' ,
'address-id'
)
puts "Address: #{ address. address } "
Parameters:
customer_id: String - Customer ID
liquidation_address_id: String - Address ID
Returns: LiquidationAddressResponseDto
Payment Intents
Create payment intents for bank and stablecoin payments.
Methods
payment_intent_controller_create_bank_payment_intent(create_bank_payment_intent_dto)
Create a bank payment intent.
require 'devdraft'
api_instance = Devdraft :: PaymentIntentsApi . new
begin
intent_dto = Devdraft :: CreateBankPaymentIntentDto . new (
customer_id: 'customer-id' ,
amount: 1000.00 ,
currency: 'USD' ,
payment_rail: 'wire'
)
intent = api_instance. payment_intent_controller_create_bank_payment_intent (intent_dto)
puts "Payment intent: #{ intent. id } "
puts "Status: #{ intent. status } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_bank_payment_intent_dto: CreateBankPaymentIntentDto - Intent details
Returns: PaymentIntent
payment_intent_controller_create_stable_payment_intent(create_stable_payment_intent_dto)
Create a stablecoin payment intent.
stable_intent_dto = Devdraft :: CreateStablePaymentIntentDto . new (
customer_id: 'customer-id' ,
amount: 500.00 ,
currency: 'usdc' ,
network: 'solana'
)
stable_intent = api_instance. payment_intent_controller_create_stable_payment_intent (stable_intent_dto)
puts "Stable intent: #{ stable_intent. id } "
Parameters:
create_stable_payment_intent_dto: CreateStablePaymentIntentDto - Intent details
Returns: PaymentIntent
Payment Links
Generate and manage payment links for easy customer payments.
Methods
payment_links_controller_create(create_payment_link_dto)
Create a new payment link.
require 'devdraft'
api_instance = Devdraft :: PaymentLinksApi . new
begin
link_dto = Devdraft :: CreatePaymentLinkDto . new (
name: 'Product Purchase' ,
amount: 99.99 ,
currency: 'USD' ,
products: [
{
name: 'Premium Plan' ,
quantity: 1 ,
price: 99.99
}
]
)
link = api_instance. payment_links_controller_create (link_dto)
puts "Payment link: #{ link. url } "
puts "Share this link with customers: #{ link. short_url } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_payment_link_dto: CreatePaymentLinkDto - Link details
Returns: PaymentLink
payment_links_controller_find_all(opts = {})
Get all payment links.
opts = {
page: 1 ,
limit: 20 ,
active: true
}
links = api_instance. payment_links_controller_find_all (opts)
links. each do | link |
puts " #{ link. name } : #{ link. url } "
end
Parameters:
opts: Hash - Optional parameters
page: Integer - Page number
limit: Integer - Items per page
active: Boolean - Filter by active status
Returns: Array<PaymentLink>
payment_links_controller_find_one(id)
Get a payment link by ID.
link = api_instance. payment_links_controller_find_one ( 'link-id' )
puts "Link: #{ link. url } "
Parameters:
id: String - Payment link ID
Returns: PaymentLink
payment_links_controller_update(id, update_payment_link_dto)
Update a payment link.
update_dto = {
active: false ,
expires_at: '2024-12-31T23:59:59Z'
}
updated = api_instance. payment_links_controller_update ( 'link-id' , update_dto)
puts "Link updated: #{ updated. id } "
Parameters:
id: String - Payment link ID
update_payment_link_dto: Hash - Fields to update
Returns: PaymentLink
Products
Manage your product catalog.
Methods
product_controller_create(create_product_dto)
Create a new product.
require 'devdraft'
api_instance = Devdraft :: ProductsApi . new
begin
product_dto = {
name: 'Premium Subscription' ,
description: 'Access to all premium features' ,
price: 99.99 ,
currency: 'USD' ,
category: 'subscriptions'
}
product = api_instance. product_controller_create (product_dto)
puts "Product created: #{ product. id } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_product_dto: Hash - Product details
Returns: Product
product_controller_find_all(opts = {})
Get all products.
opts = {
category: 'subscriptions' ,
active: true
}
products = api_instance. product_controller_find_all (opts)
products. each do | product |
puts " #{ product. name } : $ #{ product. price } "
end
Parameters:
opts: Hash - Optional parameters
category: String - Filter by category
active: Boolean - Filter by active status
Returns: Array<Product>
product_controller_find_one(id)
Get a product by ID.
product = api_instance. product_controller_find_one ( 'product-id' )
puts "Product: #{ product. name } "
Parameters:
Returns: Product
product_controller_update(id, update_product_dto)
Update a product.
update_dto = {
price: 89.99 ,
description: 'Updated description'
}
updated = api_instance. product_controller_update ( 'product-id' , update_dto)
puts "Product updated: #{ updated. id } "
Parameters:
id: String - Product ID
update_product_dto: Hash - Fields to update
Returns: Product
product_controller_remove(id)
Delete a product.
api_instance. product_controller_remove ( 'product-id' )
puts 'Product deleted'
Parameters:
Returns: nil
product_controller_upload_image(id, images)
Upload images for a product.
images = [
File . open ( '/path/to/image1.jpg' ),
File . open ( '/path/to/image2.jpg' )
]
product = api_instance. product_controller_upload_image ( 'product-id' , images)
puts "Images uploaded for product: #{ product. id } "
Parameters:
id: String - Product ID
images: Array<File> - Image files
Returns: Product
Taxes
Configure and manage tax settings.
Methods
tax_controller_create(create_tax_dto)
Create a new tax configuration.
require 'devdraft'
api_instance = Devdraft :: TaxesApi . new
begin
tax_dto = Devdraft :: CreateTaxDto . new (
name: 'Sales Tax' ,
percentage: 8.5 ,
country: 'US' ,
state: 'CA'
)
tax = api_instance. tax_controller_create (tax_dto)
puts "Tax created: #{ tax. id } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_tax_dto: CreateTaxDto - Tax details
Returns: Tax
tax_controller_find_all(opts = {})
Get all tax configurations.
opts = { country: 'US' }
taxes = api_instance. tax_controller_find_all (opts)
taxes. each do | tax |
puts " #{ tax. name } : #{ tax. percentage } %"
end
Parameters:
opts: Hash - Optional parameters
country: String - Filter by country
Returns: Array<Tax>
tax_controller_find_one(id)
Get a tax configuration by ID.
tax = api_instance. tax_controller_find_one ( 'tax-id' )
puts "Tax: #{ tax. name } "
Parameters:
Returns: Tax
tax_controller_update(id, update_tax_dto)
Update a tax configuration.
update_dto = Devdraft :: UpdateTaxDto . new ( percentage: 9.0 )
updated = api_instance. tax_controller_update ( 'tax-id' , update_dto)
puts "Tax updated: #{ updated. id } "
Parameters:
id: String - Tax ID
update_tax_dto: UpdateTaxDto - Fields to update
Returns: Tax
tax_controller_remove(id)
Delete a tax configuration.
api_instance. tax_controller_remove ( 'tax-id' )
puts 'Tax deleted'
Parameters:
Returns: nil
Test Payments
Process test payments in sandbox environment.
Methods
test_payment_controller_create_payment_v0(payment_request_dto)
Create a test payment.
require 'devdraft'
api_instance = Devdraft :: TestPaymentsApi . new
begin
payment_dto = Devdraft :: PaymentRequestDto . new (
amount: 100.00 ,
currency: 'USD' ,
customer_id: 'test-customer-id' ,
idempotency_key: 'unique-key-123'
)
payment = api_instance. test_payment_controller_create_payment_v0 (payment_dto)
puts "Test payment: #{ payment. id } "
puts "Status: #{ payment. status } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
payment_request_dto: PaymentRequestDto - Payment details
Returns: PaymentResponseDto
test_payment_controller_get_payment_v0(id)
Get test payment details by ID.
payment = api_instance. test_payment_controller_get_payment_v0 ( 'payment-id' )
puts "Payment status: #{ payment. status } "
Parameters:
Returns: PaymentResponseDto
test_payment_controller_refund_payment_v0(id, opts = {})
Refund a test payment.
opts = { refund_amount: 50.00 }
refund = api_instance. test_payment_controller_refund_payment_v0 ( 'payment-id' , opts)
puts "Refund processed: #{ refund. id } "
Parameters:
id: String - Payment ID
opts: Hash - Optional parameters
refund_amount: Float - Amount to refund (defaults to full amount)
Returns: RefundResponseDto
Transfers
Initiate and manage fund transfers between different payment rails.
Methods
transfer_controller_create_direct_bank_transfer(create_direct_bank_transfer_dto)
Create a direct bank transfer.
require 'devdraft'
api_instance = Devdraft :: TransfersApi . new
begin
transfer_dto = Devdraft :: CreateDirectBankTransferDto . new (
wallet_id: 'wallet-id' ,
payment_rail: 'wire' ,
source_currency: 'usd' ,
destination_currency: 'usdc' ,
amount: 1000.00
)
transfer = api_instance. transfer_controller_create_direct_bank_transfer (transfer_dto)
puts "Transfer created: #{ transfer. id } "
puts "Bank instructions: #{ transfer. source_deposit_instructions } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_direct_bank_transfer_dto: CreateDirectBankTransferDto - Transfer details
Returns: Transfer
See also: Direct Bank Transfer Guide
transfer_controller_create_direct_wallet_transfer(create_direct_wallet_transfer_dto)
Create a direct wallet transfer.
transfer_dto = Devdraft :: CreateDirectWalletTransferDto . new (
wallet_id: 'wallet-id' ,
network: 'solana' ,
stable_coin_currency: 'usdc' ,
amount: 500.00
)
transfer = api_instance. transfer_controller_create_direct_wallet_transfer (transfer_dto)
puts "Transfer created: #{ transfer. id } "
puts "Deposit address: #{ transfer. source_deposit_instructions . to_address } "
Parameters:
create_direct_wallet_transfer_dto: CreateDirectWalletTransferDto - Transfer details
Returns: Transfer
See also: Direct Wallet Transfer Guide
transfer_controller_create_external_bank_transfer(create_external_bank_transfer_dto)
Create an external bank transfer (from your wallet to external bank).
transfer_dto = Devdraft :: CreateExternalBankTransferDto . new (
source_wallet_id: 'wallet-id' ,
destination_bank_account_id: 'bank-account-id' ,
amount: 1000.00 ,
currency: 'USD'
)
transfer = api_instance. transfer_controller_create_external_bank_transfer (transfer_dto)
puts "External bank transfer: #{ transfer. id } "
Parameters:
create_external_bank_transfer_dto: CreateExternalBankTransferDto - Transfer details
Returns: Transfer
transfer_controller_create_external_stablecoin_transfer(create_external_stablecoin_transfer_dto)
Create an external stablecoin transfer (from your wallet to external wallet).
transfer_dto = Devdraft :: CreateExternalStablecoinTransferDto . new (
source_wallet_id: 'wallet-id' ,
destination_address: '0x742d35Cc6Ff82a8C2D8D1Da9da17c7eDfD5bE0a3' ,
network: 'ethereum' ,
currency: 'usdc' ,
amount: 250.00
)
transfer = api_instance. transfer_controller_create_external_stablecoin_transfer (transfer_dto)
puts "External stablecoin transfer: #{ transfer. id } "
Parameters:
create_external_stablecoin_transfer_dto: CreateExternalStablecoinTransferDto - Transfer details
Returns: Transfer
transfer_controller_create_stablecoin_conversion(create_stablecoin_conversion_dto)
Convert between different stablecoins or networks.
conversion_dto = Devdraft :: CreateStablecoinConversionDto . new (
source_wallet_id: 'wallet-id' ,
destination_wallet_id: 'wallet-id' ,
source_network: 'ethereum' ,
destination_network: 'solana' ,
source_currency: 'usdc' ,
destination_currency: 'usdc' ,
amount: 1000.00
)
conversion = api_instance. transfer_controller_create_stablecoin_conversion (conversion_dto)
puts "Conversion ID: #{ conversion. id } "
puts "Exchange rate: #{ conversion. exchange_rate . rate } "
puts "Estimated completion: #{ conversion. estimated_completion } "
Parameters:
create_stablecoin_conversion_dto: CreateStablecoinConversionDto - Conversion details
Returns: Conversion
See also: Stablecoin Conversion Guide
Wallets
Manage wallets and query balances.
Methods
wallet_controller_get_wallets()
Get all wallets for your application.
require 'devdraft'
api_instance = Devdraft :: WalletsApi . new
begin
api_instance. wallet_controller_get_wallets
puts 'Wallets retrieved successfully'
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Returns: nil
The response contains wallet IDs that you can use for transfers and other operations. In a future SDK version, this will return typed wallet objects.
Webhooks
Configure webhooks to receive real-time event notifications.
Methods
webhook_controller_create(create_webhook_dto)
Create a new webhook.
require 'devdraft'
api_instance = Devdraft :: WebhooksApi . new
begin
webhook_dto = Devdraft :: CreateWebhookDto . new (
url: 'https://your-app.com/webhooks/devdraft' ,
name: 'Production Webhook' ,
is_active: true ,
encrypted: false
)
webhook = api_instance. webhook_controller_create (webhook_dto)
puts "Webhook ID: #{ webhook. id } "
puts "Signing secret: #{ webhook. signing_secret } "
rescue Devdraft :: ApiError => e
puts "Error: #{ e } "
end
Parameters:
create_webhook_dto: CreateWebhookDto - Webhook configuration
Returns: WebhookResponseDto
See also: Webhooks Overview
webhook_controller_find_all(opts = {})
Get all webhooks.
opts = {
page: 1 ,
limit: 20 ,
active: true
}
webhooks = api_instance. webhook_controller_find_all (opts)
webhooks. each do | webhook |
puts " #{ webhook. name } : #{ webhook. url } "
puts "Active: #{ webhook. is_active } "
end
Parameters:
opts: Hash - Optional parameters
page: Integer - Page number
limit: Integer - Items per page
active: Boolean - Filter by active status
Returns: Array<WebhookResponseDto>
webhook_controller_find_one(id)
Get a webhook by ID.
webhook = api_instance. webhook_controller_find_one ( 'webhook-id' )
puts "Webhook: #{ webhook. name } "
puts "URL: #{ webhook. url } "
puts "Delivery stats: #{ webhook. delivery_stats } "
Parameters:
Returns: WebhookResponseDto
webhook_controller_update(id, update_webhook_dto)
Update a webhook.
update_dto = Devdraft :: UpdateWebhookDto . new (
url: 'https://your-app.com/webhooks/new-endpoint' ,
is_active: true
)
updated = api_instance. webhook_controller_update ( 'webhook-id' , update_dto)
puts "Webhook updated: #{ updated. id } "
Parameters:
id: String - Webhook ID
update_webhook_dto: UpdateWebhookDto - Fields to update
Returns: WebhookResponseDto
webhook_controller_remove(id)
Delete a webhook.
api_instance. webhook_controller_remove ( 'webhook-id' )
puts 'Webhook deleted'
Parameters:
Returns: nil
Error Handling
All SDK methods may raise Devdraft::ApiError. Handle them appropriately:
require 'devdraft'
begin
transfer = transfers_api. transfer_controller_create_direct_wallet_transfer (transfer_dto)
puts "Transfer created: #{ transfer. id } "
rescue Devdraft :: ApiError => e
case e. code
when 400
puts "Invalid request: #{ e. message } "
when 401
puts 'Authentication failed - check your API credentials'
when 404
puts "Resource not found: #{ e. message } "
when 422
puts "Validation error: #{ e. message } "
when 429
puts 'Rate limited - please retry later'
else
puts "API error ( #{ e. code } ): #{ e. message } "
end
# Access response body for more details
puts "Response body: #{ e. response_body } " if e. response_body
rescue StandardError => e
puts "Unexpected error: #{ e. message } "
end
Best Practices
Use Configuration Block
Set up configuration once at the start of your application. # In config/initializers/devdraft.rb (Rails)
# or at the top of your script
Devdraft . configure do | config |
config. api_key [ 'x-client-key' ] = ENV [ 'DEVDRAFT_CLIENT_KEY' ]
config. api_key [ 'x-client-secret' ] = ENV [ 'DEVDRAFT_CLIENT_SECRET' ]
config. base_url = ENV . fetch ( 'DEVDRAFT_API_URL' , 'https://api.devdraft.ai' )
# Optional: Configure debugging
config. debugging = ENV [ 'DEVDRAFT_DEBUG' ] == 'true'
# Optional: Configure timeout
config. timeout = 30
end
Use Environment Variables
Store credentials in environment variables, never in source code. # Use dotenv gem for development
require 'dotenv/load'
Devdraft . configure do | config |
config. api_key [ 'x-client-key' ] = ENV . fetch ( 'DEVDRAFT_CLIENT_KEY' )
config. api_key [ 'x-client-secret' ] = ENV . fetch ( 'DEVDRAFT_CLIENT_SECRET' )
end
Proper Exception Handling
Always wrap API calls in begin/rescue blocks. def create_transfer ( amount )
transfer_dto = Devdraft :: CreateDirectWalletTransferDto . new (
wallet_id: 'wallet-id' ,
network: 'solana' ,
stable_coin_currency: 'usdc' ,
amount: amount
)
begin
transfers_api. transfer_controller_create_direct_wallet_transfer (transfer_dto)
rescue Devdraft :: ApiError => e
Rails . logger . error ( "Transfer failed: #{ e. message } " )
raise
end
end
Use Symbols for Hash Keys
Follow Ruby conventions by using symbols for hash keys. # Good: Using symbols
opts = {
page: 1 ,
limit: 20 ,
status: 'ACTIVE'
}
# Works but not idiomatic
opts = {
'page' => 1 ,
'limit' => 20 ,
'status' => 'ACTIVE'
}
Use Blocks for Iteration
Use Ruby blocks for clean iteration over collections. # Good: Using blocks
customers. each do | customer |
puts " #{ customer. first_name } #{ customer. last_name } "
end
# Also good: Using map for transformations
customer_names = customers. map { | c | " #{ c. first_name } #{ c. last_name } " }
Implement Logging
Use Ruby’s built-in Logger or Rails logger. require 'logger'
logger = Logger . new ( STDOUT )
logger. level = Logger :: INFO
begin
logger. info ( "Creating transfer for amount: #{ amount } " )
transfer = transfers_api. transfer_controller_create_direct_wallet_transfer (dto)
logger. info ( "Transfer created: #{ transfer. id } " )
rescue Devdraft :: ApiError => e
logger. error ( "Transfer failed: #{ e. message } " )
raise
end
Testing with RSpec
Example RSpec test for SDK integration:
require 'spec_helper'
require 'devdraft'
RSpec . describe 'Devdraft Webhooks' do
before ( :all ) do
Devdraft . configure do | config |
config. api_key [ 'x-client-key' ] = ENV [ 'DEVDRAFT_TEST_CLIENT_KEY' ]
config. api_key [ 'x-client-secret' ] = ENV [ 'DEVDRAFT_TEST_CLIENT_SECRET' ]
end
end
let ( :api_instance ) { Devdraft :: WebhooksApi . new }
describe '#webhook_controller_create' do
it 'creates a webhook successfully' do
webhook_dto = Devdraft :: CreateWebhookDto . new (
url: 'https://test.example.com/webhook' ,
name: 'Test Webhook' ,
is_active: true ,
encrypted: false
)
webhook = api_instance. webhook_controller_create (webhook_dto)
expect (webhook. id ). not_to be_nil
expect (webhook. name ). to eq ( 'Test Webhook' )
expect (webhook. is_active ). to be true
end
it 'raises ApiError with invalid URL' do
webhook_dto = Devdraft :: CreateWebhookDto . new (
url: 'invalid-url' ,
name: 'Invalid Webhook' ,
is_active: true
)
expect {
api_instance. webhook_controller_create (webhook_dto)
}. to raise_error ( Devdraft :: ApiError )
end
end
describe '#webhook_controller_find_all' do
it 'returns an array of webhooks' do
webhooks = api_instance. webhook_controller_find_all
expect (webhooks). to be_an ( Array )
webhooks. each do | webhook |
expect (webhook). to be_a ( Devdraft :: WebhookResponseDto )
end
end
end
end
Rails Integration
Configuration
Create an initializer for Rails applications:
# config/initializers/devdraft.rb
Devdraft . configure do | config |
config. api_key [ 'x-client-key' ] = Rails . application . credentials . devdraft [ :client_key ]
config. api_key [ 'x-client-secret' ] = Rails . application . credentials . devdraft [ :client_secret ]
config. base_url = ENV . fetch ( 'DEVDRAFT_API_URL' , 'https://api.devdraft.ai' )
config. debugging = Rails . env . development?
end
Service Object Pattern
Create service objects for cleaner Rails integration:
# app/services/devdraft_service.rb
class DevdraftService
def initialize
@transfers_api = Devdraft :: TransfersApi . new
@webhooks_api = Devdraft :: WebhooksApi . new
end
def create_transfer ( wallet_id: , amount: )
transfer_dto = Devdraft :: CreateDirectWalletTransferDto . new (
wallet_id: wallet_id,
network: 'solana' ,
stable_coin_currency: 'usdc' ,
amount: amount
)
@transfers_api . transfer_controller_create_direct_wallet_transfer (transfer_dto)
rescue Devdraft :: ApiError => e
Rails . logger . error ( "Devdraft transfer error: #{ e. message } " )
raise
end
def create_webhook ( url: , name: )
webhook_dto = Devdraft :: CreateWebhookDto . new (
url: url,
name: name,
is_active: true ,
encrypted: false
)
@webhooks_api . webhook_controller_create (webhook_dto)
rescue Devdraft :: ApiError => e
Rails . logger . error ( "Devdraft webhook error: #{ e. message } " )
raise
end
end
Controller Example
Use the service in your Rails controllers:
# app/controllers/transfers_controller.rb
class TransfersController < ApplicationController
def create
service = DevdraftService . new
transfer = service. create_transfer (
wallet_id: params[ :wallet_id ],
amount: params[ :amount ]. to_f
)
render json: {
success: true ,
transfer_id: transfer. id ,
deposit_address: transfer. source_deposit_instructions &. to_address
}
rescue Devdraft :: ApiError => e
render json: {
success: false ,
error: e. message
}, status: e. code
rescue StandardError => e
render json: {
success: false ,
error: 'Internal server error'
}, status: :internal_server_error
end
end
Background Jobs
Process API calls in background jobs:
# app/jobs/create_transfer_job.rb
class CreateTransferJob < ApplicationJob
queue_as :default
def perform ( wallet_id , amount )
service = DevdraftService . new
transfer = service. create_transfer ( wallet_id: wallet_id, amount: amount)
# Notify user or update database
Rails . logger . info ( "Transfer created: #{ transfer. id } " )
rescue Devdraft :: ApiError => e
Rails . logger . error ( "Transfer job failed: #{ e. message } " )
# Optionally retry or notify admin
raise
end
end
Next Steps
SDK Quickstart Complete integration guide with examples
Transfers Learn about initiating transfers
Webhooks Set up webhook notifications
API Reference Complete REST API documentation