Ruby SDK

Last updated · Changelog · OpenAPI spec · Markdown

Our official Ruby SDK provides a convenient way to interact with the ShopSavvy Data API from Ruby applications with idiomatic Ruby patterns and comprehensive documentation.

Installation

gem install shopsavvy-sdk

# Or add to your Gemfile:
gem 'shopsavvy-sdk'

Basic Usage

require 'shopsavvy_data_api'

# Initialize the client
client = ShopsavvyDataApi.new(api_key: "ss_live_your_api_key_here")

# Look up a product by barcode
product = client.get_product_details("012345678901")
puts product.data.name

# Get current prices from all retailers
offers = client.get_current_offers("012345678901")
offers.data.each do |offer|
  puts "#{offer.retailer}: $#{offer.price}"
end

# Get price history
history = client.get_price_history(
  "012345678901",
  "2024-01-01",
  "2024-01-31"
)

Features

  • Idiomatic Ruby patterns and conventions
  • Comprehensive YARD documentation
  • Automatic retry logic with exponential backoff
  • Convenient model methods and helpers
  • Rails integration examples
  • Ruby 2.7+ compatibility

Rails Integration

# config/initializers/shopsavvy.rb
Rails.application.config.shopsavvy_client = ShopsavvyDataApi.new(
  api_key: Rails.application.credentials.shopsavvy_api_key
)

# In your models/controllers
client = Rails.application.config.shopsavvy_client
product = client.get_product_details(params[:barcode])

Error Handling

begin
  client = ShopsavvyDataApi.new(api_key: "ss_live_your_api_key_here")
  product = client.get_product_details("invalid-identifier")
rescue ShopsavvyDataApi::NotFoundError => e
  puts "Product not found"
rescue ShopsavvyDataApi::AuthenticationError => e
  puts "Invalid API key"
rescue ShopsavvyDataApi::RateLimitError => e
  puts "Rate limit exceeded"
rescue ShopsavvyDataApi::APIError => e
  puts "API error: #{e.message}"
end
Was this page helpful?