api2cart-ruby 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api2cart.rb +2 -0
- data/lib/api2cart/client.rb +4 -4
- data/lib/api2cart/error_class_recognizer.rb +40 -0
- data/lib/api2cart/errors.rb +33 -0
- data/lib/api2cart/store.rb +1 -1
- data/lib/api2cart/version.rb +1 -1
- data/spec/api2cart/error_class_recognizer_spec.rb +44 -0
- data/spec/api2cart/errors/api_access_denied_spec.rb +10 -0
- data/spec/api2cart/errors/api_key_disabled_spec.rb +10 -0
- data/spec/api2cart/errors/bridge_not_found_spec.rb +10 -0
- data/spec/api2cart/errors/connection_bridge_response_error_spec.rb +10 -0
- data/spec/api2cart/errors/duplicated_record_in_database_spec.rb +10 -0
- data/spec/api2cart/errors/incorrect_api_key_spec.rb +10 -0
- data/spec/api2cart/errors/incorrect_api_request_spec.rb +10 -0
- data/spec/api2cart/errors/incorrect_ftp_access_spec.rb +10 -0
- data/spec/api2cart/errors/incorrect_ftp_write_permissions_spec.rb +10 -0
- data/spec/api2cart/errors/incorrect_parameters_spec.rb +10 -0
- data/spec/api2cart/errors/incorrect_shopping_cart_id_spec.rb +10 -0
- data/spec/api2cart/errors/internal_service_error_spec.rb +10 -0
- data/spec/api2cart/errors/item_already_exists_spec.rb +10 -0
- data/spec/api2cart/errors/item_not_found_spec.rb +10 -0
- data/spec/api2cart/errors/method_name_missing_spec.rb +10 -0
- data/spec/api2cart/errors/required_parameter_missing_spec.rb +10 -0
- data/spec/api2cart/errors/search_parameter_missing_spec.rb +10 -0
- data/spec/api2cart/errors/service_not_available_spec.rb +10 -0
- data/spec/api2cart/errors/store_access_denied_spec.rb +10 -0
- data/spec/api2cart/errors/store_already_exists_spec.rb +10 -0
- data/spec/api2cart/errors/store_not_found_spec.rb +10 -0
- data/spec/api2cart/errors/store_url_unreachable_spec.rb +10 -0
- data/spec/api2cart/errors/too_many_prefixes_spec.rb +10 -0
- data/spec/api2cart/errors/too_many_requests_spec.rb +10 -0
- data/spec/api2cart/errors/update_item_id_missing_spec.rb +10 -0
- data/spec/api2cart/errors/update_parameters_missing_spec.rb +10 -0
- data/spec/api2cart/store_spec.rb +25 -4
- metadata +74 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7da9d481a2ca97c77288a08317918fd795b742a
|
4
|
+
data.tar.gz: 93d0a824c3299f4d50a073b3f2583123fad82e97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e634e1f644cfdf641eec2c9d3da682d457bd7c3d6239ac33552eacf2f0e0e628582713e1de5e7083f9969af65bf77d54e9463716e09e40fb562a5d4cde46071f
|
7
|
+
data.tar.gz: f0957f17c4002a871b3db006dfbe79ad12a9d44d5433d080f74662831c36538a154480a2dd9a8b10cefb8e8aee86819271ed921fdf36f07c1237f50ff13cacee
|
data/lib/api2cart.rb
CHANGED
data/lib/api2cart/client.rb
CHANGED
@@ -20,6 +20,10 @@ module Api2cart
|
|
20
20
|
response_json['result']
|
21
21
|
end
|
22
22
|
|
23
|
+
def return_code
|
24
|
+
response_json['return_code']
|
25
|
+
end
|
26
|
+
|
23
27
|
protected
|
24
28
|
|
25
29
|
attr_accessor :response_body
|
@@ -28,10 +32,6 @@ module Api2cart
|
|
28
32
|
@response_json ||= JSON.parse response_body
|
29
33
|
end
|
30
34
|
|
31
|
-
def return_code
|
32
|
-
response_json['return_code']
|
33
|
-
end
|
34
|
-
|
35
35
|
def parsed_proxy_url
|
36
36
|
@parsed_proxy_url ||= URI.parse proxy_url
|
37
37
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# List of errors: http://docs.api2cart.com/post/error-codes
|
2
|
+
|
3
|
+
module Api2cart
|
4
|
+
class ErrorClassRecognizer
|
5
|
+
ERROR_CODE_MAPPING = {
|
6
|
+
'1' => Api2cart::Errors::ServiceNotAvailable,
|
7
|
+
'2' => Api2cart::Errors::IncorrectApiKey,
|
8
|
+
'3' => Api2cart::Errors::MethodNameMissing,
|
9
|
+
'4' => Api2cart::Errors::StoreAccessDenied,
|
10
|
+
'5' => Api2cart::Errors::ApiAccessDenied,
|
11
|
+
'6' => Api2cart::Errors::ApiKeyDisabled,
|
12
|
+
'7' => Api2cart::Errors::TooManyRequests,
|
13
|
+
'8' => Api2cart::Errors::StoreAlreadyExists,
|
14
|
+
'9' => Api2cart::Errors::InternalServiceError,
|
15
|
+
'100' => Api2cart::Errors::IncorrectApiRequest,
|
16
|
+
'101' => Api2cart::Errors::StoreNotFound,
|
17
|
+
'102' => Api2cart::Errors::IncorrectFtpAccess,
|
18
|
+
'103' => Api2cart::Errors::IncorrectFtpWritePermissions,
|
19
|
+
'104' => Api2cart::Errors::BridgeNotFound,
|
20
|
+
'105' => Api2cart::Errors::ConnectionBridgeResponseError,
|
21
|
+
'106' => Api2cart::Errors::StoreUrlUnreachable,
|
22
|
+
'107' => Api2cart::Errors::IncorrectShoppingCartId,
|
23
|
+
'108' => Api2cart::Errors::SearchParametersMissing,
|
24
|
+
'109' => Api2cart::Errors::IncorrectParameters,
|
25
|
+
'110' => Api2cart::Errors::UpdateParametersMissing,
|
26
|
+
'111' => Api2cart::Errors::UpdateItemIdMissing,
|
27
|
+
'112' => Api2cart::Errors::ItemNotFound,
|
28
|
+
'113' => Api2cart::Errors::ItemAlreadyExists,
|
29
|
+
'114' => Api2cart::Errors::RequiredParameterMissing,
|
30
|
+
'115' => Api2cart::Errors::TooManyPrefixes,
|
31
|
+
'116' => Api2cart::Errors::DuplicatedRecordInDatabase
|
32
|
+
}.freeze
|
33
|
+
|
34
|
+
DEFAULT_ERROR_CLASS = Api2cart::Errors::UnknownError.freeze
|
35
|
+
|
36
|
+
def self.call error_code
|
37
|
+
ERROR_CODE_MAPPING[error_code.to_s] || Api2cart::Errors::UnknownError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Api2cart
|
2
|
+
module Errors
|
3
|
+
class Api2cartException < RuntimeError; end
|
4
|
+
|
5
|
+
class ServiceNotAvailable < Api2cartException; end
|
6
|
+
class IncorrectApiRequest < Api2cartException; end
|
7
|
+
class StoreNotFound < Api2cartException; end
|
8
|
+
class IncorrectFtpAccess < Api2cartException; end
|
9
|
+
class IncorrectFtpWritePermissions < Api2cartException; end
|
10
|
+
class BridgeNotFound < Api2cartException; end
|
11
|
+
class ConnectionBridgeResponseError < Api2cartException; end
|
12
|
+
class StoreUrlUnreachable < Api2cartException; end
|
13
|
+
class IncorrectShoppingCartId < Api2cartException; end
|
14
|
+
class SearchParametersMissing < Api2cartException; end
|
15
|
+
class IncorrectParameters < Api2cartException; end
|
16
|
+
class UpdateParametersMissing < Api2cartException; end
|
17
|
+
class UpdateItemIdMissing < Api2cartException; end
|
18
|
+
class ItemNotFound < Api2cartException; end
|
19
|
+
class ItemAlreadyExists < Api2cartException; end
|
20
|
+
class RequiredParameterMissing < Api2cartException; end
|
21
|
+
class TooManyPrefixes < Api2cartException; end
|
22
|
+
class DuplicatedRecordInDatabase < Api2cartException; end
|
23
|
+
class IncorrectApiKey < Api2cartException; end
|
24
|
+
class MethodNameMissing < Api2cartException; end
|
25
|
+
class StoreAccessDenied < Api2cartException; end
|
26
|
+
class ApiAccessDenied < Api2cartException; end
|
27
|
+
class ApiKeyDisabled < Api2cartException; end
|
28
|
+
class TooManyRequests < Api2cartException; end
|
29
|
+
class StoreAlreadyExists < Api2cartException; end
|
30
|
+
class InternalServiceError < Api2cartException; end
|
31
|
+
class UnknownError < Api2cartException; end
|
32
|
+
end
|
33
|
+
end
|
data/lib/api2cart/store.rb
CHANGED
data/lib/api2cart/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::ErrorClassRecognizer, '.call' do
|
4
|
+
subject{ described_class.call(error_code) }
|
5
|
+
|
6
|
+
context 'when error code is known' do
|
7
|
+
it 'should return correspondent error' do
|
8
|
+
expect( described_class.call('1') ).to eq Api2cart::Errors::ServiceNotAvailable
|
9
|
+
expect( described_class.call('2') ).to eq Api2cart::Errors::IncorrectApiKey
|
10
|
+
expect( described_class.call('3') ).to eq Api2cart::Errors::MethodNameMissing
|
11
|
+
expect( described_class.call('4') ).to eq Api2cart::Errors::StoreAccessDenied
|
12
|
+
expect( described_class.call('5') ).to eq Api2cart::Errors::ApiAccessDenied
|
13
|
+
expect( described_class.call('6') ).to eq Api2cart::Errors::ApiKeyDisabled
|
14
|
+
expect( described_class.call('7') ).to eq Api2cart::Errors::TooManyRequests
|
15
|
+
expect( described_class.call('8') ).to eq Api2cart::Errors::StoreAlreadyExists
|
16
|
+
expect( described_class.call('9') ).to eq Api2cart::Errors::InternalServiceError
|
17
|
+
expect( described_class.call('100') ).to eq Api2cart::Errors::IncorrectApiRequest
|
18
|
+
expect( described_class.call('101') ).to eq Api2cart::Errors::StoreNotFound
|
19
|
+
expect( described_class.call('102') ).to eq Api2cart::Errors::IncorrectFtpAccess
|
20
|
+
expect( described_class.call('103') ).to eq Api2cart::Errors::IncorrectFtpWritePermissions
|
21
|
+
expect( described_class.call('104') ).to eq Api2cart::Errors::BridgeNotFound
|
22
|
+
expect( described_class.call('105') ).to eq Api2cart::Errors::ConnectionBridgeResponseError
|
23
|
+
expect( described_class.call('106') ).to eq Api2cart::Errors::StoreUrlUnreachable
|
24
|
+
expect( described_class.call('107') ).to eq Api2cart::Errors::IncorrectShoppingCartId
|
25
|
+
expect( described_class.call('108') ).to eq Api2cart::Errors::SearchParametersMissing
|
26
|
+
expect( described_class.call('109') ).to eq Api2cart::Errors::IncorrectParameters
|
27
|
+
expect( described_class.call('110') ).to eq Api2cart::Errors::UpdateParametersMissing
|
28
|
+
expect( described_class.call('111') ).to eq Api2cart::Errors::UpdateItemIdMissing
|
29
|
+
expect( described_class.call('112') ).to eq Api2cart::Errors::ItemNotFound
|
30
|
+
expect( described_class.call('113') ).to eq Api2cart::Errors::ItemAlreadyExists
|
31
|
+
expect( described_class.call('114') ).to eq Api2cart::Errors::RequiredParameterMissing
|
32
|
+
expect( described_class.call('115') ).to eq Api2cart::Errors::TooManyPrefixes
|
33
|
+
expect( described_class.call('116') ).to eq Api2cart::Errors::DuplicatedRecordInDatabase
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when error code is unknown' do
|
38
|
+
let(:error_code) { '100000' }
|
39
|
+
|
40
|
+
it 'should return Api2cart::Errors::UnknownError' do
|
41
|
+
should eq Api2cart::Errors::UnknownError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::ApiAccessDenied do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Api access denied" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::ApiAccessDenied, "Api access denied"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::ApiKeyDisabled do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Api key is disabled" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::ApiKeyDisabled, "Api key is disabled"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::BridgeNotFound do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Bridge not found" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::BridgeNotFound, "Bridge not found"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::ConnectionBridgeResponseError do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Connection bridge response error" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::ConnectionBridgeResponseError, "Connection bridge response error"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::DuplicatedRecordInDatabase do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Duplicated record in database" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::DuplicatedRecordInDatabase, "Duplicated record in database"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::IncorrectApiKey do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Incorrect api key" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::IncorrectApiKey, "Incorrect api key"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::IncorrectApiRequest do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Incorrect API request" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::IncorrectApiRequest, "Incorrect API request"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::IncorrectFtpAccess do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Incorrect ftp access" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::IncorrectFtpAccess, "Incorrect ftp access"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::IncorrectFtpWritePermissions do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Incorrect ftp write permissions" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::IncorrectFtpWritePermissions, "Incorrect ftp write permissions"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::IncorrectParameters do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Incorrect params for method" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::IncorrectParameters, "Incorrect params for method"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::IncorrectShoppingCartId do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Incorrect shopping cart id" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::IncorrectShoppingCartId, "Incorrect shopping cart id"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::InternalServiceError do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Something went wrong with Api2Cart service" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::InternalServiceError, "Something went wrong with Api2Cart service"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::ItemAlreadyExists do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Item already exists" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::ItemAlreadyExists, "Item already exists"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::ItemNotFound do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Item not found" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::ItemNotFound, "Item not found"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::MethodNameMissing do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Method is not specified" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::MethodNameMissing, "Method is not specified"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::RequiredParameterMissing do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Required parameter is missing" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::RequiredParameterMissing, "Required parameter is missing"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::SearchParametersMissing do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Search parameters are not specified" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::SearchParametersMissing, "Search parameters are not specified"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::ServiceNotAvailable do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Service not available" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::ServiceNotAvailable, "Service not available"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::StoreAccessDenied do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Access to the store is denied" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::StoreAccessDenied, "Access to the store is denied"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::StoreAlreadyExists do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Store already exists" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::StoreAlreadyExists, "Store already exists"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::StoreNotFound do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Store not found" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::StoreNotFound, "Store not found"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::StoreUrlUnreachable do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Store URL is unreachable" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::StoreUrlUnreachable, "Store URL is unreachable"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::TooManyPrefixes do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Too many prefixes" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::TooManyPrefixes, "Too many prefixes"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::TooManyRequests do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Too many requests to the store" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::TooManyRequests, "Too many requests to the store"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::UpdateItemIdMissing do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Update item identifier not specified" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::UpdateItemIdMissing, "Update item identifier not specified"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api2cart::Errors::UpdateParametersMissing do
|
4
|
+
subject { raise described_class, error_message }
|
5
|
+
let(:error_message) { "Update parameters are not specified" }
|
6
|
+
|
7
|
+
it 'should raise error with complete message' do
|
8
|
+
expect{ subject }.to raise_error Api2cart::Errors::UpdateParametersMissing, "Update parameters are not specified"
|
9
|
+
end
|
10
|
+
end
|
data/spec/api2cart/store_spec.rb
CHANGED
@@ -11,10 +11,31 @@ describe Api2cart::Store do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'when response contains an error', vcr: { cassette_name: 'erroneous_request' } do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'general case' do
|
23
|
+
let(:api2cart_store) { Api2cart::Store.new('wrong', 'even more wrong') }
|
24
|
+
let(:error_class) { double }
|
25
|
+
|
26
|
+
subject{ api2cart_store.product_count }
|
27
|
+
|
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)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should call for ErrorClassRecognizer' do
|
35
|
+
expect_any_instance_of(Kernel).to receive(:raise).with(error_class, 'Something went wrong')
|
36
|
+
|
37
|
+
subject
|
38
|
+
end
|
18
39
|
end
|
19
40
|
end
|
20
41
|
end
|
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.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vartanov
|
@@ -9,90 +9,90 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.7'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.7'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - ~>
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '10.0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - ~>
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '10.0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: vcr
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: webmock
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
description: Ruby client for API2Cart with proxy support
|
@@ -103,8 +103,8 @@ executables: []
|
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
-
- .gitignore
|
107
|
-
- .rspec
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
108
|
- Gemfile
|
109
109
|
- LICENSE
|
110
110
|
- README.md
|
@@ -112,10 +112,39 @@ files:
|
|
112
112
|
- api2cart-ruby.gemspec
|
113
113
|
- lib/api2cart.rb
|
114
114
|
- lib/api2cart/client.rb
|
115
|
+
- lib/api2cart/error_class_recognizer.rb
|
116
|
+
- lib/api2cart/errors.rb
|
115
117
|
- lib/api2cart/request_url_composer.rb
|
116
118
|
- lib/api2cart/store.rb
|
117
119
|
- lib/api2cart/version.rb
|
118
120
|
- spec/api2cart/client_spec.rb
|
121
|
+
- spec/api2cart/error_class_recognizer_spec.rb
|
122
|
+
- spec/api2cart/errors/api_access_denied_spec.rb
|
123
|
+
- spec/api2cart/errors/api_key_disabled_spec.rb
|
124
|
+
- spec/api2cart/errors/bridge_not_found_spec.rb
|
125
|
+
- spec/api2cart/errors/connection_bridge_response_error_spec.rb
|
126
|
+
- spec/api2cart/errors/duplicated_record_in_database_spec.rb
|
127
|
+
- spec/api2cart/errors/incorrect_api_key_spec.rb
|
128
|
+
- spec/api2cart/errors/incorrect_api_request_spec.rb
|
129
|
+
- spec/api2cart/errors/incorrect_ftp_access_spec.rb
|
130
|
+
- spec/api2cart/errors/incorrect_ftp_write_permissions_spec.rb
|
131
|
+
- spec/api2cart/errors/incorrect_parameters_spec.rb
|
132
|
+
- spec/api2cart/errors/incorrect_shopping_cart_id_spec.rb
|
133
|
+
- spec/api2cart/errors/internal_service_error_spec.rb
|
134
|
+
- spec/api2cart/errors/item_already_exists_spec.rb
|
135
|
+
- spec/api2cart/errors/item_not_found_spec.rb
|
136
|
+
- spec/api2cart/errors/method_name_missing_spec.rb
|
137
|
+
- spec/api2cart/errors/required_parameter_missing_spec.rb
|
138
|
+
- spec/api2cart/errors/search_parameter_missing_spec.rb
|
139
|
+
- spec/api2cart/errors/service_not_available_spec.rb
|
140
|
+
- spec/api2cart/errors/store_access_denied_spec.rb
|
141
|
+
- spec/api2cart/errors/store_already_exists_spec.rb
|
142
|
+
- spec/api2cart/errors/store_not_found_spec.rb
|
143
|
+
- spec/api2cart/errors/store_url_unreachable_spec.rb
|
144
|
+
- spec/api2cart/errors/too_many_prefixes_spec.rb
|
145
|
+
- spec/api2cart/errors/too_many_requests_spec.rb
|
146
|
+
- spec/api2cart/errors/update_item_id_missing_spec.rb
|
147
|
+
- spec/api2cart/errors/update_parameters_missing_spec.rb
|
119
148
|
- spec/api2cart/request_url_composer_spec.rb
|
120
149
|
- spec/api2cart/store_spec.rb
|
121
150
|
- spec/api2cart/with_proxy_spec.rb
|
@@ -132,12 +161,12 @@ require_paths:
|
|
132
161
|
- lib
|
133
162
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
163
|
requirements:
|
135
|
-
- -
|
164
|
+
- - ">="
|
136
165
|
- !ruby/object:Gem::Version
|
137
166
|
version: '0'
|
138
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
168
|
requirements:
|
140
|
-
- -
|
169
|
+
- - ">="
|
141
170
|
- !ruby/object:Gem::Version
|
142
171
|
version: '0'
|
143
172
|
requirements: []
|
@@ -148,6 +177,33 @@ specification_version: 4
|
|
148
177
|
summary: Ruby client for API2Cart
|
149
178
|
test_files:
|
150
179
|
- spec/api2cart/client_spec.rb
|
180
|
+
- spec/api2cart/error_class_recognizer_spec.rb
|
181
|
+
- spec/api2cart/errors/api_access_denied_spec.rb
|
182
|
+
- spec/api2cart/errors/api_key_disabled_spec.rb
|
183
|
+
- spec/api2cart/errors/bridge_not_found_spec.rb
|
184
|
+
- spec/api2cart/errors/connection_bridge_response_error_spec.rb
|
185
|
+
- spec/api2cart/errors/duplicated_record_in_database_spec.rb
|
186
|
+
- spec/api2cart/errors/incorrect_api_key_spec.rb
|
187
|
+
- spec/api2cart/errors/incorrect_api_request_spec.rb
|
188
|
+
- spec/api2cart/errors/incorrect_ftp_access_spec.rb
|
189
|
+
- spec/api2cart/errors/incorrect_ftp_write_permissions_spec.rb
|
190
|
+
- spec/api2cart/errors/incorrect_parameters_spec.rb
|
191
|
+
- spec/api2cart/errors/incorrect_shopping_cart_id_spec.rb
|
192
|
+
- spec/api2cart/errors/internal_service_error_spec.rb
|
193
|
+
- spec/api2cart/errors/item_already_exists_spec.rb
|
194
|
+
- spec/api2cart/errors/item_not_found_spec.rb
|
195
|
+
- spec/api2cart/errors/method_name_missing_spec.rb
|
196
|
+
- spec/api2cart/errors/required_parameter_missing_spec.rb
|
197
|
+
- spec/api2cart/errors/search_parameter_missing_spec.rb
|
198
|
+
- spec/api2cart/errors/service_not_available_spec.rb
|
199
|
+
- spec/api2cart/errors/store_access_denied_spec.rb
|
200
|
+
- spec/api2cart/errors/store_already_exists_spec.rb
|
201
|
+
- spec/api2cart/errors/store_not_found_spec.rb
|
202
|
+
- spec/api2cart/errors/store_url_unreachable_spec.rb
|
203
|
+
- spec/api2cart/errors/too_many_prefixes_spec.rb
|
204
|
+
- spec/api2cart/errors/too_many_requests_spec.rb
|
205
|
+
- spec/api2cart/errors/update_item_id_missing_spec.rb
|
206
|
+
- spec/api2cart/errors/update_parameters_missing_spec.rb
|
151
207
|
- spec/api2cart/request_url_composer_spec.rb
|
152
208
|
- spec/api2cart/store_spec.rb
|
153
209
|
- spec/api2cart/with_proxy_spec.rb
|