ecwid_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.travis.yml +0 -0
  5. data/Gemfile +0 -2
  6. data/LICENSE.txt +0 -0
  7. data/README.md +228 -228
  8. data/Rakefile +0 -0
  9. data/ecwid_api.gemspec +4 -4
  10. data/lib/ecwid_api.rb +25 -25
  11. data/lib/ecwid_api/api.rb +8 -30
  12. data/lib/ecwid_api/api/base.rb +17 -16
  13. data/lib/ecwid_api/api/categories.rb +55 -56
  14. data/lib/ecwid_api/api/orders.rb +36 -36
  15. data/lib/ecwid_api/api/product_combinations.rb +2 -5
  16. data/lib/ecwid_api/api/products.rb +61 -63
  17. data/lib/ecwid_api/category.rb +1 -7
  18. data/lib/ecwid_api/client.rb +99 -65
  19. data/lib/ecwid_api/entity.rb +4 -6
  20. data/lib/ecwid_api/error.rb +12 -12
  21. data/lib/ecwid_api/o_auth.rb +105 -105
  22. data/lib/ecwid_api/order.rb +0 -0
  23. data/lib/ecwid_api/order_item.rb +0 -0
  24. data/lib/ecwid_api/paged_ecwid_response.rb +0 -0
  25. data/lib/ecwid_api/paged_enumerator.rb +0 -0
  26. data/lib/ecwid_api/person.rb +0 -0
  27. data/lib/ecwid_api/product.rb +3 -15
  28. data/lib/ecwid_api/product_combination.rb +1 -5
  29. data/lib/ecwid_api/version.rb +1 -1
  30. data/lib/ext/string.rb +12 -12
  31. data/spec/api/categories_spec.rb +30 -30
  32. data/spec/api/orders_spec.rb +29 -29
  33. data/spec/api/products_spec.rb +0 -0
  34. data/spec/category_spec.rb +33 -33
  35. data/spec/client_spec.rb +20 -20
  36. data/spec/entity_spec.rb +0 -0
  37. data/spec/fixtures/categories.json +0 -0
  38. data/spec/fixtures/category.json +0 -0
  39. data/spec/fixtures/order.json +0 -0
  40. data/spec/fixtures/orders.json +0 -0
  41. data/spec/fixtures/products.json +0 -0
  42. data/spec/helpers/client.rb +31 -31
  43. data/spec/oauth_spec.rb +39 -39
  44. data/spec/order_item_spec.rb +11 -11
  45. data/spec/order_spec.rb +0 -0
  46. data/spec/paged_enumerator_spec.rb +0 -0
  47. data/spec/spec_helper.rb +24 -24
  48. metadata +26 -34
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,3 @@
1
- require "open-uri"
2
-
3
1
  module EcwidApi
4
2
  class Product < Entity
5
3
  self.url_root = "products"
@@ -27,11 +25,7 @@ module EcwidApi
27
25
  #
28
26
  # Returns a Faraday::Response object
29
27
  def upload_image!(filename)
30
- client.post("#{url}/image") do |req|
31
- req.body = open(filename).read
32
- end.tap do |response|
33
- raise_on_failure(response)
34
- end
28
+ client.post_image("#{url}/image", filename)
35
29
  end
36
30
 
37
31
  # Public: Uploads gallery images for a Product
@@ -43,11 +37,7 @@ module EcwidApi
43
37
  # Returns an Array of Faraday::Response object
44
38
  def upload_gallery_images!(*filenames)
45
39
  filenames.map do |filename|
46
- client.post("#{url}/gallery") do |req|
47
- req.body = open(filename).read
48
- end.tap do |response|
49
- raise_on_failure(response)
50
- end
40
+ client.post_image("#{url}/gallery", filename)
51
41
  end
52
42
  end
53
43
 
@@ -57,9 +47,7 @@ module EcwidApi
57
47
  #
58
48
  # Returns a Faraday::Response object
59
49
  def delete_gallery_images!
60
- client.delete("#{url}/gallery").tap do |response|
61
- raise_on_failure(response)
62
- end
50
+ client.delete("#{url}/gallery")
63
51
  end
64
52
 
65
53
  def combinations
@@ -24,11 +24,7 @@ module EcwidApi
24
24
  #
25
25
  # Returns a Faraday::Response object
26
26
  def upload_image!(filename)
27
- client.post("#{url}/image") do |req|
28
- req.body = open(filename).read
29
- end.tap do |response|
30
- raise_on_failure(response)
31
- end
27
+ client.post_image("#{url}/image", filename)
32
28
  end
33
29
  end
34
30
  end
