Ruby SDK Integrations Documentation
Welcome to the documentation for integrating our services with the Ruby SDK. This guide provides comprehensive information on setting up, configuring, and utilizing the SDK for seamless integration into your Ruby applications.
Installation
To get started, you need to add the Ruby SDK to your project's Gemfile:
gem 'your_service_sdk'
Then, run the following command to install the gem:
bundle install
Alternatively, you can install it directly from RubyGems:
gem install your_service_sdk
Basic Usage
Initialize the SDK with your API key:
require 'your_service_sdk'
client = YourServiceSdk::Client.new(api_key: 'YOUR_API_KEY')
Now you can interact with various services. For example, fetching a list of items:
begin
items = client.list_items
items.each do |item|
puts "Item Name: #{item['name']}, ID: #{item['id']}"
end
rescue YourServiceSdk::Error => e
puts "An error occurred: #{e.message}"
end
API Reference
The Ruby SDK provides access to a rich set of functionalities. Below are some key modules and methods:
YourServiceSdk::Client
initialize(api_key:, options: {})
: Initializes the client.
list_items(params: {})
: Fetches a list of items.
get_item(id:)
: Retrieves a specific item by its ID.
create_item(attributes:)
: Creates a new item.
update_item(id:, attributes:)
: Updates an existing item.
delete_item(id:)
: Deletes an item.
YourServiceSdk::Errors
YourServiceSdk::Error
: Base class for all SDK errors.
YourServiceSdk::AuthenticationError
: Raised for invalid API keys.
YourServiceSdk::ApiError
: Raised for general API errors.
Examples
Creating a new item
require 'your_service_sdk'
client = YourServiceSdk::Client.new(api_key: 'YOUR_API_KEY')
begin
new_item_data = {
name: "Example Product",
price: 99.99,
description: "A wonderful example product."
}
created_item = client.create_item(attributes: new_item_data)
puts "Successfully created item with ID: #{created_item['id']}"
rescue YourServiceSdk::ApiError => e
puts "Failed to create item: #{e.message}"
end
Handling pagination
When fetching lists, you might encounter pagination. The SDK typically handles this by returning an array. For advanced control, check the specific method documentation.
require 'your_service_sdk'
client = YourServiceSdk::Client.new(api_key: 'YOUR_API_KEY')
# Fetch first page of items
items_page1 = client.list_items(params: { page: 1, per_page: 10 })
puts "Fetched #{items_page1.count} items from page 1."
# To fetch all items (use with caution for large datasets)
# all_items = client.list_items(params: { per_page: 100 }).auto_paginate
# For auto-pagination, assume a method like this exists or implement it
# based on the SDK's capabilities.
# The actual implementation might vary.
# Example if auto_paginate is a method on the response object:
# all_items = client.list_items.auto_paginate
# puts "Fetched a total of #{all_items.count} items."