currency_cloud 0.9.0 → 0.10.0
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 +4 -4
- data/.gitignore +31 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +2 -4
- data/Gemfile +0 -3
- data/LICENSE.md +16 -17
- data/README.md +5 -3
- data/Rakefile +12 -12
- data/currency_cloud.gemspec +9 -9
- data/examples/server.rb +7 -7
- data/lib/currency_cloud/client.rb +5 -1
- data/lib/currency_cloud/conversion.rb +15 -0
- data/lib/currency_cloud/conversion_cancel_result.rb +5 -0
- data/lib/currency_cloud/conversion_date_change_result.rb +5 -0
- data/lib/currency_cloud/conversion_split_result.rb +5 -0
- data/lib/currency_cloud/errors/api_error.rb +2 -2
- data/lib/currency_cloud/errors/error_utils.rb +4 -4
- data/lib/currency_cloud/errors/unexpected_error.rb +3 -3
- data/lib/currency_cloud/iban.rb +22 -0
- data/lib/currency_cloud/ibans.rb +6 -0
- data/lib/currency_cloud/payer_required_details.rb +5 -0
- data/lib/currency_cloud/payment.rb +10 -0
- data/lib/currency_cloud/payment_authorisation_result.rb +5 -0
- data/lib/currency_cloud/payment_dates.rb +5 -0
- data/lib/currency_cloud/payment_submission.rb +5 -0
- data/lib/currency_cloud/purpose_code.rb +5 -0
- data/lib/currency_cloud/reference.rb +20 -5
- data/lib/currency_cloud/request_handler.rb +1 -3
- data/lib/currency_cloud/response_handler.rb +7 -7
- data/lib/currency_cloud/session.rb +2 -3
- data/lib/currency_cloud/transfer.rb +8 -0
- data/lib/currency_cloud/version.rb +1 -1
- data/lib/currency_cloud/virtual_account.rb +22 -0
- data/lib/currency_cloud/virtual_accounts.rb +6 -0
- data/spec/currency_cloud_spec.rb +9 -9
- data/spec/integration/authentication_spec.rb +2 -2
- data/spec/integration/conversions_spec.rb +94 -0
- data/spec/integration/error_utils_spec.rb +12 -12
- data/spec/integration/errors_spec.rb +84 -102
- data/spec/integration/ibans_spec.rb +42 -0
- data/spec/integration/payment_spec.rb +31 -0
- data/spec/integration/payments_spec.rb +67 -0
- data/spec/integration/reference_spec.rb +37 -14
- data/spec/integration/transfers_spec.rb +39 -0
- data/spec/integration/virtual_accounts_spec.rb +37 -0
- data/spec/spec_helper.rb +9 -1
- data/spec/support/vcr_cassettes/Authentication/can_be_closed.yml +1 -1
- data/spec/support/vcr_cassettes/Authentication/handles_session_timeout_error.yml +1 -1
- data/spec/support/vcr_cassettes/Authentication/happens_lazily.yml +1 -1
- data/spec/support/vcr_cassettes/Conversions/can_cancel_conversion/with_notes/has_a_non-empty_notes_attribute.yml +158 -0
- data/spec/support/vcr_cassettes/Conversions/can_cancel_conversion/without_notes/has_a_empty_notes_attribute.yml +157 -0
- data/spec/support/vcr_cassettes/Conversions/can_date_change_conversion.yml +157 -0
- data/spec/support/vcr_cassettes/Conversions/can_split_conversion.yml +157 -0
- data/spec/support/vcr_cassettes/Error/contains_full_details_for_api_error.yml +1 -1
- data/spec/support/vcr_cassettes/Error/is_raised_on_a_bad_request.yml +1 -1
- data/spec/support/vcr_cassettes/Error/is_raised_on_a_forbidden_request.yml +1 -1
- data/spec/support/vcr_cassettes/Error/is_raised_on_an_internal_server_error.yml +1 -1
- data/spec/support/vcr_cassettes/Error/is_raised_on_incorrect_authentication_details.yml +1 -1
- data/spec/support/vcr_cassettes/Error/is_raised_when_too_many_requests_have_been_issued.yml +1 -1
- data/spec/support/vcr_cassettes/IBANs/can_IBANs_for_a_specific_subaccount.yml +109 -0
- data/spec/support/vcr_cassettes/IBANs/can_IBANs_for_subaccounts.yml +108 -0
- data/spec/support/vcr_cassettes/IBANs/can_find.yml +114 -0
- data/spec/support/vcr_cassettes/Payments/can_authorise/when_payment_ids_are_valid.yml +263 -0
- data/spec/support/vcr_cassettes/Payments/can_create.yml +155 -0
- data/spec/support/vcr_cassettes/Payments/can_get_the_submission.yml +205 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_beneficiary_required_details.yml +77 -12
- data/spec/support/vcr_cassettes/Reference/can_retrieve_conversion_dates.yml +183 -22
- data/spec/support/vcr_cassettes/Reference/can_retrieve_currencies.yml +110 -22
- data/spec/support/vcr_cassettes/Reference/can_retrieve_payer_required_details.yml +103 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_payment_dates.yml +110 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_payment_purpose_codes.yml +128 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_settlement_accounts.yml +76 -11
- data/spec/support/vcr_cassettes/Settlements/can_add_conversion.yml +56 -6
- data/spec/support/vcr_cassettes/Settlements/can_release.yml +55 -5
- data/spec/support/vcr_cassettes/Settlements/can_remove_conversion.yml +55 -5
- data/spec/support/vcr_cassettes/Settlements/can_unrelease.yml +55 -5
- data/spec/support/vcr_cassettes/Transfers/can_create.yml +101 -0
- data/spec/support/vcr_cassettes/Transfers/can_find.yml +151 -0
- data/spec/support/vcr_cassettes/Transfers/can_retrieve.yml +151 -0
- data/spec/support/vcr_cassettes/VirtualAccounts/can_find.yml +108 -0
- data/spec/support/vcr_cassettes/VirtualAccounts/can_find_VANs_for_a_specific_subaccount.yml +108 -0
- data/spec/support/vcr_cassettes/VirtualAccounts/can_find_VANs_for_subaccounts.yml +108 -0
- metadata +82 -20
- data/Guardfile +0 -14
@@ -4,11 +4,6 @@ module CurrencyCloud
|
|
4
4
|
|
5
5
|
resource :reference
|
6
6
|
|
7
|
-
def self.currencies
|
8
|
-
response = client.get('currencies')
|
9
|
-
response['currencies'].map { |c| Currency.new(c) }
|
10
|
-
end
|
11
|
-
|
12
7
|
def self.beneficiary_required_details(params = {})
|
13
8
|
client.get('beneficiary_required_details', params)['details']
|
14
9
|
end
|
@@ -18,6 +13,26 @@ module CurrencyCloud
|
|
18
13
|
ConversionDates.new(dates)
|
19
14
|
end
|
20
15
|
|
16
|
+
def self.currencies
|
17
|
+
response = client.get('currencies')
|
18
|
+
response['currencies'].map { |c| Currency.new(c) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.payer_required_details(params)
|
22
|
+
response = client.get('payer_required_details', params)
|
23
|
+
response['details'].map { |prd| PayerRequiredDetails.new(prd) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.payment_dates(params)
|
27
|
+
dates = client.get('payment_dates', params)
|
28
|
+
PaymentDates.new(dates)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.payment_purpose_codes(params)
|
32
|
+
response = client.get('payment_purpose_codes', params)
|
33
|
+
response['purpose_codes'].map { |pc| PurposeCode.new(pc) }
|
34
|
+
end
|
35
|
+
|
21
36
|
def self.settlement_accounts(params = {})
|
22
37
|
response = client.get('settlement_accounts', params)
|
23
38
|
response['settlement_accounts'].map { |s| SettlementAccount.new(s) }
|
@@ -42,15 +42,13 @@ module CurrencyCloud
|
|
42
42
|
response_handler.process
|
43
43
|
rescue ApiError, UnexpectedError
|
44
44
|
raise
|
45
|
-
rescue => e
|
45
|
+
rescue StandardError => e
|
46
46
|
raise UnexpectedError.new(verb, full_url, params, e)
|
47
47
|
end
|
48
48
|
|
49
49
|
def process_options(opts)
|
50
50
|
options = { headers: headers }
|
51
|
-
# options[:debug_output] = $stdout
|
52
51
|
options.merge(opts)
|
53
|
-
# options
|
54
52
|
end
|
55
53
|
|
56
54
|
def process_params(params)
|
@@ -22,13 +22,13 @@ module CurrencyCloud
|
|
22
22
|
|
23
23
|
def handle_failure
|
24
24
|
error_class = case response.code
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
when 400 then BadRequestError
|
26
|
+
when 401 then AuthenticationError
|
27
|
+
when 403 then ForbiddenError
|
28
|
+
when 404 then NotFoundError
|
29
|
+
when 429 then TooManyRequestsError
|
30
|
+
when 500 then InternalApplicationError
|
31
|
+
end
|
32
32
|
raise error_class.new(verb, route, params, response) if error_class
|
33
33
|
raise UnexpectedError.new(verb, route, params, response)
|
34
34
|
end
|
@@ -10,9 +10,8 @@ module CurrencyCloud
|
|
10
10
|
attr_accessor :token, :on_behalf_of
|
11
11
|
|
12
12
|
def self.validate_environment(environment)
|
13
|
-
|
14
|
-
|
15
|
-
end
|
13
|
+
return if ENVIRONMENTS.key?(environment)
|
14
|
+
raise "'#{environment}' is not a valid environment. Must be one of: #{ENVIRONMENTS.keys.join(', ')}"
|
16
15
|
end
|
17
16
|
|
18
17
|
def initialize(environment, login_id, api_key, token)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CurrencyCloud
|
2
|
+
class VirtualAccount
|
3
|
+
include CurrencyCloud::Resource
|
4
|
+
|
5
|
+
resource :virtual_accounts
|
6
|
+
|
7
|
+
def self.find(params = {})
|
8
|
+
result = client.get('/', params)
|
9
|
+
VirtualAccounts.new(:virtual_accounts, self, result)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.for_subaccount(subaccount_id, params = {})
|
13
|
+
result = client.get("subaccounts/#{subaccount_id}", params)
|
14
|
+
VirtualAccounts.new(:virtual_accounts, self, result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.for_subaccounts(params = {})
|
18
|
+
result = client.get("subaccounts/find", params)
|
19
|
+
VirtualAccounts.new(:virtual_accounts, self, result)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/currency_cloud_spec.rb
CHANGED
@@ -17,23 +17,23 @@ describe CurrencyCloud do
|
|
17
17
|
|
18
18
|
describe '#login_id' do
|
19
19
|
it 'can set the login_id' do
|
20
|
-
CurrencyCloud.login_id = '
|
21
|
-
expect(CurrencyCloud.login_id).to eq('
|
20
|
+
CurrencyCloud.login_id = 'development@currencycloud.com'
|
21
|
+
expect(CurrencyCloud.login_id).to eq('development@currencycloud.com')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe '#api_key' do
|
26
26
|
it 'can set the api_key' do
|
27
|
-
CurrencyCloud.api_key = '
|
28
|
-
expect(CurrencyCloud.api_key).to eq('
|
27
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
28
|
+
expect(CurrencyCloud.api_key).to eq('deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#session' do
|
33
33
|
it 'returns a session object' do
|
34
34
|
CurrencyCloud.environment = :demonstration
|
35
|
-
CurrencyCloud.login_id = '
|
36
|
-
CurrencyCloud.api_key = '
|
35
|
+
CurrencyCloud.login_id = 'development@currencycloud.com'
|
36
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
37
37
|
|
38
38
|
request_handler = double('RequestHandler')
|
39
39
|
expect(request_handler).to receive(:post).and_return('auth_token' => '123')
|
@@ -45,13 +45,13 @@ describe CurrencyCloud do
|
|
45
45
|
it 'raises an error if the environment is not set' do
|
46
46
|
CurrencyCloud.environment = nil
|
47
47
|
expect { CurrencyCloud.session }
|
48
|
-
.to raise_error(
|
48
|
+
.to raise_error(RuntimeError)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'raises an error if the environment is invalid' do
|
52
52
|
CurrencyCloud.environment = :invalid
|
53
53
|
expect { CurrencyCloud.session }
|
54
|
-
.to raise_error(
|
54
|
+
.to raise_error(RuntimeError)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'raises an error if the login_id is not set' do
|
@@ -62,7 +62,7 @@ describe CurrencyCloud do
|
|
62
62
|
|
63
63
|
it 'raises an error if the api_key is not set' do
|
64
64
|
CurrencyCloud.environment = :demonstration
|
65
|
-
CurrencyCloud.login_id = '
|
65
|
+
CurrencyCloud.login_id = 'development@currencycloud.com'
|
66
66
|
expect { CurrencyCloud.session }
|
67
67
|
.to raise_error(CurrencyCloud::GeneralError, 'api_key must be set using CurrencyCloud.api_key=')
|
68
68
|
end
|
@@ -4,8 +4,8 @@ describe 'Authentication', vcr: true do
|
|
4
4
|
before do
|
5
5
|
CurrencyCloud.reset_session
|
6
6
|
CurrencyCloud.environment = :demonstration
|
7
|
-
CurrencyCloud.login_id = '
|
8
|
-
CurrencyCloud.api_key = '
|
7
|
+
CurrencyCloud.login_id = 'development@currencycloud.com'
|
8
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
9
9
|
CurrencyCloud.token = nil
|
10
10
|
end
|
11
11
|
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Conversions', vcr: true do
|
4
|
+
let(:conversion_params) do
|
5
|
+
{
|
6
|
+
buy_currency: 'USD',
|
7
|
+
sell_currency: 'GBP',
|
8
|
+
fixed_side: :buy,
|
9
|
+
amount: 95_000,
|
10
|
+
reason: 'SDK conversion testing',
|
11
|
+
term_agreement: true
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'can #cancel conversion' do
|
16
|
+
context 'without notes' do
|
17
|
+
it 'has a empty "notes" attribute' do
|
18
|
+
conversion = CurrencyCloud::Conversion.create(conversion_params)
|
19
|
+
cancelled_conversion = conversion.cancel
|
20
|
+
|
21
|
+
expect(cancelled_conversion).to have_attributes(
|
22
|
+
'account_id' => '67e1b252-40a7-454d-a097-8f77d385889d',
|
23
|
+
'contact_id' => '04d0c252-7b78-4d72-b408-df78841e3ddc',
|
24
|
+
'event_account_id' => '67e1b252-40a7-454d-a097-8f77d385889d',
|
25
|
+
'event_contact_id' => '04d0c252-7b78-4d72-b408-df78841e3ddc',
|
26
|
+
'conversion_id' => conversion.id,
|
27
|
+
'event_type' => 'self_service_cancellation',
|
28
|
+
'amount' => '-9.58',
|
29
|
+
'currency' => 'GBP',
|
30
|
+
'notes' => ''
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with notes' do
|
36
|
+
it 'has a non-empty "notes" attribute' do
|
37
|
+
conversion = CurrencyCloud::Conversion.create(conversion_params)
|
38
|
+
cancelled_conversion = conversion.cancel(notes: 'Business Terminated Contract')
|
39
|
+
|
40
|
+
expect(cancelled_conversion).to have_attributes(
|
41
|
+
'account_id' => '67e1b252-40a7-454d-a097-8f77d385889d',
|
42
|
+
'contact_id' => '04d0c252-7b78-4d72-b408-df78841e3ddc',
|
43
|
+
'event_account_id' => '67e1b252-40a7-454d-a097-8f77d385889d',
|
44
|
+
'event_contact_id' => '04d0c252-7b78-4d72-b408-df78841e3ddc',
|
45
|
+
'conversion_id' => conversion.id,
|
46
|
+
'event_type' => 'self_service_cancellation',
|
47
|
+
'amount' => '-9.58',
|
48
|
+
'currency' => 'GBP',
|
49
|
+
'notes' => 'Business Terminated Contract'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can #date_change conversion' do
|
56
|
+
new_settlement_date = Time.now + 86400
|
57
|
+
|
58
|
+
conversion = CurrencyCloud::Conversion.create(conversion_params)
|
59
|
+
|
60
|
+
conversion_with_date_changed = conversion.date_change(new_settlement_date: new_settlement_date)
|
61
|
+
|
62
|
+
expect(conversion_with_date_changed).to have_attributes(
|
63
|
+
'conversion_id' => conversion.id,
|
64
|
+
'amount' => '-14.38',
|
65
|
+
'currency' => 'GBP',
|
66
|
+
'new_conversion_date' => '2018-07-17T00:00:00+00:00',
|
67
|
+
'new_settlement_date' => '2018-07-17T15:30:00+00:00',
|
68
|
+
'old_conversion_date' => '2018-07-18T00:00:00+00:00',
|
69
|
+
'old_settlement_date' => '2018-07-18T15:30:00+00:00'
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'can #split conversion' do
|
74
|
+
conversion = CurrencyCloud::Conversion.create(conversion_params)
|
75
|
+
|
76
|
+
split_conversion = conversion.split(amount: 45_000)
|
77
|
+
|
78
|
+
expect(split_conversion.parent_conversion['sell_amount']).to eq('35513.88')
|
79
|
+
expect(split_conversion.parent_conversion['sell_currency']).to eq('GBP')
|
80
|
+
expect(split_conversion.parent_conversion['buy_amount']).to eq('50000.00')
|
81
|
+
expect(split_conversion.parent_conversion['buy_currency']).to eq('USD')
|
82
|
+
expect(split_conversion.parent_conversion['settlement_date']).to eq('2018-07-18T15:30:00+00:00')
|
83
|
+
expect(split_conversion.parent_conversion['conversion_date']).to eq('2018-07-18T00:00:00+00:00')
|
84
|
+
expect(split_conversion.parent_conversion['status']).to eq('awaiting_funds')
|
85
|
+
|
86
|
+
expect(split_conversion.child_conversion['sell_amount']).to eq('31962.50')
|
87
|
+
expect(split_conversion.child_conversion['sell_currency']).to eq('GBP')
|
88
|
+
expect(split_conversion.child_conversion['buy_amount']).to eq('45000.00')
|
89
|
+
expect(split_conversion.child_conversion['buy_currency']).to eq('USD')
|
90
|
+
expect(split_conversion.child_conversion['settlement_date']).to eq('2018-07-18T15:30:00+00:00')
|
91
|
+
expect(split_conversion.child_conversion['conversion_date']).to eq('2018-07-18T00:00:00+00:00')
|
92
|
+
expect(split_conversion.child_conversion['status']).to eq('awaiting_funds')
|
93
|
+
end
|
94
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'ErrorUtils' do
|
4
4
|
module CurrencyCloud
|
5
5
|
class ErrorUtilTester
|
6
6
|
extend ErrorUtils
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'can #redact_params' do
|
11
11
|
params = {
|
12
|
-
unaffected:
|
13
|
-
api_key:
|
14
|
-
login_id:
|
15
|
-
token:
|
12
|
+
unaffected: 'value',
|
13
|
+
api_key: 'value',
|
14
|
+
login_id: 'value',
|
15
|
+
token: 'value'
|
16
16
|
}
|
17
17
|
|
18
18
|
redacted = CurrencyCloud::ErrorUtilTester.redacted_params(params)
|
19
19
|
|
20
|
-
expect(redacted[:unaffected]).to eq
|
20
|
+
expect(redacted[:unaffected]).to eq 'value'
|
21
21
|
expect(redacted[:api_key]).to eq CurrencyCloud::ErrorUtils::REDACTED_STRING
|
22
22
|
expect(redacted[:login_id]).to eq CurrencyCloud::ErrorUtils::REDACTED_STRING
|
23
23
|
expect(redacted[:token]).to eq CurrencyCloud::ErrorUtils::REDACTED_STRING
|
24
24
|
|
25
|
-
expect(params[:unaffected]).to eq
|
26
|
-
expect(params[:api_key]).to eq
|
27
|
-
expect(params[:login_id]).to eq
|
28
|
-
expect(params[:token]).to eq
|
25
|
+
expect(params[:unaffected]).to eq 'value'
|
26
|
+
expect(params[:api_key]).to eq 'value'
|
27
|
+
expect(params[:login_id]).to eq 'value'
|
28
|
+
expect(params[:token]).to eq 'value'
|
29
29
|
end
|
30
30
|
end
|
@@ -2,28 +2,23 @@ require 'spec_helper'
|
|
2
2
|
require 'net/http'
|
3
3
|
|
4
4
|
describe 'Error', vcr: true do
|
5
|
+
include CurrencyCloud::ErrorUtils
|
6
|
+
|
5
7
|
before(:each) do
|
6
8
|
CurrencyCloud.reset_session
|
7
9
|
CurrencyCloud.environment = :demonstration
|
8
|
-
CurrencyCloud.login_id = '
|
9
|
-
CurrencyCloud.api_key = '
|
10
|
+
CurrencyCloud.login_id = 'development@currencycloud.com'
|
11
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
10
12
|
CurrencyCloud.token = nil
|
11
13
|
end
|
12
14
|
|
13
15
|
it 'contains full details for api error' do
|
14
16
|
CurrencyCloud.login_id = 'non-existent-login-id'
|
15
|
-
CurrencyCloud.api_key = '
|
16
|
-
|
17
|
-
error = nil
|
18
|
-
begin
|
19
|
-
CurrencyCloud.session
|
20
|
-
raise 'Should have failed'
|
21
|
-
rescue CurrencyCloud::BadRequestError => error
|
22
|
-
end
|
17
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
23
18
|
|
24
19
|
expected_error = %{CurrencyCloud::BadRequestError
|
25
20
|
---
|
26
|
-
platform: #{
|
21
|
+
platform: #{platform}
|
27
22
|
request:
|
28
23
|
parameters:
|
29
24
|
login_id: REDACTED
|
@@ -41,68 +36,62 @@ errors:
|
|
41
36
|
params:
|
42
37
|
length: 64
|
43
38
|
}
|
44
|
-
|
39
|
+
|
40
|
+
expect { CurrencyCloud.session }.to raise_error(CurrencyCloud::BadRequestError, expected_error)
|
45
41
|
end
|
46
42
|
|
47
43
|
it 'is raised on a bad request' do
|
48
44
|
CurrencyCloud.login_id = 'non-existent-login-id'
|
49
|
-
CurrencyCloud.api_key = '
|
45
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
50
46
|
|
51
|
-
error = nil
|
52
47
|
begin
|
53
48
|
CurrencyCloud.session
|
54
|
-
|
49
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
55
50
|
rescue CurrencyCloud::BadRequestError => error
|
51
|
+
expect(error.code).to eq('auth_invalid_user_login_details')
|
52
|
+
expect(error.raw_response).to_not be_nil
|
53
|
+
expect(error.status_code).to eq(400)
|
54
|
+
expect(error.messages.length).to eq(1)
|
55
|
+
|
56
|
+
error_message = error.messages[0]
|
57
|
+
expect(error_message.field).to eq('api_key')
|
58
|
+
expect(error_message.code).to eq('api_key_length_is_invalid')
|
59
|
+
expect(error_message.message).to eq('api_key should be 64 character(s) long')
|
60
|
+
expect(error_message.params).to include('length' => 64)
|
56
61
|
end
|
57
|
-
|
58
|
-
expect(error.code).to eq('auth_invalid_user_login_details')
|
59
|
-
expect(error.raw_response).to_not be_nil
|
60
|
-
expect(error.status_code).to eq(400)
|
61
|
-
expect(error.messages.length).to eq(1)
|
62
|
-
|
63
|
-
error_message = error.messages[0]
|
64
|
-
expect(error_message.field).to eq('api_key')
|
65
|
-
expect(error_message.code).to eq('api_key_length_is_invalid')
|
66
|
-
expect(error_message.message).to eq('api_key should be 64 character(s) long')
|
67
|
-
expect(error_message.params).to include('length' => 64)
|
68
62
|
end
|
69
63
|
|
70
64
|
it 'is raised on incorrect authentication details' do
|
71
65
|
CurrencyCloud.login_id = 'non-existent-login-id'
|
72
|
-
CurrencyCloud.api_key = '
|
66
|
+
CurrencyCloud.api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
73
67
|
|
74
|
-
error = nil
|
75
68
|
begin
|
76
69
|
CurrencyCloud.session
|
77
|
-
|
70
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
78
71
|
rescue CurrencyCloud::AuthenticationError => error
|
72
|
+
expect(error.code).to eq('auth_failed')
|
73
|
+
expect(error.raw_response).to_not be_nil
|
74
|
+
expect(error.status_code).to eq(401)
|
75
|
+
expect(error.messages.length).to eq(1)
|
76
|
+
|
77
|
+
error_message = error.messages[0]
|
78
|
+
expect(error_message.field).to eq('username')
|
79
|
+
expect(error_message.code).to eq('invalid_supplied_credentials')
|
80
|
+
expect(error_message.message).to eq('Authentication failed with the supplied credentials')
|
81
|
+
expect(error_message.params).to be_empty
|
79
82
|
end
|
80
|
-
|
81
|
-
expect(error.code).to eq('auth_failed')
|
82
|
-
expect(error.raw_response).to_not be_nil
|
83
|
-
expect(error.status_code).to eq(401)
|
84
|
-
expect(error.messages.length).to eq(1)
|
85
|
-
|
86
|
-
error_message = error.messages[0]
|
87
|
-
expect(error_message.field).to eq('username')
|
88
|
-
expect(error_message.code).to eq('invalid_supplied_credentials')
|
89
|
-
expect(error_message.message).to eq('Authentication failed with the supplied credentials')
|
90
|
-
expect(error_message.params).to be_empty
|
91
83
|
end
|
92
84
|
|
93
85
|
it 'is raised on unexpected error' do
|
94
86
|
allow(HTTParty).to receive(:post).and_raise(Timeout::Error)
|
95
87
|
|
96
|
-
error = nil
|
97
88
|
begin
|
98
89
|
CurrencyCloud.session
|
99
|
-
|
90
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
100
91
|
rescue CurrencyCloud::UnexpectedError => error
|
101
|
-
|
102
|
-
|
103
|
-
expected_error = %(CurrencyCloud::UnexpectedError
|
92
|
+
expected_error = %(CurrencyCloud::UnexpectedError
|
104
93
|
---
|
105
|
-
platform: #{
|
94
|
+
platform: #{platform}
|
106
95
|
request:
|
107
96
|
parameters:
|
108
97
|
login_id: REDACTED
|
@@ -112,92 +101,85 @@ request:
|
|
112
101
|
inner_error: Timeout::Error
|
113
102
|
)
|
114
103
|
|
115
|
-
|
116
|
-
|
117
|
-
|
104
|
+
expect(error.to_s).to eq(expected_error)
|
105
|
+
expect(error.inner_error).to_not be_nil
|
106
|
+
expect(error.inner_error.class).to eq(Timeout::Error)
|
107
|
+
end
|
118
108
|
end
|
119
109
|
|
120
110
|
it 'is raised on a forbidden request' do
|
121
|
-
error = nil
|
122
111
|
begin
|
123
112
|
CurrencyCloud.session
|
124
|
-
|
113
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
125
114
|
rescue CurrencyCloud::ForbiddenError => error
|
115
|
+
expect(error.code).to eq('auth_failed')
|
116
|
+
expect(error.raw_response).to_not be_nil
|
117
|
+
expect(error.status_code).to eq(403)
|
118
|
+
expect(error.messages.length).to eq(1)
|
119
|
+
|
120
|
+
error_message = error.messages[0]
|
121
|
+
expect(error_message.field).to eq('username')
|
122
|
+
expect(error_message.code).to eq('invalid_supplied_credentials')
|
123
|
+
expect(error_message.message).to eq('Authentication failed with the supplied credentials')
|
124
|
+
expect(error_message.params).to be_empty
|
126
125
|
end
|
127
|
-
|
128
|
-
expect(error.code).to eq('auth_failed')
|
129
|
-
expect(error.raw_response).to_not be_nil
|
130
|
-
expect(error.status_code).to eq(403)
|
131
|
-
expect(error.messages.length).to eq(1)
|
132
|
-
|
133
|
-
error_message = error.messages[0]
|
134
|
-
expect(error_message.field).to eq('username')
|
135
|
-
expect(error_message.code).to eq('invalid_supplied_credentials')
|
136
|
-
expect(error_message.message).to eq('Authentication failed with the supplied credentials')
|
137
|
-
expect(error_message.params).to be_empty
|
138
126
|
end
|
139
127
|
|
140
128
|
it 'is raised when a resource is not found' do
|
141
129
|
CurrencyCloud.token = '656485646b068f6e9c81e3d885fa54f5'
|
142
|
-
error = nil
|
143
130
|
begin
|
144
131
|
CurrencyCloud::Beneficiary.retrieve('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
145
|
-
|
132
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
146
133
|
rescue CurrencyCloud::NotFoundError => error
|
134
|
+
expect(error.code).to eq('beneficiary_not_found')
|
135
|
+
expect(error.raw_response).to_not be_nil
|
136
|
+
expect(error.status_code).to eq(404)
|
137
|
+
expect(error.messages.length).to eq(1)
|
138
|
+
|
139
|
+
error_message = error.messages[0]
|
140
|
+
expect(error_message.field).to eq('id')
|
141
|
+
expect(error_message.code).to eq('beneficiary_not_found')
|
142
|
+
expect(error_message.message).to eq('Beneficiary was not found for this id')
|
143
|
+
expect(error_message.params).to be_empty
|
147
144
|
end
|
148
|
-
|
149
|
-
expect(error.code).to eq('beneficiary_not_found')
|
150
|
-
expect(error.raw_response).to_not be_nil
|
151
|
-
expect(error.status_code).to eq(404)
|
152
|
-
expect(error.messages.length).to eq(1)
|
153
|
-
|
154
|
-
error_message = error.messages[0]
|
155
|
-
expect(error_message.field).to eq('id')
|
156
|
-
expect(error_message.code).to eq('beneficiary_not_found')
|
157
|
-
expect(error_message.message).to eq('Beneficiary was not found for this id')
|
158
|
-
expect(error_message.params).to be_empty
|
159
145
|
end
|
160
146
|
|
161
147
|
it 'is raised on an internal server error' do
|
162
|
-
error = nil
|
163
148
|
begin
|
164
149
|
CurrencyCloud.session
|
165
|
-
|
150
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
166
151
|
rescue CurrencyCloud::InternalApplicationError => error
|
152
|
+
expect(error.code).to eq('internal_application_error')
|
153
|
+
expect(error.raw_response).to_not be_nil
|
154
|
+
expect(error.status_code).to eq(500)
|
155
|
+
expect(error.messages.length).to eq(1)
|
156
|
+
|
157
|
+
error_message = error.messages[0]
|
158
|
+
expect(error_message.field).to eq('base')
|
159
|
+
expect(error_message.code).to eq('internal_application_error')
|
160
|
+
expect(error_message.message).to eq('A general application error occurred')
|
161
|
+
expect(error_message.params).to include('request_id' => 2771875643610572878)
|
167
162
|
end
|
168
|
-
|
169
|
-
expect(error.code).to eq('internal_application_error')
|
170
|
-
expect(error.raw_response).to_not be_nil
|
171
|
-
expect(error.status_code).to eq(500)
|
172
|
-
expect(error.messages.length).to eq(1)
|
173
|
-
|
174
|
-
error_message = error.messages[0]
|
175
|
-
expect(error_message.field).to eq('base')
|
176
|
-
expect(error_message.code).to eq('internal_application_error')
|
177
|
-
expect(error_message.message).to eq('A general application error occurred')
|
178
|
-
expect(error_message.params).to include('request_id' => 2771875643610572878)
|
179
163
|
end
|
180
164
|
|
181
165
|
it 'is raised when too many requests have been issued' do
|
182
|
-
CurrencyCloud.login_id = '
|
166
|
+
CurrencyCloud.login_id = 'development@currencycloud.com'
|
183
167
|
|
184
|
-
error = nil
|
185
168
|
begin
|
186
169
|
CurrencyCloud.session
|
187
170
|
|
188
|
-
|
171
|
+
expect(0).to eq 1, 'expected exception that was not raised'
|
189
172
|
rescue CurrencyCloud::TooManyRequestsError => error
|
173
|
+
expect(error.code).to eq('too_many_requests')
|
174
|
+
expect(error.raw_response).to_not be_nil
|
175
|
+
expect(error.status_code).to eq(429)
|
176
|
+
expect(error.messages.length).to eq(1)
|
177
|
+
|
178
|
+
error_message = error.messages[0]
|
179
|
+
expect(error_message.field).to eq('base')
|
180
|
+
expect(error_message.code).to eq('too_many_requests')
|
181
|
+
expect(error_message.message).to eq('Too many requests have been made to the api. Please refer to the Developer Center for more information')
|
182
|
+
expect(error_message.params).to be_empty
|
190
183
|
end
|
191
|
-
|
192
|
-
expect(error.code).to eq('too_many_requests')
|
193
|
-
expect(error.raw_response).to_not be_nil
|
194
|
-
expect(error.status_code).to eq(429)
|
195
|
-
expect(error.messages.length).to eq(1)
|
196
|
-
|
197
|
-
error_message = error.messages[0]
|
198
|
-
expect(error_message.field).to eq('base')
|
199
|
-
expect(error_message.code).to eq('too_many_requests')
|
200
|
-
expect(error_message.message).to eq('Too many requests have been made to the api. Please refer to the Developer Center for more information')
|
201
|
-
expect(error_message.params).to be_empty
|
202
184
|
end
|
203
185
|
end
|