A Ruby gem for interacting with the SamCart API.
Add this line to your application's Gemfile:
gem 'samcart_api'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install samcart_api
SamcartApi.configure do |config|
config.api_key = 'your_api_key'
end
# Find a specific product
product = SamcartApi::Product.find('123')
# Access product attributes
product.id # => "123"
product.name # => "Test Product"
product.price # => "99.99"
product.created_at # => Time object
By default, SamcartApi::Product.all
returns a Paginator object, allowing you to iterate through paginated results efficiently.
Using each_page
to Iterate Over Paginated Results
SamcartApi::Product.all.each_page do |products|
products.each do |product|
puts "Product ID: #{product['id']}, Name: #{product['product_name']}"
end
end
You can filter products using query parameters such as status
, created_at_min
, created_at_max
, product_category
, and pricing_type
. See getProducts
# Find a specific order
order = SamcartApi::Order.find('123')
# Access order attributes
order.id # => "123"
order.status # => "completed"
order.total # => "99.99"
order.created_at # => Time object
By default, SamcartApi::Order.all
returns a Paginator object, allowing you to iterate through paginated results efficiently.
Using each_page
to Iterate Over Paginated Results
SamcartApi::Order.all.each_page do |orders|
orders.each do |order|
puts "Order ID: #{order['id']}"
end
end
If you need to make custom API calls, you can use the client directly:
client = SamcartApi::Client.new('your_api_key')
# GET request
response = client.get('/products')
# POST request
response = client.post('/orders', { product_id: '123' })
# PUT request
response = client.put('/products/123', { name: 'Updated Name' })
# DELETE request
response = client.delete('/products/123')
After checking out the repo, run bundle install
to install dependencies. Then, run rake spec
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
.
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request
The gem is available as open source under the terms of the MIT License.