ecwid_gateway 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,12 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in ecwid_gateway.gemspec
4
4
  gemspec
5
5
 
6
- gem 'weary'
7
-
8
- group :development, :test do
9
- gem 'webmock'
10
- gem 'json'
11
- gem 'minitest'
12
- gem 'turn'
13
- gem 'tconsole'
14
- end
6
+ gem 'rake'
7
+ gem 'minitest'
8
+ gem 'webmock', :require => 'webmock/minitest'
9
+ gem 'tconsole'
10
+ gem 'turn'
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # EcwidGateway
2
2
 
3
- TODO: Write a gem description
3
+ [![Build Status](https://secure.travis-ci.org/zzet/ecwid_gateway.png)](http://travis-ci.org/zzet/ecwid_gateway)
4
+
5
+ Gem for work with Ecwid store API
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,7 +20,32 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ ### Configuration
24
+
25
+ # Add config/initializers/ecwid_gateway.rb
26
+ EcwidGateway.configure do |conig|
27
+ conig.store_id = 'your_store_id'
28
+ conig.api_domain = 'http://app.ecwid.com'
29
+ conig.order_secure_auth_key = 'your_order_secure_auth_key'
30
+ conig.sso_secure_auth_key = 'your_sso_secure_auth_key'
31
+ end
32
+
33
+ ### Usage
34
+
35
+ client = EcwidGateway::Client.new
36
+
37
+ client.get_categories # Return root category list
38
+
39
+ client.get_categories(parent_category_id)
40
+
41
+ client.get_products(category_id)
42
+
43
+ client.get_product(product_id)
44
+
45
+ client.get_random_products(count)
46
+
47
+ client.get_profile
48
+
22
49
 
23
50
  ## Contributing
24
51
 
data/Rakefile CHANGED
@@ -1,4 +1,11 @@
1
- #!/usr/bin/env rake
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
4
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/lib/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
+ $:.push File.expand_path('../lib', __FILE__)
4
3
  require 'ecwid_gateway/version'
5
4
 
6
5
  Gem::Specification.new do |gem|
@@ -9,13 +8,16 @@ Gem::Specification.new do |gem|
9
8
  gem.authors = ["Andrey Kumanyaev"]
10
9
  gem.email = ["me@zzet.org"]
11
10
  gem.description = %q{Ecwid API wrapper}
12
- gem.summary = %q{Some summary}
11
+ gem.summary = %q{Ecwid API wrapper}
13
12
  gem.homepage = ""
14
13
 
15
- gem.add_dependency 'weary'
14
+ gem.rubyforge_project = "ecwid_gateway"
16
15
 
17
- gem.files = `git ls-files`.split($/)
16
+ gem.files = `git ls-files`.split("\n")
18
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
19
  gem.require_paths = ["lib"]
20
+
21
+ gem.add_runtime_dependency 'weary'
22
+ gem.add_runtime_dependency 'json'
21
23
  end
@@ -1,4 +1,5 @@
1
1
  require "weary/client"
2
+ require "json"
2
3
 
3
4
  module EcwidGateway
4
5
  class Client < Weary::Client
@@ -66,27 +67,27 @@ module EcwidGateway
66
67
 
67
68
  def get_categories(category = 0)
68
69
  request = categories_request({:store_id => @store_id, :parent => category}).perform
69
- request.body
70
+ JSON.parse(request.body)
70
71
  end
71
72
 
72
73
  def get_products(category)
73
74
  request = products_request({:store_id => @store_id, :category => category}).perform
74
- request.body
75
+ JSON.parse(request.body)
75
76
  end
76
77
 
77
78
  def get_product(product)
78
79
  request = product_request({:store_id => @store_id, :id => product}).perform
79
- request.body
80
+ JSON.parse(request.body)
80
81
  end
81
82
 
82
83
  def get_random_products(count)
83
84
  request = random_products_request({:store_id => @store_id, :count => count}).perform
84
- request.body
85
+ JSON.parse(request.body)
85
86
  end
86
87
 
87
88
  def get_profile
88
89
  request = profile_request({:store_id => @store_id}).perform
89
- request.body
90
+ JSON.parse(request.body)
90
91
  end
91
92
 
92
93
  end
@@ -1,3 +1,3 @@
1
1
  module EcwidGateway
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,37 @@
1
+ [
2
+ {
3
+ "id": 15320780,
4
+ "sku": "00091",
5
+ "name": "Name_1",
6
+ "price": 0.0,
7
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320780"
8
+ },
9
+ {
10
+ "id": 15320781,
11
+ "sku": "00092",
12
+ "name": "Name_2",
13
+ "price": 0.0,
14
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320781"
15
+ },
16
+ {
17
+ "id": 15320782,
18
+ "sku": "00093",
19
+ "name": "Name_3",
20
+ "price": 0.0,
21
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320782"
22
+ },
23
+ {
24
+ "id": 15320783,
25
+ "sku": "00094",
26
+ "name": "Name_4",
27
+ "price": 0.0,
28
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320783"
29
+ },
30
+ {
31
+ "id": 15320784,
32
+ "sku": "00095",
33
+ "name": "Name_5",
34
+ "price": 0.0,
35
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320784"
36
+ }
37
+ ]
@@ -0,0 +1,46 @@
1
+ {
2
+ "id": 123,
3
+ "sku": "00091",
4
+ "name": "Name_1",
5
+ "price": 0.0,
6
+ "wholesalePrices": {},
7
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320780",
8
+ "description": "",
9
+ "options": [
10
+ {
11
+ "name": "pre-packing",
12
+ "type": "SELECT",
13
+ "choices": [
14
+ {
15
+ "text": "a box of 60 sticks",
16
+ "priceModifierType": "ABSOLUTE",
17
+ "priceModifier": 32.0
18
+ }
19
+ ],
20
+ "defaultChoice": 0,
21
+ "required": false
22
+ }
23
+ ],
24
+ "taxes": [],
25
+ "galleryImages": [],
26
+ "categories": [
27
+ {
28
+ "id": 3597823,
29
+ "parentId": 3597822,
30
+ "name": "Category",
31
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597823",
32
+ "defaultCategory": true
33
+ },
34
+ {
35
+ "id": 3597833,
36
+ "parentId": 3597826,
37
+ "name": "Subcategory",
38
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597833",
39
+ "defaultCategory": false
40
+ }
41
+ ],
42
+ "dateAdded": 1347957072,
43
+ "created": "2012-09-18 03:31:12",
44
+ "productClass": "Общий",
45
+ "extraFields": []
46
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "storeName": "Example store",
3
+ "storeUrl": "http://example.com/estore",
4
+ "mobileUrl": "http://app.ecwid.com/jsp/123456/catalog",
5
+ "weightUnit": "POUND",
6
+ "currency": "GBP",
7
+ "currencyPrefix": "£",
8
+ "currencySuffix": "",
9
+ "groupSeparator": " ",
10
+ "decimalSeparator": ".",
11
+ "numericPrecision": 2,
12
+ "closed": false
13
+ }
@@ -0,0 +1,72 @@
1
+ [
2
+ {
3
+ "id": 15320715,
4
+ "sku": "00026",
5
+ "name": "Name_1",
6
+ "price": 0.0,
7
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320715"
8
+ },
9
+ {
10
+ "id": 15320763,
11
+ "sku": "00074",
12
+ "name": "Name_2",
13
+ "price": 0.0,
14
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320763"
15
+ },
16
+ {
17
+ "id": 15320736,
18
+ "sku": "00047",
19
+ "name": "Name_3",
20
+ "price": 0.0,
21
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320736"
22
+ },
23
+ {
24
+ "id": 15320764,
25
+ "sku": "00075",
26
+ "name": "Name_4",
27
+ "price": 0.0,
28
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320764"
29
+ },
30
+ {
31
+ "id": 15320771,
32
+ "sku": "00082",
33
+ "name": "Name_5",
34
+ "price": 0.0,
35
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320771"
36
+ },
37
+ {
38
+ "id": 15320690,
39
+ "sku": "00001",
40
+ "name": "Name_6",
41
+ "price": 0.0,
42
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320690"
43
+ },
44
+ {
45
+ "id": 15320737,
46
+ "sku": "00048",
47
+ "name": "Name_7",
48
+ "price": 0.0,
49
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320737"
50
+ },
51
+ {
52
+ "id": 15320755,
53
+ "sku": "00066",
54
+ "name": "Name_8",
55
+ "price": 0.0,
56
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320755"
57
+ },
58
+ {
59
+ "id": 15320719,
60
+ "sku": "00030",
61
+ "name": "Name_9",
62
+ "price": 0.0,
63
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320719"
64
+ },
65
+ {
66
+ "id": 15320700,
67
+ "sku": "00011",
68
+ "name": "Name_10",
69
+ "price": 0.0,
70
+ "url": "http://example.com/estore#ecwid:mode=product&product=15320700"
71
+ }
72
+ ]
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "id": 3597822,
4
+ "name": "Type",
5
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597822"
6
+ },
7
+ {
8
+ "id": 3597826,
9
+ "name": "Brands",
10
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597826"
11
+ },
12
+ {
13
+ "id": 3597845,
14
+ "name": "Component",
15
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597845"
16
+ }
17
+ ]
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "id": 3597830,
4
+ "name": "Type_1",
5
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597830"
6
+ },
7
+ {
8
+ "id": 3597831,
9
+ "name": "Type_2",
10
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597831"
11
+ },
12
+ {
13
+ "id": 3597832,
14
+ "name": "Type_3",
15
+ "url": "http://example.com/estore#ecwid:mode=category&category=3597832"
16
+ }
17
+ ]
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+
3
+ class EcwidGatewayTest < TestCase
4
+ def setup
5
+ EcwidGateway.configure do |conig|
6
+ conig.store_id = '123456'
7
+ conig.api_domain = 'http://localhost'
8
+ conig.order_secure_auth_key = 'some_key'
9
+ conig.sso_secure_auth_key = 'sso_key'
10
+ end
11
+
12
+ @client = EcwidGateway::Client.new
13
+ @domain = EcwidGateway.options[:api_domain]
14
+ @store_id = EcwidGateway.options[:store_id]
15
+ end
16
+
17
+ def test_lookup_http_query
18
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/categories?parent=0").
19
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
20
+ to_return(:status => 200, :body => load_fixture('root_categories.json'), :headers => {})
21
+
22
+ @client.get_categories
23
+
24
+ assert_requested @stub
25
+ end
26
+
27
+ def test_get_root_categories
28
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/categories?parent=0").
29
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
30
+ to_return(:status => 200, :body => load_fixture('root_categories.json'), :headers => {})
31
+
32
+ categories = @client.get_categories
33
+
34
+ assert_equal 3, categories.count
35
+
36
+ first_category = categories[0]
37
+ assert_equal "Type", first_category["name"]
38
+ end
39
+
40
+ def test_get_category_subcategories
41
+ category = 123
42
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/categories?parent=#{category}").
43
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
44
+ to_return(:status => 200, :body => load_fixture('type_category_subcategories.json'), :headers => {})
45
+
46
+ categories = @client.get_categories(category)
47
+
48
+ assert_equal 3, categories.count
49
+
50
+ first_category = categories[0]
51
+ assert_equal "Type_1", first_category["name"]
52
+ end
53
+
54
+
55
+ def test_get_category_products
56
+ category = 123
57
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/products?category=#{category}").
58
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
59
+ to_return(:status => 200, :body => load_fixture('category_products.json'), :headers => {})
60
+
61
+ products = @client.get_products(category)
62
+
63
+ assert_equal 5, products.count
64
+
65
+ first_product = products[0]
66
+ assert_equal "Name_1", first_product["name"]
67
+ end
68
+
69
+
70
+ def test_get_product
71
+ product = 123
72
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/product?id=#{product}").
73
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
74
+ to_return(:status => 200, :body => load_fixture('product.json'), :headers => {})
75
+
76
+ product_info = @client.get_product(product)
77
+
78
+ assert_equal 15, product_info.count
79
+
80
+ assert_equal "Name_1", product_info["name"]
81
+ end
82
+
83
+
84
+ def test_get_ranmod_product
85
+ count = 10
86
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/random_products?count=#{count}").
87
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
88
+ to_return(:status => 200, :body => load_fixture('random_products.json'), :headers => {})
89
+
90
+ random_products = @client.get_random_products(count)
91
+
92
+ assert_equal 10, random_products.count
93
+
94
+ product_info = random_products[0]
95
+
96
+ assert_equal "Name_1", product_info["name"]
97
+ end
98
+
99
+ def test_get_profile
100
+ @stub = stub_request(:get, "#{@domain}/api/v1/#{@store_id}/profile").
101
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
102
+ to_return(:status => 200, :body => load_fixture('profile.json'), :headers => {})
103
+
104
+ profile = @client.get_profile
105
+
106
+ assert_equal 11, profile.count
107
+
108
+ assert_equal "Example store", profile["storeName"]
109
+ end
110
+
111
+ end
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+ MiniTest::Unit.autorun
5
+
6
+ class TestCase < MiniTest::Unit::TestCase
7
+ def load_fixture(filename)
8
+ File.read(File.dirname(__FILE__) + "/fixtures/#{filename}")
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecwid_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-25 00:00:00.000000000 Z
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: weary
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Ecwid API wrapper
31
47
  email:
32
48
  - me@zzet.org
@@ -45,6 +61,14 @@ files:
45
61
  - lib/ecwid_gateway/client.rb
46
62
  - lib/ecwid_gateway/config.rb
47
63
  - lib/ecwid_gateway/version.rb
64
+ - test/fixtures/category_products.json
65
+ - test/fixtures/product.json
66
+ - test/fixtures/profile.json
67
+ - test/fixtures/random_products.json
68
+ - test/fixtures/root_categories.json
69
+ - test/fixtures/type_category_subcategories.json
70
+ - test/lib/ecwid_gateway_test.rb
71
+ - test/test_helper.rb
48
72
  homepage: ''
49
73
  licenses: []
50
74
  post_install_message:
@@ -64,9 +88,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
88
  - !ruby/object:Gem::Version
65
89
  version: '0'
66
90
  requirements: []
67
- rubyforge_project:
91
+ rubyforge_project: ecwid_gateway
68
92
  rubygems_version: 1.8.24
69
93
  signing_key:
70
94
  specification_version: 3
71
- summary: Some summary
72
- test_files: []
95
+ summary: Ecwid API wrapper
96
+ test_files:
97
+ - test/fixtures/category_products.json
98
+ - test/fixtures/product.json
99
+ - test/fixtures/profile.json
100
+ - test/fixtures/random_products.json
101
+ - test/fixtures/root_categories.json
102
+ - test/fixtures/type_category_subcategories.json
103
+ - test/lib/ecwid_gateway_test.rb
104
+ - test/test_helper.rb