ecwid_api 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.travis.yml +0 -0
  5. data/Gemfile +0 -0
  6. data/LICENSE.txt +0 -0
  7. data/README.md +12 -4
  8. data/Rakefile +0 -0
  9. data/ecwid_api.gemspec +8 -7
  10. data/lib/ecwid_api.rb +3 -0
  11. data/lib/ecwid_api/api.rb +6 -3
  12. data/lib/ecwid_api/api/base.rb +0 -0
  13. data/lib/ecwid_api/api/categories.rb +0 -0
  14. data/lib/ecwid_api/api/customers.rb +53 -0
  15. data/lib/ecwid_api/api/orders.rb +4 -4
  16. data/lib/ecwid_api/api/product_combinations.rb +0 -0
  17. data/lib/ecwid_api/api/product_types.rb +56 -0
  18. data/lib/ecwid_api/api/products.rb +93 -7
  19. data/lib/ecwid_api/category.rb +0 -0
  20. data/lib/ecwid_api/client.rb +7 -5
  21. data/lib/ecwid_api/customer.rb +10 -0
  22. data/lib/ecwid_api/entity.rb +15 -3
  23. data/lib/ecwid_api/error.rb +1 -1
  24. data/lib/ecwid_api/o_auth.rb +0 -0
  25. data/lib/ecwid_api/order.rb +39 -9
  26. data/lib/ecwid_api/order_item.rb +0 -0
  27. data/lib/ecwid_api/paged_ecwid_response.rb +11 -9
  28. data/lib/ecwid_api/paged_enumerator.rb +0 -0
  29. data/lib/ecwid_api/person.rb +0 -0
  30. data/lib/ecwid_api/product.rb +0 -0
  31. data/lib/ecwid_api/product_combination.rb +0 -0
  32. data/lib/ecwid_api/product_type.rb +18 -0
  33. data/lib/ecwid_api/product_type_attribute.rb +27 -0
  34. data/lib/ecwid_api/unpaged_ecwid_response.rb +38 -0
  35. data/lib/ecwid_api/version.rb +1 -1
  36. data/lib/ext/string.rb +0 -0
  37. data/spec/api/categories_spec.rb +0 -0
  38. data/spec/api/customers_spec.rb +20 -0
  39. data/spec/api/orders_spec.rb +5 -5
  40. data/spec/api/product_types_spec.rb +20 -0
  41. data/spec/api/products_spec.rb +0 -0
  42. data/spec/category_spec.rb +0 -0
  43. data/spec/client_spec.rb +3 -3
  44. data/spec/entity_spec.rb +41 -14
  45. data/spec/fixtures/categories.json +0 -0
  46. data/spec/fixtures/category.json +0 -0
  47. data/spec/fixtures/classes.json +44 -0
  48. data/spec/fixtures/customers.json +48 -0
  49. data/spec/fixtures/order.json +1 -1
  50. data/spec/fixtures/orders.json +2 -1
  51. data/spec/fixtures/products.json +0 -0
  52. data/spec/helpers/client.rb +4 -2
  53. data/spec/oauth_spec.rb +4 -4
  54. data/spec/order_item_spec.rb +0 -0
  55. data/spec/order_spec.rb +12 -12
  56. data/spec/paged_enumerator_spec.rb +2 -2
  57. data/spec/spec_helper.rb +1 -1
  58. metadata +37 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 46dcd4e6a2d43c7fad4d64e00476a240b0d18c02
4
- data.tar.gz: ea1cccacb59b117efa147353ad038605a867a957
2
+ SHA256:
3
+ metadata.gz: b3586666f15cbba13b4138fd19fba02ac3e1dffccc70803d975215e447b8471b
4
+ data.tar.gz: 9aadcd7b9217e1e92cebdaba858da43cf359873b7d2be100a63f514313da63fd
5
5
  SHA512:
6
- metadata.gz: c8c88afb4c895ef03be8d767e2d8a347ca4109852813df33fc77126ada5109bc67c5809faaf48f77e2a8152eaea4be1e09e1a2478cf33204c3ac80ab73da6e13
7
- data.tar.gz: e7a441c8d51c30971954ad531930c7777a5af0abde8d77cfd850ab41c4e382397cdbc3f2d932f9ba7d11aeadf4b1cbefccc123ca6ed3fb60fd8e79d3d0e7b648
6
+ metadata.gz: 0d83a8bf4a7460bdbbf86b878b3383bd29fbb40659a7b3f3e796b058d20e36d6ec4ff8a0af33f50e34d888157eb3d75d28aec4d8a2c9b92870e19928fd0e504c
7
+ data.tar.gz: ce28316fc8cee04433d47b04ea9c58d79c6b2519aab5cd27735338268601c763c9d4cde6cef4afe463169078d94611febb637f93d0dd77f0861420df34a05159
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  A gem to interface with the Ecwid REST APIs.
4
4
 
5
- [![Code Climate](https://codeclimate.com/github/davidbiehl/ecwid_api.png)](https://codeclimate.com/github/davidbiehl/ecwid_api)
6
- [![Build Status](https://travis-ci.org/davidbiehl/ecwid_api.svg?branch=master)](https://travis-ci.org/davidbiehl/ecwid_api)
5
+ [![Code Climate](https://codeclimate.com/github/vishalzambre/ecwid_api.png)](https://codeclimate.com/github/vishalzambre/ecwid_api)
6
+ [![Build Status](https://travis-ci.org/vishalzambre/ecwid_api.svg?branch=master)](https://travis-ci.org/vishalzambre/ecwid_api)
7
7
 
8
8
  ## API v3 Warning!
9
9
 
10
10
  This is for the latest version of the API, also known as v3, which is currently
11
11
  in closed beta! The (incomplete) v1 API is still available on the
12
- [api-v1 branch](https://github.com/davidbiehl/ecwid_api/tree/api-v1).
12
+ [api-v1 branch](https://github.com/vishalzambre/ecwid_api/tree/api-v1).
13
13
 
14
14
  To participate in the beta, please contact Ecwid and they will give you the
15
15
  information necessary to configure and authorize your application with OAuth2.
@@ -196,12 +196,20 @@ that feature.
196
196
 
197
197
  ## Contributing
198
198
 
199
- 1. Fork it ( http://github.com/davidbiehl/ecwid_api/fork )
199
+ 1. Fork it ( http://github.com/vishalzambre/ecwid_api/fork )
200
200
  2. Create your feature branch (`git checkout -b my-new-feature`)
201
201
  3. Commit your changes (`git commit -am 'Add some feature'`)
202
202
  4. Push to the branch (`git push origin my-new-feature`)
203
203
  5. Create new Pull Request
204
204
 
205
+ ## Authors
206
+
207
+ * **Vishal Zambre** - *Current work* - [vishalzambre](https://github.com/vishalzambre)
208
+ * **David Biehl** - *Initial work* - [davidbiehl](https://github.com/davidbiehl)
209
+
210
+ See also the list of [contributors](https://github.com/vishalzambre/ecwid_api/contributors) who participated in this project.
211
+
212
+
205
213
  ## License
206
214
 
207
215
  The MIT License (MIT)
data/Rakefile CHANGED
File without changes
@@ -6,22 +6,23 @@ require 'ecwid_api/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ecwid_api"
8
8
  spec.version = EcwidApi::VERSION
9
- spec.authors = ["David Biehl"]
10
- spec.email = ["me@davidbiehl.com"]
9
+ spec.authors = ["David Biehl", "Vishal Zambre"]
10
+ spec.email = ["v.zambre@gmail.com"]
11
11
  spec.summary = %q{A client for the Ecwid REST API}
12
12
  spec.description = %q{A client for the Ecwid REST API in Ruby}
13
- spec.homepage = "https://github.com/davidbiehl/ecwid_api"
13
+ spec.homepage = "https://github.com/vishalzambre/ecwid_api"
14
14
  spec.license = "MIT"
15
+ spec.post_install_message = "Thanks for installing!"
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "bundler", "~> 1.5", ">= 1.5"
22
23
  spec.add_development_dependency "rake", "~> 0"
23
- spec.add_development_dependency "rspec", "~> 2.14", ">= 2.14.1"
24
+ spec.add_development_dependency "rspec", "~> 3.5", ">= 3.5"
24
25
 
25
- spec.add_dependency "faraday", "~> 0.9.0"
26
- spec.add_dependency "faraday_middleware", "~> 0.9.1"
26
+ spec.add_dependency "faraday", "~> 0.9"
27
+ spec.add_dependency "faraday_middleware", "~> 0.9"
27
28
  end
@@ -16,10 +16,13 @@ module EcwidApi
16
16
  require_relative "ecwid_api/entity"
17
17
 
18
18
  require_relative "ecwid_api/category"
19
+ require_relative "ecwid_api/customer"
19
20
  require_relative "ecwid_api/order"
20
21
  require_relative "ecwid_api/order_item"
21
22
  require_relative "ecwid_api/person"
22
23
  require_relative "ecwid_api/product_combination"
23
24
 
24
25
  require_relative "ecwid_api/product"
26
+ require_relative "ecwid_api/product_type"
27
+ require_relative "ecwid_api/product_type_attribute"
25
28
  end
@@ -1,9 +1,12 @@
1
1
  module EcwidApi
2
2
  module Api
3
3
  require_relative "api/base"
4
- require_relative "api/orders"
5
- require_relative "api/products"
4
+
6
5
  require_relative "api/categories"
6
+ require_relative "api/customers"
7
+ require_relative "api/orders"
7
8
  require_relative "api/product_combinations"
9
+ require_relative "api/product_types"
10
+ require_relative "api/products"
8
11
  end
9
- end
12
+ end
File without changes
File without changes
@@ -0,0 +1,53 @@
1
+ require_relative "../paged_ecwid_response"
2
+
3
+ module EcwidApi
4
+ module Api
5
+ class Customers < Base
6
+ # Public: Get all of the Customer objects for the Ecwid store
7
+ #
8
+ # Returns an Array of Customer objects
9
+ def all(params = {})
10
+ PagedEcwidResponse.new(client, "customers", params) do |customer_hash|
11
+ Customer.new(customer_hash, client: client)
12
+ end
13
+ end
14
+
15
+ # Public: Finds a single customer by customer ID
16
+ #
17
+ # id - an Ecwid customer ID
18
+ #
19
+ # Returns a Customer object, or nil if one can't be found
20
+ def find(id)
21
+ response = client.get("customers/#{id}")
22
+ if response.success?
23
+ Customer.new(response.body, client: client)
24
+ end
25
+ end
26
+
27
+ # Public: Creates a new Customer
28
+ #
29
+ # params - a Hash
30
+ #
31
+ # Raises an Error if there is a problem
32
+ #
33
+ # Returns a Customer object
34
+ def create(params)
35
+ response = client.post("customers", params)
36
+ find(response.body["id"])
37
+ end
38
+
39
+ # Public: Updates an existing Customer
40
+ #
41
+ # id - the Ecwid customer ID
42
+ # params - a Hash
43
+ #
44
+ # Raises an Error if there is a problem
45
+ #
46
+ # Returns a Customer object
47
+ def update(id, params)
48
+ client.put("customers/#{id}", params)
49
+ find(id)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -20,13 +20,13 @@ module EcwidApi
20
20
  end
21
21
  end
22
22
 
23
- # Public: Finds a an Order given an Ecwid order_number
23
+ # Public: Finds a an Order given an Ecwid id
24
24
  #
25
- # order_number - an Integer that is the Ecwid Order number
25
+ # id - an Integer that is the Ecwid Order number
26
26
  #
27
27
  # Returns an EcwidApi::Order if found, nil if not
28
- def find(order_number)
29
- response = client.get("orders/#{order_number}")
28
+ def find(id)
29
+ response = client.get("orders/#{id}")
30
30
  if response.success?
31
31
  Order.new(response.body, client: client)
32
32
  end
File without changes
@@ -0,0 +1,56 @@
1
+ require_relative "../unpaged_ecwid_response"
2
+
3
+ module EcwidApi
4
+ module Api
5
+ class ProductTypes < Base
6
+ # Public: Get all of the ProductType objects for the Ecwid store
7
+ #
8
+ # Returns an Array of ProductType objects
9
+ # NOTE: This endpoint does not behave like other Ecwid endpoints in that
10
+ # it does not return paged results. It simply returns every
11
+ # result in an array, without a wrapper with an "items" property.
12
+ def all(params = {})
13
+ UnpagedEcwidResponse.new(client, "classes") do |product_type_hash|
14
+ ProductType.new(product_type_hash, client: client)
15
+ end
16
+ end
17
+
18
+ # Public: Finds a single product_type by product_type ID
19
+ #
20
+ # id - an Ecwid product_type ID
21
+ #
22
+ # Returns a ProductType object, or nil if one can't be found
23
+ def find(id)
24
+ response = client.get("classes/#{id}")
25
+ if response.success?
26
+ ProductType.new(response.body, client: client)
27
+ end
28
+ end
29
+
30
+ # Public: Creates a new ProductType
31
+ #
32
+ # params - a Hash
33
+ #
34
+ # Raises an Error if there is a problem
35
+ #
36
+ # Returns a ProductType object
37
+ def create(params)
38
+ response = client.post("classes", params)
39
+ find(response.body["id"])
40
+ end
41
+
42
+ # Public: Updates an existing ProductType
43
+ #
44
+ # id - the Ecwid product_type ID
45
+ # params - a Hash
46
+ #
47
+ # Raises an Error if there is a problem
48
+ #
49
+ # Returns a ProductType object
50
+ def update(id, params)
51
+ client.put("classes/#{id}", params)
52
+ find(id)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -4,7 +4,77 @@ module EcwidApi
4
4
  module Api
5
5
  class Products < Base
6
6
  # Public: Get all of the Product objects for the Ecwid store
7
- #
7
+ # params - a hash of request parameters. Parameters can be
8
+ # keyword string Search term. Use quotes to search for exact match.
9
+ # Ecwid searches products over multiple fields:
10
+ # * title
11
+ # * description
12
+ # * SKU
13
+ # * product options
14
+ # * category name
15
+ # * gallery image descriptions
16
+ # * attribute values (except for hidden attributes).
17
+ # If your keywords contain special characters,
18
+ # it may make sense to URL encode them before making a request
19
+ # priceFrom number Minimum product price
20
+ # priceTo number Maximum product price
21
+ # category number Category ID. To get Store Front Page products, specify `&category=0` in the request
22
+ # withSubcategories boolean `true/false`: defines whether Ecwid should search in subcategories of the
23
+ # category you set in `category` field. Ignored if `category` field is not set.
24
+ # `false` is the default value
25
+ # sortBy string Sort order. Supported values:
26
+ # * `RELEVANCE` default
27
+ # * `DEFINED_BY_STORE_OWNER`
28
+ # * `ADDED_TIME_DESC`
29
+ # * `ADDED_TIME_ASC`
30
+ # * `NAME_ASC`
31
+ # * `NAME_DESC`
32
+ # * `PRICE_ASC`
33
+ # * `PRICE_DESC`
34
+ # * `UPDATED_TIME_ASC`
35
+ # * `UPDATED_TIME_DESC`
36
+ # . If request is applicable to a specific category (i.e. `category` is set),
37
+ # then `DEFINED_BY_STORE_OWNER` sort method is used
38
+ # offset number Offset from the beginning of the returned items list (for paging)
39
+ # limit number Maximum number of returned items. Maximum allowed value: `100`. Default value: `100`
40
+ # createdFrom string Product creation date/time (lower bound). Supported formats:
41
+ # * UNIX timestamp
42
+ # Examples:
43
+ # * `1447804800`
44
+ # createdTo string Product creation date/time (upper bound). Supported formats:
45
+ # * UNIX timestamp
46
+ # updatedFrom string Product last update date/time (lower bound). Supported formats:
47
+ # * UNIX timestamp
48
+ # updatedTo string Product last update date/time (upper bound). Supported formats:
49
+ # * UNIX timestamp
50
+ # enabled boolean `true` to get only enabled products, `false` to get only disabled products
51
+ # inStock boolean `true` to get only products in stock, `false` to get out of stock products
52
+ # sku string Product or variation SKU. Ecwid will return details of a product containing that SKU,
53
+ # if SKU value is an exact match. If SKU is specified, other search parameters are ignored,
54
+ # except for product ID.
55
+ # productId number Internal Ecwid product ID or multiple productIds separated by a comma. If this field is
56
+ # specified, other search parameters are ignored.
57
+ # baseUrl string Storefront URL for Ecwid to use when returning product URLs in the url field.
58
+ # If not specified, Ecwid will use the storefront URL specified in the store settings
59
+ # cleanUrls boolean If `true`, Ecwid will return the SEO-friendly clean URL (without hash `'#'`) in the `url` field.
60
+ # If `false`, Ecwid will return URL in the old format (with hash `'#'`). We recommend using
61
+ # `true` value if merchant’s website supports clean SEO-friendly URL feature
62
+ # onsale string Use `"onsale"` to get on sale items only or `"notonsale"` for items not currently on sale.
63
+ # option_{optionName} string Filter by product option values. Format: `option_{optionName}=param[,param]`,
64
+ # where optionName is the attribute name and param is the attribute value.
65
+ # You can place several values separated by comma. In that case, values will be connected
66
+ # through logical “OR”, and if the product has at least one of them it will get to the
67
+ # search results. Example:
68
+ # `option_Size=S,M,L&option_Color=Red,Black`
69
+ # attribute_{attributeName} string Filter by product attribute values. Format: `attribute_{attributeName}=param[,param]`,
70
+ # where attributeName is the attribute name and param is the attribute value.
71
+ # You can place several values separated by comma. In that case, values will be connected
72
+ # through logical “OR”, and if the product has at least one of them it will get to the
73
+ # search results. Example:
74
+ # `attribute_Brand=Apple&attribute_Capacity=32GB,64GB`
75
+ # lang string Preferred language for the product fields in search results.
76
+ # If a certain field does not have the translation available for the set language,
77
+ # the default language text will be used for that field.
8
78
  # Returns an Array of Product objects
9
79
  def all(params = {})
10
80
  PagedEcwidResponse.new(client, "products", params) do |product_hash|
@@ -15,10 +85,18 @@ module EcwidApi
15
85
  # Public: Finds a single product by product ID
16
86
  #
17
87
  # id - an Ecwid product ID
18
- #
88
+ # params - a hash of request parameters. Parameters can be
89
+ # baseUrl string Storefront URL for Ecwid to use when returning product URLs in the url field.
90
+ # If not specified, Ecwid will use the storefront URL specified in the
91
+ # cleanUrls boolean If `true`, Ecwid will return the SEO-friendly clean URL (without hash '#')
92
+ # in the url field. If `false`, Ecwid will return URL in the old format (with hash '#').
93
+ # We recommend using `true` value if merchant’s website supports clean
94
+ # lang string Preferred language for the product fields in search results. If a certain field does
95
+ # not have the translation available for the set language, the default language text
96
+ # will be used for that field.
19
97
  # Returns a Product object, or nil if one can't be found
20
- def find(id)
21
- response = client.get("products/#{id}")
98
+ def find(id, params = {})
99
+ response = client.get("products/#{id}", params)
22
100
  if response.success?
23
101
  Product.new(response.body, client: client)
24
102
  end
@@ -27,10 +105,18 @@ module EcwidApi
27
105
  # Public: Finds a single Product by SKU
28
106
  #
29
107
  # sku - a SKU of a product
30
- #
108
+ # params - a hash of request parameters. Parameters can be
109
+ # baseUrl string Storefront URL for Ecwid to use when returning product URLs in the url field.
110
+ # If not specified, Ecwid will use the storefront URL specified in the
111
+ # cleanUrls boolean If `true`, Ecwid will return the SEO-friendly clean URL (without hash '#')
112
+ # in the url field. If `false`, Ecwid will return URL in the old format (with hash '#').
113
+ # We recommend using `true` value if merchant’s website supports clean
114
+ # lang string Preferred language for the product fields in search results. If a certain field does
115
+ # not have the translation available for the set language, the default language text
116
+ # will be used for that field.
31
117
  # Returns a Product object, or nil if one can't be found
32
- def find_by_sku(sku)
33
- all(keyword: sku).find { |product| product[:sku] == sku }
118
+ def find_by_sku(sku, params = {})
119
+ all(params.merge(keyword: sku)).find { |product| product[:sku] == sku }
34
120
  end
35
121
 
36
122
  # Public: Creates a new Product
File without changes
@@ -20,7 +20,7 @@ module EcwidApi
20
20
  attr_reader :token
21
21
  attr_reader :adapter
22
22
 
23
- attr_reader :connection, :categories, :orders, :products
23
+ attr_reader :connection, :categories, :customers, :orders, :products, :product_types
24
24
 
25
25
  # Public: Initializes a new Client to interact with the API
26
26
  #
@@ -41,9 +41,11 @@ module EcwidApi
41
41
  conn.adapter adapter
42
42
  end
43
43
 
44
- @categories = Api::Categories.new(self)
45
- @orders = Api::Orders.new(self)
46
- @products = Api::Products.new(self)
44
+ @categories = Api::Categories.new(self)
45
+ @customers = Api::Customers.new(self)
46
+ @orders = Api::Orders.new(self)
47
+ @products = Api::Products.new(self)
48
+ @product_types = Api::ProductTypes.new(self)
47
49
  end
48
50
 
49
51
  # Public: The URL of the API for the Ecwid Store
@@ -97,4 +99,4 @@ module EcwidApi
97
99
  end
98
100
  end
99
101
  end
100
- end
102
+ end
@@ -0,0 +1,10 @@
1
+ module EcwidApi
2
+ class Customer < Entity
3
+ self.url_root = "customers"
4
+
5
+ ecwid_reader :name, :email, :totalOrderCount, :customerGroupId, :customerGroupName
6
+
7
+ ecwid_writer :name, :email
8
+
9
+ end
10
+ end
@@ -1,8 +1,8 @@
1
1
  module EcwidApi
2
2
  class Entity
3
3
  # Private: Gets the Hash of data
4
- attr_reader :data
5
- protected :data
4
+ attr_reader :data, :new_data
5
+ protected :data, :new_data
6
6
 
7
7
  attr_reader :client
8
8
  private :client
@@ -173,5 +173,17 @@ module EcwidApi
173
173
  def to_json(*args)
174
174
  data.to_json(*args)
175
175
  end
176
+
177
+ def marshal_dump
178
+ [@data, @new_data]
179
+ end
180
+
181
+ def marshal_load(array)
182
+ @data, @new_data = *array
183
+ end
184
+
185
+ def ==(other)
186
+ data == other.data && new_data == other.new_data
187
+ end
176
188
  end
177
- end
189
+ end