@@ -1,3 +1,3 @@
1
1
  module EcwidApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,13 +1,13 @@
1
- class String
2
- def camel_case
3
- split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
4
- end unless method_defined?(:camel_case)
5
-
6
- def underscore
7
- self.gsub(/::/, '/').
8
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
- tr("-", "_").
11
- downcase
12
- end unless method_defined?(:underscore)
1
+ class String
2
+ def camel_case
3
+ split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
4
+ end unless method_defined?(:camel_case)
5
+
6
+ def underscore
7
+ self.gsub(/::/, '/').
8
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
+ tr("-", "_").
11
+ downcase
12
+ end unless method_defined?(:underscore)
13
13
  end
@@ -1,31 +1,31 @@
1
- require 'spec_helper'
2
-
3
- describe EcwidApi::Api::Categories, faraday: true do
4
- subject { client.categories }
5
-
6
- describe "#all" do
7
- it "gets all of the categories from the client" do
8
- expect(client).to receive(:get).with("categories", hash_including({})).and_call_original
9
- subject.all
10
- end
11
-
12
- it "gets sub categories" do
13
- expect(client).to receive(:get).with("categories", hash_including(parent: 5)).and_call_original
14
- subject.all(parent: 5)
15
- end
16
- end
17
-
18
- describe "#root" do
19
- it "gets the root level categories" do
20
- expect(subject).to receive(:all).with(hash_including(parent: 0)).and_call_original
21
- subject.root
22
- end
23
- end
24
-
25
- describe "#find" do
26
- it "finds a single category" do
27
- expect(client).to receive(:get).with("categories/#{5}").and_call_original
28
- subject.find(5)
29
- end
30
- end
1
+ require 'spec_helper'
2
+
3
+ describe EcwidApi::Api::Categories, faraday: true do
4
+ subject { client.categories }
5
+
6
+ describe "#all" do
7
+ it "gets all of the categories from the client" do
8
+ expect(client).to receive(:get).with("categories", hash_including({})).and_call_original
9
+ subject.all
10
+ end
11
+
12
+ it "gets sub categories" do
13
+ expect(client).to receive(:get).with("categories", hash_including(parent: 5)).and_call_original
14
+ subject.all(parent: 5)
15
+ end
16
+ end
17
+
18
+ describe "#root" do
19
+ it "gets the root level categories" do
20
+ expect(subject).to receive(:all).with(hash_including(parent: 0)).and_call_original
21
+ subject.root
22
+ end
23
+ end
24
+
25
+ describe "#find" do
26
+ it "finds a single category" do
27
+ expect(client).to receive(:get).with("categories/#{5}").and_call_original
28
+ subject.find(5)
29
+ end
30
+ end
31
31
  end
@@ -1,30 +1,30 @@
1
- require 'spec_helper'
2
-
3
- describe EcwidApi::Api::Orders, faraday: true do
4
- subject { client.orders }
5
-
6
- describe "#all" do
7
- it "passes the parameters to the client" do
8
- expect(client).to receive(:get).with("orders", hash_including(from_date: '1982-05-17'))
9
- subject.all(from_date: '1982-05-17')
10
- end
11
-
12
- it "gets the proper response (see fixtures)" do
13
- subject.all.count.should == 2
14
- end
15
-
16
- it "gets EcwidApi::Order types" do
17
- subject.all.all? { |order| order.is_a?(EcwidApi::Order) }.should be_true
18
- end
19
- end
20
-
21
- describe "#find" do
22
- it "is an `EcwidApi::Order`" do
23
- subject.find(35).is_a?(EcwidApi::Order).should be_true
24
- end
25
-
26
- it "is nil when not found" do
27
- subject.find(404).should be_nil
28
- end
29
- end
1
+ require 'spec_helper'
2
+
3
+ describe EcwidApi::Api::Orders, faraday: true do
4
+ subject { client.orders }
5
+
6
+ describe "#all" do
7
+ it "passes the parameters to the client" do
8
+ expect(client).to receive(:get).with("orders", hash_including(from_date: '1982-05-17'))
9
+ subject.all(from_date: '1982-05-17')
10
+ end
11
+
12
+ it "gets the proper response (see fixtures)" do
13
+ subject.all.count.should == 2
14
+ end
15
+
16
+ it "gets EcwidApi::Order types" do
17
+ subject.all.all? { |order| order.is_a?(EcwidApi::Order) }.should be_true
18
+ end
19
+ end
20
+
21
+ describe "#find" do
22
+ it "is an `EcwidApi::Order`" do
23
+ subject.find(35).is_a?(EcwidApi::Order).should be_true
24
+ end
25
+
26
+ it "is nil when not found" do
27
+ subject.find(404).should be_nil
28
+ end
29
+ end
30
30
  end
