README.md in bootic_client-0.0.5 vs README.md in bootic_client-0.0.6
- old
+ new
@@ -1,9 +1,8 @@
[](https://travis-ci.org/bootic/bootic_client.rb)
[](http://badge.fury.io/rb/bootic_client)
-## WORK IN PROGRESS
# BooticClient
Official Ruby client for the [Bootic API](https://developers.bootic.net)
@@ -51,17 +50,45 @@
all_products.each do |product|
puts product.title
puts product.price
end
- if all_product.has?(:next)
+ # Iterate through pages of products
+ # See "iterating" section below for a more elegant option
+ if all_products.has?(:next)
next_page = all_products.next
next_page.each{...}
end
end
```
+### Iterating
+
+Entities representing lists of things ([products](https://developers.bootic.net/rels/products/), [orders](https://developers.bootic.net/rels/orders/), etc) are fully [enumerable](http://ruby-doc.org/core-2.2.0/Enumerable.html).
+
+```ruby
+# These will only iterate this page's worth of products
+all_products.each{|pr| puts pr.title}
+all_products.map(&:title)
+all_products.reduce(0){|sum, pr| sum + pr.price}
+```
+
+These lists might be part of a paginated data set. If you want to iterate items across pages and make sure you consume the full set, use `#full_set`.
+
+```ruby
+# These will iterate all necessary pages
+all_products.full_set.each{|pr| puts pr.title }
+all_products.full_set.map(&:title)
+all_products.full_set.first(500)
+```
+
+You can check whether an entity is iterable with:
+
+```ruby
+all_products.respond_to?(:each)
+```
+
## Strategies
The Bootic Client supports different authentication strategies depending on the use case.
### 1. Refresh token flow (web apps)
@@ -104,17 +131,20 @@
if shop.can?(:create_product)
product = shop.create_product(
title: 'A shiny new product',
price: 122332,
status: "visible",
- collecton_names: ["Featured products", "Homepage"],
variants: [
{
title: 'First variant',
sku: 'F23332-X',
available_if_no_stock: 1,
stock: 12
}
+ ],
+ collections: [
+ {title: "A new collection"},
+ {id: 1234}
]
)
puts product.rels[:web].href # => 'http://acme.bootic.net/products/a-shiny-new-product'
end