api2cart-ruby 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8ab8789095578d475cb638aacf6de3673d879716
4
- data.tar.gz: 9e86285773bf57ac40fd5976a39bcac6ffb3d5c3
2
+ SHA256:
3
+ metadata.gz: 4a08156ad7729b1456d299cb9fa179585b814e17f46057591b8673ed631d3a14
4
+ data.tar.gz: '014182fa2ff104f8769ae6ab56d4477b79dbba44d80d9e763d44008955d0c5eb'
5
5
  SHA512:
6
- metadata.gz: 821124ef0dbbf9b7a18c6576231001f66dc8008ca631792cdaeb7ed230ecc93e5dfa0a111874a17e93565a39da0d76e311e9f5bf55f92227f37df542c03eee17
7
- data.tar.gz: d56756525e4a7824f6b1657e2dd980527ea81cd508819dbb20ccc668882dac9b3e30b1487a0ec3c096c95ce6e42d8b20e87015811b135c0df2fffeeb4a29bb01
6
+ metadata.gz: a760348de57240677f0d3dfe611758b2f28f50c6dfcdd396f9d02ea79f31d62717fd45eed415250da6ebebd84972bcba85cebded10afe712b29378b13b88940d
7
+ data.tar.gz: 668218a34749339c873dd723e2950ff8852c51df060aea12215b661679ebec84fa04b49b41137f1a36ea427ca428c16fce371d953b8a471f83e7367f2f4907a1
data/.gitignore CHANGED
@@ -41,3 +41,5 @@ build/
41
41
  *.a
42
42
  mkmf.log
43
43
  /eproject.cfg