File without changes
@@ -1,34 +1,34 @@
1
- require 'spec_helper'
2
-
3
- describe EcwidApi::Category, faraday: true do
4
- subject { EcwidApi::Category.new({"id" => 123, "parentId" => 456}, client: client) }
5
-
6
- describe "#sub_categories" do
7
- it "sends the request to the CategoryApi" do
8
- expect(client.categories).to receive(:all).with(parent: 123)
9
- subject.sub_categories
10
- end
11
-
12
- it "is memoized" do
13
- subject.sub_categories
14
- expect(client.categories).to_not receive(:all)
15
- subject.sub_categories
16
- end
17
- end
18
-
19
- describe "#parent" do
20
- it "sends the request for the parent to the CategoryApi" do
21
- expect(client.categories).to receive(:find).with(456)
22
- subject.parent
23
- end
24
-
25
- context "without a parent" do
26
- subject { EcwidApi::Category.new({"id" => 123}) }
27
-
28
- it "returns nil" do
29
- expect(client.categories).to_not receive(:find)
30
- subject.parent.should be_nil
31
- end
32
- end
33
- end
1
+ require 'spec_helper'
2
+
3
+ describe EcwidApi::Category, faraday: true do
4
+ subject { EcwidApi::Category.new({"id" => 123, "parentId" => 456}, client: client) }
5
+
6
+ describe "#sub_categories" do
7
+ it "sends the request to the CategoryApi" do
8
+ expect(client.categories).to receive(:all).with(parent: 123)
9
+ subject.sub_categories
10
+ end
11
+
12
+ it "is memoized" do
13
+ subject.sub_categories
14
+ expect(client.categories).to_not receive(:all)
15
+ subject.sub_categories
16
+ end
17
+ end
18
+
19
+ describe "#parent" do
20
+ it "sends the request for the parent to the CategoryApi" do
21
+ expect(client.categories).to receive(:find).with(456)
22
+ subject.parent
23
+ end
24
+
25
+ context "without a parent" do
26
+ subject { EcwidApi::Category.new({"id" => 123}) }
27
+
28
+ it "returns nil" do
29
+ expect(client.categories).to_not receive(:find)
30
+ subject.parent.should be_nil
31
+ end
32
+ end
33
+ end
34
34
  end
