Skip to content

Commit

Permalink
cleaning rubocop offenses, adding examples, bumping version
Browse files Browse the repository at this point in the history
  • Loading branch information
mingoscd committed Feb 17, 2016
1 parent 27f42e2 commit 574b75d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 12 deletions.
19 changes: 19 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## 1.0.4

* New Calls:

* Epages::REST::Shop#`update_product`
* Epages::REST::Shop#`product_add_slideshow_image`
* Epages::REST::Shop#`product_delete_slideshow_image`
* Epages::REST::Shop#`product_slideshow_sequence`
* Epages::REST::Shop#`product_update_slideshow_sequence`
* Epages::REST::Shop#`sales`
* Epages::REST::Shop#`parallel_calls`

* Other changes

* new attributes `shipping_data` and `payment_data` to orders
* replaced attribute `comment` with `ustomer_comment` and `internal_note`
* added range filters `crated_before` and `created_after` to orders
* dates and are interpreted as Datetime, before was String

19 changes: 19 additions & 0 deletions examples/miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,23 @@ Returns suggestions for a product search query. Returns an Array of Epages::Prod
```
jackets = shop.product_suggestions_for("Jacket")
top = shop.product_suggestions_for("Jacket", limit: 5)
```

## Parallel calls

Run the calls in different threads and return the responses in the same order as it was called.
The keys must be the same that the name of the method to call. If you want to call multiple times tha same call with different parameters put every collection as an array element

```
requests = {
products: {},
categories: {locale: 'en_GB'},
create_cart: {currency: 'USD', locale: 'en_US'},
}
product_requests = {
products: [{sort: 'name', results_per_page: 2}, {results_per_page: 1, page: 3}],
}
response = shop.parallel_calls(requests) # => { products: products_response, categories: categories_response, create_cart: create_cart_response }
product_response = shop.parallel_calls(requests) # => { products: [products_response_1, products_response_2] }
```
14 changes: 14 additions & 0 deletions examples/sales.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# [Sales Examples](https://developer.epages.com/apps/api-reference/resource-sales.html)

This example assumes you have configured the `shop` correctly.

# [Sales Call](https://developer.epages.com/apps/api-reference/get-shops-shopid-sales.html)

Returns the summary of sales for a specified product or for the shop grouped by currencies.

```
general_sales = shop.sales
product_sales = shop.sales(product_id: product)
today_sales = shop.sales(created_after: Date.today)
sales_since = shop.sales(created_after: '24-01-2016')
```
2 changes: 1 addition & 1 deletion lib/epages/rest/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def product_add_slideshow_image(product, image)
# @param image [String]
def product_delete_slideshow_image(product, image)
id = epages_id(product)
perform_delete_request("/products/#{id}/slideshow/#{image.to_s}")
perform_delete_request("/products/#{id}/slideshow/#{image}")
end

# call the API to get the slideshow sequence of a product
Expand Down
14 changes: 7 additions & 7 deletions lib/epages/rest/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(object, request_method, path, options = {})
def set_request_options(method, options)
@request_method = method
@headers = request_headers
@options = set_options(options)
@options = format_options(options)
end

def auth_token
Expand All @@ -40,7 +40,7 @@ def request_headers
end

def options_passed_by
return :form if @request_method == :post && @options.has_key?(:image)
return :form if @request_method == :post && @options.key?(:image)
case @request_method
when :get then :params
when :patch then :body
Expand All @@ -52,7 +52,7 @@ def content_type_options
@request_method == :patch ? 'application/json-patch+json' : 'application/json'
end

def set_options(options)
def format_options(options)
case @request_method
when :multipart_post then options_to_multipart_request(options)
when :patch then options_to_patch_request(options).to_json
Expand All @@ -62,10 +62,10 @@ def set_options(options)

def mime_type(basename)
case basename
when %r{.gif} then 'image/gif'
when %r{.jpe?g} then 'image/jpeg'
when %r{.png} then 'image/png'
else 'application/octet-stream'
when /.gif/ then 'image/gif'
when /.jpe?g/ then 'image/jpeg'
when /.png/ then 'image/png'
else 'application/octet-stream'
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/epages/rest/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def perform_post_with_objects(path, options, klass)
# @param options [Hash]
# @param klass [Class]
def perform_multipart_post_with_objects(path, image, klass)
response = perform_request(:multipart_post, path, {file: image})
response.has_key?('items') ? response[:items].collect { |data| klass.new(data) } : klass.new(response)
response = perform_request(:multipart_post, path, file: image)
response.key?('items') ? response[:items].collect { |data| klass.new(data) } : klass.new(response)
end

# @param request_method [Symbol]
Expand Down
2 changes: 1 addition & 1 deletion lib/epages/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Epages
VERSION = '1.0.3'
VERSION = '1.0.4'
end
2 changes: 1 addition & 1 deletion spec/epages/rest/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
end

it 'assigns attributes' do
api_product = shop.update_product(product, 'name' => name, 'short_description' => short_description, "price_info/price/amount" => price)
api_product = shop.update_product(product, 'name' => name, 'short_description' => short_description, 'price_info/price/amount' => price)
expect(api_product.name).to eq name
expect(api_product.short_description).to eq short_description
expect(api_product.price_info.price.amount).to eq price
Expand Down

0 comments on commit 574b75d

Please sign in to comment.