SpreadshopClient
is a Ruby gem that provides a convenient interface for interacting with the Spreadshop GraphQL API. It simplifies fetching shop data by encapsulating the necessary queries and handling the API communication, making it easy to integrate into your Ruby projects or Rails applications.
Add this line to your application's Gemfile:
gem 'spreadshop_client'
And then execute:
bundle install
Or install it yourself as:
gem install spreadshop_client
Here's an example of how to use the SpreadshopClient gem to fetch shop details:
require 'spreadshop_client'
name = "my-shop" # Replace with the actual shop name
platform = "EU" # Replace with the platform
locale = "de_DE" # Replace with the locale
response = SpreadshopClient.get_shop(name: name, platform: platform, locale: locale)
if response.is_a?(SpreadshopClient::Shop)
puts "Shop ID: #{response.id}"
puts "Shop Name: #{response.name}"
elsif response.is_a?(Hash) && response[:error]
puts "Error: #{response[:error]}"
else
puts "Unexpected response: #{response.inspect}"
end
To fetch all products from a shop, you can use the SpreadshopClient as follows:
require 'spreadshop_client'
shop_id = "123456" # Replace with the actual shop ID
platform = "EU" # Replace with the platform
locale = "de_DE" # Replace with the locale
products = SpreadshopClient::Product.get_all(shop_id: shop_id, platform: platform, locale: locale)
if products.is_a?(Array)
puts "Number of Products: #{products.size}"
first_product = products.first
puts "First Product ID: #{first_product.id}"
puts "First Product Name: #{first_product.name}"
else
puts "Error fetching products: #{products[:error]}"
end
To fetch a specific product by ID:
product_id = "12345" # Replace with the actual product ID
product = SpreadshopClient::Product.get_by_id(product_id: product_id, shop_id: shop_id, platform: platform, locale: locale)
if product.is_a?(SpreadshopClient::Product)
puts "Product ID: #{product.id}"
puts "Product Name: #{product.name}"
else
puts "Error fetching product by ID: #{product[:error]}"
end
rake test
The project uses StandardRB to ensure consistent coding style. Run the linter with:
rake standard
rake standard:fix
Bug reports and pull requests are welcome on GitHub at https://github.com/paderich/spreadshop_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the SpreadshopClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.