@@ -1,21 +1,21 @@
1
- require "spec_helper"
2
-
3
- describe EcwidApi::Client do
4
- subject { client }
5
-
6
- describe "#store_url" do
7
- its(:store_url) { "http://app.ecwid.com/api/v3/12345" }
8
- end
9
-
10
- describe "#get", faraday: true do
11
- it "delegates to the Faraday connection" do
12
- expect(subject.send(:connection)).to receive(:get).with("categories", parent: 1)
13
-
14
- subject.get "categories", parent: 1
15
- end
16
-
17
- it "returns a Faraday::Response" do
18
- subject.get("categories", parent: 1).is_a?(Faraday::Response).should be_true
19
- end
20
- end
1
+ require "spec_helper"
2
+
3
+ describe EcwidApi::Client do
4
+ subject { client }
5
+
6
+ describe "#store_url" do
7
+ its(:store_url) { "http://app.ecwid.com/api/v3/12345" }
8
+ end
9
+
10
+ describe "#get", faraday: true do
11
+ it "delegates to the Faraday connection" do
12
+ expect(subject.send(:connection)).to receive(:get).with("categories", parent: 1)
13
+
14
+ subject.get "categories", parent: 1
15
+ end
16
+
17
+ it "returns a Faraday::Response" do
18
+ subject.get("categories", parent: 1).is_a?(Faraday::Response).should be_true
19
+ end
20
+ end
21
21
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,32 +1,32 @@
1
- module Helpers
2
- module Client
3
- def client
4
- @client ||= EcwidApi::Client.new(12345, "access_token").tap do |client|
5
- allow(client).to receive(:connection).and_return(faraday)
6
- end
7
- end
8
-
9
- def fixtures
10
- %w(categories category orders products)
11
- end
12
-
13
- def faraday_stubs
14
- ::Faraday::Adapter::Test::Stubs.new do |stub|
15
- fixtures.each do |fixture|
16
- stub.get(fixture) { [ 200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/#{fixture}.json") ] }
17
- end
18
- stub.get("/categories/5") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/category.json") ] }
19
- stub.get("/orders/35") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/order.json") ] }
20
- stub.get("/orders/404") { [404, {"Content-Type" => "application/json"}, nil ] }
21
- end
22
- end
23
-
24
- # Public: Returns a test Faraday::Connection
25
- def faraday
26
- ::Faraday.new do |builder|
27
- builder.response :json, content_type: /\bjson$/
28
- builder.adapter :test, faraday_stubs
29
- end
30
- end
31
- end
1
+ module Helpers
2
+ module Client
3
+ def client
4
+ @client ||= EcwidApi::Client.new(12345, "access_token").tap do |client|
5
+ allow(client).to receive(:connection).and_return(faraday)
6
+ end
7
+ end
8
+
9
+ def fixtures
10
+ %w(categories category orders products)
11
+ end
12
+
13
+ def faraday_stubs
14
+ ::Faraday::Adapter::Test::Stubs.new do |stub|
15
+ fixtures.each do |fixture|
16
+ stub.get(fixture) { [ 200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/#{fixture}.json") ] }
17
+ end
18
+ stub.get("/categories/5") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/category.json") ] }
19
+ stub.get("/orders/35") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/order.json") ] }
20
+ stub.get("/orders/404") { [404, {"Content-Type" => "application/json"}, nil ] }
21
+ end
22
+ end
23
+
24
+ # Public: Returns a test Faraday::Connection
25
+ def faraday
26
+ ::Faraday.new do |builder|
27
+ builder.response :json, content_type: /\bjson$/
28
+ builder.adapter :test, faraday_stubs
29
+ end
30
+ end
31
+ end
32
32
  end
@@ -1,40 +1,40 @@
1
- require 'spec_helper'
2
-
3
- describe EcwidApi::OAuth do
4
- subject do
5
- EcwidApi::OAuth.new do |config|
6
- config.client_id = "client_id"
7
- config.client_secret = "client_secret"
8
- config.scope = "scope"
9
- config.redirect_uri = "https://example.com/oauth"
10
- end
11
- end
12
-
13
- its(:oauth_url) { should == "https://my.ecwid.com/api/oauth/authorize?client_id=client_id&scope=scope&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Foauth" }
14
-
15
- describe "#access_token(code)" do
16
- let(:response) do
17
- double("response").tap do |response|
18
- allow(response).to receive(:success?).and_return(true)
19
- allow(response).to receive(:body).and_return(access_token: "the_token", store_id: "12345")
20
- end
21
- end
22
-
23
- before(:each) do
24
- allow(subject.send(:connection)).to receive(:post).with("/api/oauth/token", hash_including(code: "code")).and_return(response)
25
- end
26
-
27
- it "sends a request to the API for an access_token" do
28
- expect(subject.send(:connection)).to receive(:post).with("/api/oauth/token", hash_including(code: "code")).and_return(response)
29
- subject.access_token("code")
30
- end
31
-
32
- it "returns an object that has the access_token" do
33
- subject.access_token("code").access_token.should == "the_token"
34
- end
35
-
36
- it "returns an object that has the store_id" do
37
- subject.access_token("code").store_id.should == "12345"
38
- end
39
- end
1
+ require 'spec_helper'
2
+
3
+ describe EcwidApi::OAuth do
4
+ subject do
5
+ EcwidApi::OAuth.new do |config|
6
+ config.client_id = "client_id"
7
+ config.client_secret = "client_secret"
8
+ config.scope = "scope"
9
+ config.redirect_uri = "https://example.com/oauth"
10
+ end
11
+ end
12
+
13
+ its(:oauth_url) { should == "https://my.ecwid.com/api/oauth/authorize?client_id=client_id&scope=scope&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Foauth" }
14
+
15
+ describe "#access_token(code)" do
16
+ let(:response) do
17
+ double("response").tap do |response|
18
+ allow(response).to receive(:success?).and_return(true)
19
+ allow(response).to receive(:body).and_return(access_token: "the_token", store_id: "12345")
20
+ end
21
+ end
22
+
23
+ before(:each) do
24
+ allow(subject.send(:connection)).to receive(:post).with("/api/oauth/token", hash_including(code: "code")).and_return(response)
25
+ end
26
+
27
+ it "sends a request to the API for an access_token" do
28
+ expect(subject.send(:connection)).to receive(:post).with("/api/oauth/token", hash_including(code: "code")).and_return(response)
29
+ subject.access_token("code")
30
+ end
31
+
32
+ it "returns an object that has the access_token" do
33
+ subject.access_token("code").access_token.should == "the_token"
34
+ end
35
+
36
+ it "returns an object that has the store_id" do
37
+ subject.access_token("code").store_id.should == "12345"
38
+ end
39
+ end
40
40
  end