44
+
45
+ .DS_Store
data/README.md CHANGED
@@ -32,6 +32,15 @@ Api2cart::Store.new(api_key, store_key, proxy: 'http://anti-throttling-proxy.loc
32
32
  # => { 'products_count' => 76 }
33
33
  ```
34
34
 
35
+ ## Configuration
36
+
37
+ ```ruby
38
+ Api2cart.configure do |c|
39
+ c.host = 'custom.example.com' # default is 'api.api2cart.com'
40
+ c.api_version = '1.1' # default is '1.0'
41
+ end
42
+ ```
43
+
35
44
  ## Contributors
36
45
 
37
46
  * [Anton Pershakov](https://github.com/main24)
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_dependency "activesupport"
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
27
27
  spec.add_development_dependency "vcr"
28
28
  spec.add_development_dependency "webmock"
data/lib/api2cart.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'active_support/configurable'
2
+
1
3
  require 'api2cart/request_url_composer'
2
4
  require 'api2cart/client'
3
5
  require 'api2cart/store'
@@ -5,4 +7,13 @@ require 'api2cart/errors'
5
7
  require 'api2cart/error_class_recognizer'
6
8
 
7
9
  module Api2cart
10
+ include ActiveSupport::Configurable
11
+
12
+ config_accessor :host,
13
+ :api_version
14
+
15
+ self.configure do |config|
16
+ config.host = 'api.api2cart.com'
17
+ config.api_version = '1.0'
18
+ end
8
19
  end
@@ -4,7 +4,7 @@ require 'active_support/core_ext/object/blank'
4
4
 
5
5
  module Api2cart
6
6
  class Client < Struct.new(:request_url, :proxy_url)
7
- READ_TIMEOUT = 2000
7
+ READ_TIMEOUT = 999999
8
8
 
9
9
  def make_request!
10
10
  self.response_body = net_http.get(request_url.request_uri).body
@@ -1,23 +1,26 @@
1
1
  require 'uri'
2
2
  require 'active_support/core_ext/object/to_query'
3
+ require 'active_support/core_ext/module/delegation'
3
4
 
4
5
  module Api2cart
5
6
  class RequestUrlComposer < Struct.new(:api_key, :store_key, :method_name, :query_params)
6
- HOST = 'api.api2cart.com'
7
- PATH_BASE = '/v1.0'
7
+
8
+ delegate :host,
9
+ :api_version,
10
+ to: :Api2cart
8
11
 
9
12
  def compose_request_url
10
- URI::HTTP.build host: HOST, path: full_path, query: query_string
13
+ URI::HTTP.build host: host, path: full_path, query: query_string
11
14
  end
12
15
 
13
16
  protected
14
17
 
15
18
  def full_path
16
- "#{PATH_BASE}/#{dotted_method_name}.json"
19
+ "/v#{api_version}/#{dotted_method_name}.json"
17
20
  end
18
21
 
19
22
  def dotted_method_name
20
- method_name.to_s.gsub('_', '.')
23
+ method_name.to_s.gsub('__', '-').gsub('_', '.').gsub('-', '_')
21
24
  end
22
25
 
23
26
  def query_string
@@ -1,3 +1,3 @@
1
1
  module Api2cart
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -1,56 +1,120 @@
1
1
  describe Api2cart::Client do
2
2
  let(:api2cart_client) { Api2cart::Client.new(request_url) }
3
3
 
4
- before { api2cart_client.make_request! }
4
+ context 'when API version is default' do
5
+ before { api2cart_client.make_request! }
5
6
 
6
- context 'when request is successful', vcr: { cassette_name: 'successful_request' } do
7
- let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
8
- let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
7
+ context 'when request is successful', vcr: { cassette_name: 'v1_0/successful_request' } do
8
+ let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
9
+ let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
9
10
 
10
- let(:request_url) { Api2cart::RequestUrlComposer.new(api_key, store_key, :product_count).compose_request_url }
11
+ let(:request_url) { Api2cart::RequestUrlComposer.new(api_key, store_key, :product_count).compose_request_url }
11
12
 
12
- describe '#successful?' do
13
- subject { api2cart_client.successful? }
13
+ describe '#successful?' do
14
+ subject { api2cart_client.successful? }
14
15
 
15
- it { is_expected.to be true }
16
- end
16
+ it { is_expected.to be true }
17
+ end
18
+
19
+ describe '#error_message' do
20
+ subject { api2cart_client.error_message }
21
+
22
+ it { is_expected.to eq '' }
23
+ end
17
24
 
18
- describe '#error_message' do
19
- subject { api2cart_client.error_message }
25
+ describe '#result' do
26
+ subject { api2cart_client.result }
20
27
 
21
- it { is_expected.to eq '' }
28
+ it 'returns result as parsed JSON' do
29
+ expect(subject).to eq({ "products_count" => 76 })
30
+ end
31
+ end
22
32
  end
23
33
 
24
- describe '#result' do
25
- subject { api2cart_client.result }
34
+ context 'when request is erroneous', vcr: { cassette_name: 'v1_0/erroneous_request' } do
35
+ let(:request_url) { Api2cart::RequestUrlComposer.new('wrong', 'even more wrong', :product_count).compose_request_url }
36
+
37
+ describe '#successful?' do
38
+ subject { api2cart_client.successful? }
39
+
40
+ it { is_expected.to be false }
41
+ end
42
+
43
+ describe '#error_message' do
44
+ subject { api2cart_client.error_message }
45
+
46
+ it 'parses request and extracts error message' do
47
+ expect(subject).to eq 'Incorrect API Key'
48
+ end
49
+ end
26
50
 
27
- it 'returns result as parsed JSON' do
28
- expect(subject).to eq({ "products_count" => 76 })
51
+ describe '#result' do
52
+ subject { api2cart_client.result }
53
+
54
+ it { is_expected.to eq({}) }
29
55
  end
30
56
  end
31
57
  end
32
58
 
33
- context 'when request is erroneous', vcr: { cassette_name: 'erroneous_request' } do
34
- let(:request_url) { Api2cart::RequestUrlComposer.new('wrong', 'even more wrong', :product_count).compose_request_url }
35
-
36
- describe '#successful?' do
37
- subject { api2cart_client.successful? }
59
+ context 'when API version is configured' do
60
+ let!(:current_api_version) { Api2cart.api_version }
38
61
 
39
- it { is_expected.to be false }
62
+ before do
63
+ Api2cart.configure{ |config| config.api_version = '1.1' }
64
+ api2cart_client.make_request!
40
65
  end
41
66
 
42
- describe '#error_message' do
43
- subject { api2cart_client.error_message }
67
+ after { Api2cart.configure{ |config| config.api_version = current_api_version } }
68
+
69
+ context 'when request is successful', vcr: { cassette_name: 'v1_1/successful_request' } do
70
+ let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
71
+ let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
72
+
73
+ let(:request_url) { Api2cart::RequestUrlComposer.new(api_key, store_key, :product_count).compose_request_url }
44
74
 
45
- it 'parses request and extracts error message' do
46
- expect(subject).to eq 'Incorrect API Key'
75
+ describe '#successful?' do
76
+ subject { api2cart_client.successful? }
77
+
78
+ it { is_expected.to be true }
79
+ end
80
+
81
+ describe '#error_message' do
82
+ subject { api2cart_client.error_message }
83
+
84
+ it { is_expected.to eq '' }
85
+ end
86
+
87
+ describe '#result' do
88
+ subject { api2cart_client.result }
89
+
90
+ it 'returns result as parsed JSON' do
91
+ expect(subject).to eq({ "products_count" => 88 })
92
+ end
47
93
  end
48
94
  end
49
95
 
50
- describe '#result' do
51
- subject { api2cart_client.result }
96
+ context 'when request is erroneous', vcr: { cassette_name: 'v1_1/erroneous_request' } do
97
+ let(:request_url) { Api2cart::RequestUrlComposer.new('wrong', 'even more wrong', :product_count).compose_request_url }
98
+
99
+ describe '#successful?' do
100
+ subject { api2cart_client.successful? }
52
101
 
53
- it { is_expected.to eq({}) }
102
+ it { is_expected.to be false }
103
+ end
104
+
105
+ describe '#error_message' do
106
+ subject { api2cart_client.error_message }
107
+
108
+ it 'parses request and extracts error message' do
109
+ expect(subject).to eq 'Incorrect API Key'
110
+ end
111
+ end
112
+
113
+ describe '#result' do
114
+ subject { api2cart_client.result }
115
+
116
+ it { is_expected.to eq({}) }
117
+ end
54
118
  end
55
119
  end
56
120
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Api2cart do
4
+ describe '#host' do
5
+ context 'when host is not configured' do
6
+ it 'should be equal to default value' do
7
+ expect(Api2cart.host).to eq 'api.api2cart.com'
8
+ end
9
+ end
10
+
11
+ context 'when host is configured' do
12
+ let!(:current_host) { Api2cart.host }
13
+
14
+ before { Api2cart.configure{ |config| config.host = 'host.com' } }
15
+
16
+ it 'should be equal to new host' do
17
+ expect(Api2cart.host).to eq 'host.com'
18
+ end
19
+
20
+ after { Api2cart.configure{ |config| config.host = current_host } }
21
+ end
22
+ end
23
+
24
+ describe '#api_version' do
25
+ context 'when API version is not configured' do
26
+ it 'should be equal to default value' do
27
+ expect(Api2cart.api_version).to eq '1.0'
28
+ end
29
+ end
30
+
31
+ context 'when API version is configured' do
32
+ let!(:current_api_version) { Api2cart.api_version }
33
+
34
+ before { Api2cart.configure{ |config| config.api_version = '1.1' } }
35
+
36
+ it 'should be equal to new api_version' do
37
+ expect(Api2cart.api_version).to eq '1.1'
38
+ end
39
+
40
+ after { Api2cart.configure{ |config| config.api_version = current_api_version } }
41
+ end
42
+ end
43
+ end
@@ -24,24 +24,76 @@ describe Api2cart::RequestUrlComposer do
24
24
  describe 'domain' do
25
25
  subject { composed_url.host }
26
26
 
27
- specify do
28
- expect(subject).to eq('api.api2cart.com')
27
+ context 'when host is default' do
28
+ specify do
29
+ expect(subject).to eq('api.api2cart.com')
30
+ end
31
+ end
32
+
33
+ context 'when host is configured' do
34
+ let!(:current_host) { Api2cart.host }
35
+
36
+ before { Api2cart.configure{ |config| config.host = 'host.com' } }
37
+
38
+ specify do
39
+ expect(subject).to eq('host.com')
40
+ end
41
+
42
+ after { Api2cart.configure{ |config| config.host = current_host } }
29
43
  end
30
44
  end
31
45
 
32
46
  describe 'path' do
33
47
  subject { composed_url.path }
34
48
 
35
- it 'contains API version in the beginning' do
36
- expect(subject).to start_with('/v1.0')
49
+ context 'when API version is default' do
50
+ it 'contains API version in the beginning' do
51
+ expect(subject).to start_with('/v1.0')
52
+ end
53
+
54
+ it 'contains method name translating underscores to dots' do
55
+ expect(subject).to start_with('/v1.0/order.list')
56
+ end
57
+
58
+ it 'contains indicator of JSON format' do
59
+ expect(subject).to start_with('/v1.0/order.list.json')
60
+ end
61
+
62
+ context 'when method name contains doubled underscores' do
63
+ let(:method_name) { :product_child__item_list }
64
+
65
+ it 'converts doubled underscores to single' do
66
+ expect(subject).to start_with('/v1.0/product.child_item.list')
67
+ end
68
+ end
37
69
  end
38
70
 
39
- it 'contains method name translating underscores to dots' do
40
- expect(subject).to start_with('/v1.0/order.list')
41
- end
71
+ context 'when API version is configured' do
72
+ let!(:current_api_version) { Api2cart.api_version }
73
+
74
+ before { Api2cart.configure{ |config| config.api_version = '1.1' } }
75
+
76
+ it 'contains API version in the beginning' do
77
+ expect(subject).to start_with('/v1.1')
78
+ end
79
+
80
+ it 'contains method name translating underscores to dots' do
81
+ expect(subject).to start_with('/v1.1/order.list')
82
+ end
83
+
84
+ it 'contains indicator of JSON format' do
85
+ expect(subject).to start_with('/v1.1/order.list.json')
86
+ end
42
87
 
43
- it 'contains indicator of JSON format' do
44
- expect(subject).to start_with('/v1.0/order.list.json')
88
+ context 'when method name contains doubled underscores' do
89
+ let(:method_name) { :product_child__item_list }
90
+
91
+ it 'converts doubled underscores to single' do
92
+ expect(subject).to start_with('/v1.1/product.child_item.list')
93
+ end
94
+ end
95
+
96
+ after { Api2cart.configure{ |config| config.api_version = current_api_version } }
45
97
  end
46
98
  end
47
99
 
@@ -64,8 +116,34 @@ describe Api2cart::RequestUrlComposer do
64
116
  describe 'all together' do
65
117
  subject { composed_url.to_s }
66
118
 
67
- it do
68
- is_expected.to eq 'http://api.api2cart.com/v1.0/order.list.json?api_key=43ba7043badfa2cd31cfaf5dc601a884&count=10&params=force_all&start=20&store_key=6f00bbf49f5ada8156506aba161408c6'
119
+ context 'when host is default' do
120
+ it do
121
+ is_expected.to eq 'http://api.api2cart.com/v1.0/order.list.json?api_key=43ba7043badfa2cd31cfaf5dc601a884&count=10&params=force_all&start=20&store_key=6f00bbf49f5ada8156506aba161408c6'
122
+ end
123
+ end
124
+
125
+ context 'when host is configured' do
126
+ let!(:current_host) { Api2cart.host }
127
+
128
+ before { Api2cart.configure{ |config| config.host = 'host.com' } }
129
+
130
+ it do
131
+ is_expected.to eq 'http://host.com/v1.0/order.list.json?api_key=43ba7043badfa2cd31cfaf5dc601a884&count=10&params=force_all&start=20&store_key=6f00bbf49f5ada8156506aba161408c6'
132
+ end
133
+
134
+ after { Api2cart.configure{ |config| config.host = current_host } }
135
+ end
136
+
137
+ context 'when API version is configured' do
138
+ let!(:current_api_version) { Api2cart.api_version }
139
+
140
+ before { Api2cart.configure{ |config| config.api_version = '1.1' } }
141
+
142
+ it do
143
+ is_expected.to eq 'http://api.api2cart.com/v1.1/order.list.json?api_key=43ba7043badfa2cd31cfaf5dc601a884&count=10&params=force_all&start=20&store_key=6f00bbf49f5ada8156506aba161408c6'
144
+ end
145
+
146
+ after { Api2cart.configure{ |config| config.api_version = current_api_version } }
69
147
  end
70
148
  end
71
149
 
@@ -1,40 +1,87 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Api2cart::Store do
4
- context 'when request is successful', vcr: { cassette_name: 'successful_request' } do
5
- let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
6
- let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
4
+ context 'when API version is default' do
5
+ context 'when request is successful', vcr: { cassette_name: 'v1_0/successful_request' } do
6
+ let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
7
+ let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
7
8
 
8
- it 'returns parsed JSON' do
9
- expect(Api2cart::Store.new(api_key, store_key).product_count).to eq({ 'products_count' => 76 })
9
+ it 'returns parsed JSON' do
10
+ expect(Api2cart::Store.new(api_key, store_key).product_count).to eq({ 'products_count' => 76 })
11
+ end
10
12
  end
11
- end
12
13
 
13
- context 'when response contains an error', vcr: { cassette_name: 'erroneous_request' } do
14
- context 'specific case' do
15
- it 'raises an exception with correspondent message' do
16
- expect {
17
- Api2cart::Store.new('wrong', 'even more wrong').product_count
18
- }.to raise_error(Api2cart::Errors::IncorrectApiKey, 'Incorrect API Key')
14
+ context 'when response contains an error', vcr: { cassette_name: 'v1_0/erroneous_request' } do
15
+ context 'specific case' do
16
+ it 'raises an exception with correspondent message' do
17
+ expect {
18
+ Api2cart::Store.new('wrong', 'even more wrong').product_count
19
+ }.to raise_error(Api2cart::Errors::IncorrectApiKey, 'Incorrect API Key')
20
+ end
21
+ end
22
+
23
+ context 'general case' do
24
+ let(:api2cart_store) { Api2cart::Store.new('wrong', 'even more wrong') }
25
+ let(:error_class) { double }
26
+
27
+ subject{ api2cart_store.product_count }
28
+
29
+ before do
30
+ allow_any_instance_of(Api2cart::Client).to receive(:return_code).and_return('9')
31
+ allow_any_instance_of(Api2cart::Client).to receive(:error_message).and_return('Something went wrong')
32
+ allow(Api2cart::ErrorClassRecognizer).to receive(:call).with('9').and_return(error_class)
33
+ end
34
+
35
+ it 'should call for ErrorClassRecognizer' do
36
+ expect_any_instance_of(Kernel).to receive(:raise).with(error_class, 'Something went wrong')
37
+
38
+ subject
39
+ end
19
40
  end
20
41
  end
42
+ end
43
+
44
+ context 'when API version is configured' do
45
+ let!(:current_api_version) { Api2cart.api_version }
21
46
 
22
- context 'general case' do
23
- let(:api2cart_store) { Api2cart::Store.new('wrong', 'even more wrong') }
24
- let(:error_class) { double }
47
+ before { Api2cart.configure{ |config| config.api_version = '1.1' } }
48
+ after { Api2cart.configure{ |config| config.api_version = current_api_version } }
25
49
 
26
- subject{ api2cart_store.product_count }
50
+ context 'when request is successful', vcr: { cassette_name: 'v1_1/successful_request' } do
51
+ let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
52
+ let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
53
+
54
+ it 'returns parsed JSON' do
55
+ expect(Api2cart::Store.new(api_key, store_key).product_count).to eq({ 'products_count' => 88 })
56
+ end
57
+ end
27
58
 
28
- before do
29
- allow_any_instance_of(Api2cart::Client).to receive(:return_code).and_return('9')
30
- allow_any_instance_of(Api2cart::Client).to receive(:error_message).and_return('Something went wrong')
31
- allow(Api2cart::ErrorClassRecognizer).to receive(:call).with('9').and_return(error_class)
59
+ context 'when response contains an error', vcr: { cassette_name: 'v1_1/erroneous_request' } do
60
+ context 'specific case' do
61
+ it 'raises an exception with correspondent message' do
62
+ expect {
63
+ Api2cart::Store.new('wrong', 'even more wrong').product_count
64
+ }.to raise_error(Api2cart::Errors::IncorrectApiKey, 'Incorrect API Key')
65
+ end
32
66
  end
33
67
 
34
- it 'should call for ErrorClassRecognizer' do
35
- expect_any_instance_of(Kernel).to receive(:raise).with(error_class, 'Something went wrong')
68
+ context 'general case' do
69
+ let(:api2cart_store) { Api2cart::Store.new('wrong', 'even more wrong') }
70
+ let(:error_class) { double }
71
+
72
+ subject{ api2cart_store.product_count }
73
+
74
+ before do
75
+ allow_any_instance_of(Api2cart::Client).to receive(:return_code).and_return('9')
76
+ allow_any_instance_of(Api2cart::Client).to receive(:error_message).and_return('Something went wrong')
77
+ allow(Api2cart::ErrorClassRecognizer).to receive(:call).with('9').and_return(error_class)
78
+ end
79
+
80
+ it 'should call for ErrorClassRecognizer' do
81
+ expect_any_instance_of(Kernel).to receive(:raise).with(error_class, 'Something went wrong')
36
82
 
37
- subject
83
+ subject
84
+ end
38
85
  end
39
86
  end
40
87
  end
@@ -1,19 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Api2cart do
4
- context 'when proxy URL is given', vcr: { cassette_name: 'successful_request' } do
5
- let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
6
- let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
4
+ context 'when API version is default' do
5
+ context 'when proxy URL is given', vcr: { cassette_name: 'v1_0/successful_request' } do
6
+ let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
7
+ let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
7
8
 
8
- let(:store_with_proxy) { Api2cart::Store.new api_key, store_key, proxy: 'http://anti-throttling-proxy.local:1080' }
9
+ let(:store_with_proxy) { Api2cart::Store.new api_key, store_key, proxy: 'http://anti-throttling-proxy.local:1080' }
9
10
 
10
- it 'sends request via proxy (see cassette)' do
11
- expect(store_with_proxy.product_count).to eq({ 'products_count' => 76 })
11
+ it 'sends request via proxy (see cassette)' do
12
+ expect(store_with_proxy.product_count).to eq({ 'products_count' => 76 })
13
+ end
14
+
15
+ it 'extracts hostname and port from proxy URL' do
16
+ expect(Net::HTTP).to receive(:new).with('api.api2cart.com', 80, 'anti-throttling-proxy.local', 1080).and_call_original
17
+ store_with_proxy.product_count
18
+ end
12
19
  end
20
+ end
21
+
22
+ context 'when API version is configured' do
23
+
24
+ let!(:current_api_version) { Api2cart.api_version }
25
+
26
+ before { Api2cart.configure{ |config| config.api_version = '1.1' } }
27
+ after { Api2cart.configure{ |config| config.api_version = current_api_version } }
28
+
29
+ context 'when proxy URL is given', vcr: { cassette_name: 'v1_1/successful_request' } do
30
+ let(:api_key) { '43ba7043badfa2cd31cfaf5dc601a884' }
31
+ let(:store_key) { '6f00bbf49f5ada8156506aba161408c6' }
32
+
33
+ let(:store_with_proxy) { Api2cart::Store.new api_key, store_key, proxy: 'http://anti-throttling-proxy.local:1080' }
34
+
35
+ it 'sends request via proxy (see cassette)' do
36
+ expect(store_with_proxy.product_count).to eq({ 'products_count' => 88 })
37
+ end
13
38
 
14
- it 'extracts hostname and port from proxy URL' do
15
- expect(Net::HTTP).to receive(:new).with('api.api2cart.com', 80, 'anti-throttling-proxy.local', 1080).and_call_original
16
- store_with_proxy.product_count
39
+ it 'extracts hostname and port from proxy URL' do
40
+ expect(Net::HTTP).to receive(:new).with('api.api2cart.com', 80, 'anti-throttling-proxy.local', 1080).and_call_original
41
+ store_with_proxy.product_count
42
+ end
17
43
  end
18
44
  end
19
45
  end
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.api2cart.com/v1.1/product.count.json?api_key=wrong&store_key=even%20more%20wrong
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Tue, 09 Jan 2018 17:36:42 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Powered-By:
32
+ - PHP/7.0.22
33
+ Set-Cookie:
34
+ - PHPSESSID=jn45hst5rmj1bl5m9th6f6e2k6; path=/
35
+ Expires:
36
+ - Thu, 19 Nov 1981 08:52:00 GMT
37
+ Cache-Control:
38
+ - no-store, no-cache, must-revalidate
39
+ Pragma:
40
+ - no-cache
41
+ body:
42
+ encoding: ASCII-8BIT
43
+ string: '{"return_code" : 2, "return_message": "Incorrect API Key", "result"
44
+ : {}}'
45
+ http_version:
46
+ recorded_at: Tue, 09 Jan 2018 17:36:41 GMT
47
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.api2cart.com/v1.1/product.count.json?api_key=43ba7043badfa2cd31cfaf5dc601a884&store_key=6f00bbf49f5ada8156506aba161408c6
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Tue, 09 Jan 2018 17:36:41 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Powered-By:
32
+ - PHP/7.0.22
33
+ Set-Cookie:
34
+ - PHPSESSID=lmqe0ihr21p0flkb5lng7qbns1; path=/
35
+ Expires:
36
+ - Thu, 19 Nov 1981 08:52:00 GMT
37
+ Cache-Control:
38
+ - no-store, no-cache, must-revalidate
39
+ Pragma:
40
+ - no-cache
41
+ body:
42
+ encoding: ASCII-8BIT
43
+ string: '{"return_code" : 0, "return_message": "", "result" : {"products_count":88}}'
44
+ http_version:
45
+ recorded_at: Tue, 09 Jan 2018 17:36:41 GMT
46
+ recorded_with: VCR 4.0.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api2cart-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Pershakov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-27 00:00:00.000000000 Z
13
+ date: 2021-07-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -30,30 +30,30 @@ dependencies:
30
30
  name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: '1.7'
35
+ version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: '1.7'
42
+ version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '10.0'
49
+ version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '10.0'
56
+ version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rspec
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ files:
119
119
  - lib/api2cart/store.rb
120
120
  - lib/api2cart/version.rb
121
121
  - spec/api2cart/client_spec.rb
122
+ - spec/api2cart/configuration_spec.rb
122
123
  - spec/api2cart/error_class_recognizer_spec.rb
123
124
  - spec/api2cart/errors/api_access_denied_spec.rb
124
125
  - spec/api2cart/errors/api_key_disabled_spec.rb
@@ -150,8 +151,10 @@ files:
150
151
  - spec/api2cart/store_spec.rb
151
152
  - spec/api2cart/with_proxy_spec.rb
152
153
  - spec/spec_helper.rb
153
- - spec/vcr_cassettes/erroneous_request.yml
154
- - spec/vcr_cassettes/successful_request.yml
154
+ - spec/vcr_cassettes/v1_0/erroneous_request.yml
155
+ - spec/vcr_cassettes/v1_0/successful_request.yml
156
+ - spec/vcr_cassettes/v1_1/erroneous_request.yml
157
+ - spec/vcr_cassettes/v1_1/successful_request.yml
155
158
  homepage: https://github.com/DanielVartanov/api2cart-ruby
156
159
  licenses:
157
160
  - MIT
@@ -171,13 +174,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
174
  - !ruby/object:Gem::Version
172
175
  version: '0'
173
176
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.4.4
177
+ rubygems_version: 3.0.9
176
178
  signing_key:
177
179
  specification_version: 4
178
180
  summary: Ruby client for API2Cart
179
181
  test_files:
180
182
  - spec/api2cart/client_spec.rb
183
+ - spec/api2cart/configuration_spec.rb
181
184
  - spec/api2cart/error_class_recognizer_spec.rb
182
185
  - spec/api2cart/errors/api_access_denied_spec.rb
183
186
  - spec/api2cart/errors/api_key_disabled_spec.rb
@@ -209,5 +212,7 @@ test_files:
209
212
  - spec/api2cart/store_spec.rb
210
213
  - spec/api2cart/with_proxy_spec.rb
211
214
  - spec/spec_helper.rb
212
- - spec/vcr_cassettes/erroneous_request.yml
213
- - spec/vcr_cassettes/successful_request.yml
215
+ - spec/vcr_cassettes/v1_0/erroneous_request.yml
216
+ - spec/vcr_cassettes/v1_0/successful_request.yml
217
+ - spec/vcr_cassettes/v1_1/erroneous_request.yml
218
+ - spec/vcr_cassettes/v1_1/successful_request.yml