currency_cloud 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +99 -0
- data/Guardfile +14 -0
- data/LICENSE.md +22 -0
- data/README.md +10 -0
- data/Rakefile +30 -0
- data/currency_cloud.gemspec +27 -0
- data/examples/server.rb +15 -0
- data/lib/currency_cloud.rb +26 -0
- data/lib/currency_cloud/actions/create.rb +9 -0
- data/lib/currency_cloud/actions/current.rb +9 -0
- data/lib/currency_cloud/actions/delete.rb +15 -0
- data/lib/currency_cloud/actions/find.rb +27 -0
- data/lib/currency_cloud/actions/retrieve.rb +9 -0
- data/lib/currency_cloud/actions/update.rb +12 -0
- data/lib/currency_cloud/errors/api_error.rb +38 -0
- data/lib/currency_cloud/errors/config_error.rb +5 -0
- data/lib/currency_cloud/errors/unexpected_error.rb +10 -0
- data/lib/currency_cloud/pagination.rb +7 -0
- data/lib/currency_cloud/request_handler.rb +68 -0
- data/lib/currency_cloud/resource.rb +73 -0
- data/lib/currency_cloud/resourceful_collection.rb +15 -0
- data/lib/currency_cloud/resources/account.rb +6 -0
- data/lib/currency_cloud/resources/balance.rb +8 -0
- data/lib/currency_cloud/resources/beneficiary.rb +14 -0
- data/lib/currency_cloud/resources/contact.rb +6 -0
- data/lib/currency_cloud/resources/conversion.rb +10 -0
- data/lib/currency_cloud/resources/payer.rb +6 -0
- data/lib/currency_cloud/resources/payment.rb +11 -0
- data/lib/currency_cloud/resources/rate.rb +21 -0
- data/lib/currency_cloud/resources/reference.rb +29 -0
- data/lib/currency_cloud/resources/settlement.rb +30 -0
- data/lib/currency_cloud/resources/transaction.rb +7 -0
- data/lib/currency_cloud/response_handler.rb +46 -0
- data/lib/currency_cloud/session.rb +62 -0
- data/lib/currency_cloud/version.rb +8 -0
- data/spec/currency_cloud_spec.rb +78 -0
- data/spec/integration/actions_spec.rb +101 -0
- data/spec/integration/authentication_spec.rb +37 -0
- data/spec/integration/errors_spec.rb +157 -0
- data/spec/integration/rates_spec.rb +39 -0
- data/spec/integration/reference_spec.rb +57 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/vcr_cassettes/Actions/can_create.yml +38 -0
- data/spec/support/vcr_cassettes/Actions/can_current.yml +37 -0
- data/spec/support/vcr_cassettes/Actions/can_delete.yml +39 -0
- data/spec/support/vcr_cassettes/Actions/can_find.yml +38 -0
- data/spec/support/vcr_cassettes/Actions/can_first.yml +75 -0
- data/spec/support/vcr_cassettes/Actions/can_retrieve.yml +38 -0
- data/spec/support/vcr_cassettes/Actions/can_update.yml +39 -0
- data/spec/support/vcr_cassettes/Authentication/can_be_closed.yml +67 -0
- data/spec/support/vcr_cassettes/Authentication/can_use_just_a_token.yml +36 -0
- data/spec/support/vcr_cassettes/Authentication/handles_session_timeout_error.yml +101 -0
- data/spec/support/vcr_cassettes/Authentication/happens_lazily.yml +34 -0
- data/spec/support/vcr_cassettes/Error/is_raised_on_a_bad_request.yml +39 -0
- data/spec/support/vcr_cassettes/Error/is_raised_on_a_forbidden_request.yml +35 -0
- data/spec/support/vcr_cassettes/Error/is_raised_on_an_internal_server_error.yml +69 -0
- data/spec/support/vcr_cassettes/Error/is_raised_on_incorrect_authentication_details.yml +39 -0
- data/spec/support/vcr_cassettes/Error/is_raised_when_a_resource_is_not_found.yml +37 -0
- data/spec/support/vcr_cassettes/Error/is_raised_when_too_many_requests_have_been_issued.yml +34 -0
- data/spec/support/vcr_cassettes/Rates/can_find.yml +36 -0
- data/spec/support/vcr_cassettes/Rates/can_provided_detailed_rate.yml +36 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_beneficiary_required_details.yml +36 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_conversion_dates.yml +46 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_currencies.yml +47 -0
- data/spec/support/vcr_cassettes/Reference/can_retrieve_settlement_accounts.yml +39 -0
- metadata +230 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurrencyCloud do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
CurrencyCloud.environment = nil
|
7
|
+
CurrencyCloud.login_id = nil
|
8
|
+
CurrencyCloud.api_key = nil
|
9
|
+
CurrencyCloud.reset_session
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#environment" do
|
13
|
+
|
14
|
+
it "can set the environment" do
|
15
|
+
CurrencyCloud.environment = :development
|
16
|
+
expect(CurrencyCloud.environment).to eq(:development)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#login_id" do
|
22
|
+
|
23
|
+
it "can set the login_id" do
|
24
|
+
CurrencyCloud.login_id = 'test@example.com'
|
25
|
+
expect(CurrencyCloud.login_id).to eq('test@example.com')
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#api_key" do
|
31
|
+
|
32
|
+
it "can set the api_key" do
|
33
|
+
CurrencyCloud.api_key = 'e3b0d6895f91f46d9eaf5c95aa0f64dca9007b7ab0778721b6cdc0a8bc7c563b'
|
34
|
+
expect(CurrencyCloud.api_key).to eq('e3b0d6895f91f46d9eaf5c95aa0f64dca9007b7ab0778721b6cdc0a8bc7c563b')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#session" do
|
40
|
+
|
41
|
+
it "returns a session object" do
|
42
|
+
CurrencyCloud.environment = :demonstration
|
43
|
+
CurrencyCloud.login_id = 'test@example.com'
|
44
|
+
CurrencyCloud.api_key = 'e3b0d6895f91f46d9eaf5c95aa0f64dca9007b7ab0778721b6cdc0a8bc7c563b'
|
45
|
+
|
46
|
+
request_handler = double('RequestHandler')
|
47
|
+
expect(request_handler).to receive(:post).and_return({'auth_token' => '123'})
|
48
|
+
expect(CurrencyCloud::RequestHandler).to receive(:new).and_return(request_handler)
|
49
|
+
|
50
|
+
expect(CurrencyCloud.session).to be_a(CurrencyCloud::Session)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises an error if the environment is not set" do
|
54
|
+
CurrencyCloud.environment = nil
|
55
|
+
expect { CurrencyCloud.session }
|
56
|
+
.to raise_error(CurrencyCloud::ConfigError, "'' is not a valid environment, must be one of: production, demonstration, uat")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raises an error if the environment is invalid" do
|
60
|
+
CurrencyCloud.environment = :invalid
|
61
|
+
expect { CurrencyCloud.session }
|
62
|
+
.to raise_error(CurrencyCloud::ConfigError, "'invalid' is not a valid environment, must be one of: production, demonstration, uat")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises an error if the login_id is not set" do
|
66
|
+
CurrencyCloud.environment = :demonstration
|
67
|
+
expect { CurrencyCloud.session }
|
68
|
+
.to raise_error(CurrencyCloud::ConfigError, "login_id must be set using CurrencyCloud.login_id=")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "raises an error if the api_key is not set" do
|
72
|
+
CurrencyCloud.environment = :demonstration
|
73
|
+
CurrencyCloud.login_id = 'test@example.com'
|
74
|
+
expect { CurrencyCloud.session }
|
75
|
+
.to raise_error(CurrencyCloud::ConfigError, "api_key must be set using CurrencyCloud.api_key=")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Actions', :vcr => true do
|
4
|
+
before do
|
5
|
+
CurrencyCloud.reset_session
|
6
|
+
CurrencyCloud.environment = :demonstration
|
7
|
+
CurrencyCloud.token = '4df5b3e5882a412f148dcd08fa4e5b73'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can #create" do
|
11
|
+
params = {
|
12
|
+
:bank_account_holder_name => 'Test User',
|
13
|
+
:bank_country => 'GB',
|
14
|
+
:currency => 'GBP',
|
15
|
+
:name => 'Test User',
|
16
|
+
:account_number => '12345678',
|
17
|
+
:routing_code_type_1 => 'sort_code',
|
18
|
+
:routing_code_value_1 => '123456',
|
19
|
+
:payment_types => ['regular']
|
20
|
+
}
|
21
|
+
|
22
|
+
beneficiary = CurrencyCloud::Beneficiary.create(params)
|
23
|
+
expect(beneficiary).to be_a_kind_of(CurrencyCloud::Beneficiary)
|
24
|
+
|
25
|
+
expect(beneficiary.id).to eq('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
26
|
+
expect(beneficiary.bank_account_holder_name).to eq('Test User')
|
27
|
+
expect(beneficiary.payment_types).to include('regular')
|
28
|
+
expect(beneficiary.created_at).to eq('2015-04-25T09:21:00+00:00')
|
29
|
+
expect(beneficiary.updated_at).to eq('2015-04-25T09:21:00+00:00')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can #retrieve" do
|
33
|
+
beneficiary = CurrencyCloud::Beneficiary.retrieve('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
34
|
+
expect(beneficiary).to be_a_kind_of(CurrencyCloud::Beneficiary)
|
35
|
+
|
36
|
+
expect(beneficiary.id).to eq('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
37
|
+
expect(beneficiary.bank_account_holder_name).to eq('Test User')
|
38
|
+
expect(beneficiary.payment_types).to include('regular')
|
39
|
+
expect(beneficiary.created_at).to eq('2015-04-25T09:21:00+00:00')
|
40
|
+
expect(beneficiary.updated_at).to eq('2015-04-25T09:21:00+00:00')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can #first" do
|
44
|
+
beneficiary = CurrencyCloud::Beneficiary.first(:bank_account_holder_name => 'Test User')
|
45
|
+
expect(beneficiary).to be_a_kind_of(CurrencyCloud::Beneficiary)
|
46
|
+
|
47
|
+
expect(beneficiary.id).to eq('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
48
|
+
expect(beneficiary.bank_account_holder_name).to eq('Test User')
|
49
|
+
expect(beneficiary.payment_types).to include('regular')
|
50
|
+
expect(beneficiary.created_at).to eq('2015-04-25T09:21:00+00:00')
|
51
|
+
expect(beneficiary.updated_at).to eq('2015-04-25T10:58:21+00:00')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can #find" do
|
55
|
+
beneficiaries = CurrencyCloud::Beneficiary.find
|
56
|
+
expect(beneficiaries).to_not be_empty
|
57
|
+
expect(beneficiaries.length).to eq(1)
|
58
|
+
|
59
|
+
beneficiaries.each do |b|
|
60
|
+
expect(b).to_not be_nil
|
61
|
+
expect(b).to be_a_kind_of(CurrencyCloud::Beneficiary)
|
62
|
+
end
|
63
|
+
|
64
|
+
pagination = beneficiaries.pagination
|
65
|
+
expect(pagination.total_entries).to eq(1)
|
66
|
+
expect(pagination.total_pages).to eq(1)
|
67
|
+
expect(pagination.current_page).to eq(1)
|
68
|
+
expect(pagination.per_page).to eq(25)
|
69
|
+
expect(pagination.previous_page).to eq(-1)
|
70
|
+
expect(pagination.next_page).to eq(-1)
|
71
|
+
expect(pagination.order).to eq('created_at')
|
72
|
+
expect(pagination.order_asc_desc).to eq('asc')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "can #update" do
|
76
|
+
beneficiary = CurrencyCloud::Beneficiary.update('081596c9-02de-483e-9f2a-4cf55dcdf98c', :bank_account_holder_name => 'Test User 2')
|
77
|
+
expect(beneficiary).to be_a_kind_of(CurrencyCloud::Beneficiary)
|
78
|
+
expect(beneficiary.bank_account_holder_name).to eq('Test User 2')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "can #delete" do
|
82
|
+
beneficiary = CurrencyCloud::Beneficiary.delete('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
83
|
+
expect(beneficiary).to be_a_kind_of(CurrencyCloud::Beneficiary)
|
84
|
+
|
85
|
+
expect(beneficiary.id).to eq('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
86
|
+
expect(beneficiary.bank_account_holder_name).to eq('Test User 2')
|
87
|
+
expect(beneficiary.payment_types).to include('regular')
|
88
|
+
expect(beneficiary.created_at).to eq('2015-04-25T09:21:00+00:00')
|
89
|
+
expect(beneficiary.updated_at).to eq('2015-04-25T11:06:27+00:00')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "can #current" do
|
93
|
+
account = CurrencyCloud::Account.current
|
94
|
+
|
95
|
+
expect(account).to be_a_kind_of(CurrencyCloud::Account)
|
96
|
+
expect(account.id).to eq('8ec3a69b-02d1-4f09-9a6b-6bd54a61b3a8')
|
97
|
+
expect(account.postal_code).to be_nil
|
98
|
+
expect(account.created_at).to eq('2015-04-24T15:57:55+00:00')
|
99
|
+
expect(account.updated_at).to eq('2015-04-24T15:57:55+00:00')
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Authentication', :vcr => true do
|
4
|
+
before(:each) do
|
5
|
+
CurrencyCloud.reset_session
|
6
|
+
CurrencyCloud.environment = :demonstration
|
7
|
+
CurrencyCloud.login_id = 'rjnienaber@gmail.com'
|
8
|
+
CurrencyCloud.api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb65f02f129fd87eafa45ded8ae257528f0'
|
9
|
+
CurrencyCloud.token = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'happens lazily' do
|
13
|
+
expect(CurrencyCloud.session).to_not be_nil
|
14
|
+
expect(CurrencyCloud.session.token).to eq('57ef449f6316f2f54dfec37c2006fe50')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can use just a token' do
|
18
|
+
CurrencyCloud.login_id = nil
|
19
|
+
CurrencyCloud.api_key = nil
|
20
|
+
CurrencyCloud.token = '7fbba909f66ee6721b2e20a5fa1ccae7'
|
21
|
+
|
22
|
+
response = CurrencyCloud::Beneficiary.find
|
23
|
+
expect(response).to_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can be closed' do
|
27
|
+
CurrencyCloud.session
|
28
|
+
expect(CurrencyCloud.close_session).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'handles session timeout error' do
|
32
|
+
CurrencyCloud.token = '3907f05da86533710efc589d58f51f45'
|
33
|
+
|
34
|
+
response = CurrencyCloud::Beneficiary.find
|
35
|
+
expect(response).to_not be_nil
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
describe 'Error', :vcr => true do
|
5
|
+
before(:each) do
|
6
|
+
CurrencyCloud.reset_session
|
7
|
+
CurrencyCloud.environment = :demonstration
|
8
|
+
CurrencyCloud.login_id = 'rjnienaber@gmail.com'
|
9
|
+
CurrencyCloud.api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb65f02f129fd87eafa45ded8ae257528f0'
|
10
|
+
CurrencyCloud.token = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is raised on a bad request' do
|
14
|
+
CurrencyCloud.login_id = 'non-existent-login-id'
|
15
|
+
CurrencyCloud.api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb57528f0'
|
16
|
+
|
17
|
+
error = nil
|
18
|
+
begin
|
19
|
+
CurrencyCloud.session
|
20
|
+
raise 'Should have failed'
|
21
|
+
rescue CurrencyCloud::BadRequestError => error
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(error.code).to eq('auth_invalid_user_login_details')
|
25
|
+
expect(error.raw_response).to_not be_nil
|
26
|
+
expect(error.status_code).to eq(400)
|
27
|
+
expect(error.messages.length).to eq(1)
|
28
|
+
|
29
|
+
error_message = error.messages[0]
|
30
|
+
expect(error_message.field).to eq('api_key')
|
31
|
+
expect(error_message.code).to eq('api_key_length_is_invalid')
|
32
|
+
expect(error_message.message).to eq('api_key should be 64 character(s) long')
|
33
|
+
expect(error_message.params).to include("length" => 64)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is raised on incorrect authentication details' do
|
37
|
+
CurrencyCloud.login_id = 'non-existent-login-id'
|
38
|
+
CurrencyCloud.api_key = 'efb5ae2af84978b7a37f18dd61c8bbe139b403009faea83484405a3dcb64c4d8'
|
39
|
+
|
40
|
+
error = nil
|
41
|
+
begin
|
42
|
+
CurrencyCloud.session
|
43
|
+
raise 'Should have failed'
|
44
|
+
rescue CurrencyCloud::AuthenticationError => error
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(error.code).to eq('auth_failed')
|
48
|
+
expect(error.raw_response).to_not be_nil
|
49
|
+
expect(error.status_code).to eq(401)
|
50
|
+
expect(error.messages.length).to eq(1)
|
51
|
+
|
52
|
+
error_message = error.messages[0]
|
53
|
+
expect(error_message.field).to eq('username')
|
54
|
+
expect(error_message.code).to eq('invalid_supplied_credentials')
|
55
|
+
expect(error_message.message).to eq('Authentication failed with the supplied credentials')
|
56
|
+
expect(error_message.params).to be_empty
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'is raised on unexpected error' do
|
60
|
+
allow(HTTParty).to receive(:post).and_raise(Timeout::Error)
|
61
|
+
|
62
|
+
error = nil
|
63
|
+
begin
|
64
|
+
CurrencyCloud.session
|
65
|
+
raise 'Should have failed'
|
66
|
+
rescue CurrencyCloud::UnexpectedError => error
|
67
|
+
end
|
68
|
+
|
69
|
+
expect(error.inner_error).to_not be_nil
|
70
|
+
expect(error.inner_error.class).to eq(Timeout::Error)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'is raised on a forbidden request' do
|
74
|
+
error = nil
|
75
|
+
begin
|
76
|
+
CurrencyCloud.session
|
77
|
+
raise 'Should have failed'
|
78
|
+
rescue CurrencyCloud::ForbiddenError => error
|
79
|
+
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(403)
|
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
|
+
end
|
92
|
+
|
93
|
+
it 'is raised when a resource is not found' do
|
94
|
+
CurrencyCloud.token = '656485646b068f6e9c81e3d885fa54f5'
|
95
|
+
error = nil
|
96
|
+
begin
|
97
|
+
CurrencyCloud::Beneficiary.retrieve('081596c9-02de-483e-9f2a-4cf55dcdf98c')
|
98
|
+
raise 'Should fail'
|
99
|
+
rescue CurrencyCloud::NotFoundError => error
|
100
|
+
end
|
101
|
+
|
102
|
+
expect(error.code).to eq('beneficiary_not_found')
|
103
|
+
expect(error.raw_response).to_not be_nil
|
104
|
+
expect(error.status_code).to eq(404)
|
105
|
+
expect(error.messages.length).to eq(1)
|
106
|
+
|
107
|
+
error_message = error.messages[0]
|
108
|
+
expect(error_message.field).to eq('id')
|
109
|
+
expect(error_message.code).to eq('beneficiary_not_found')
|
110
|
+
expect(error_message.message).to eq('Beneficiary was not found for this id')
|
111
|
+
expect(error_message.params).to be_empty
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'is raised on an internal server error' do
|
115
|
+
|
116
|
+
error = nil
|
117
|
+
begin
|
118
|
+
CurrencyCloud.session
|
119
|
+
raise 'Should have failed'
|
120
|
+
rescue CurrencyCloud::InternalApplicationError => error
|
121
|
+
end
|
122
|
+
|
123
|
+
expect(error.code).to eq('internal_application_error')
|
124
|
+
expect(error.raw_response).to_not be_nil
|
125
|
+
expect(error.status_code).to eq(500)
|
126
|
+
expect(error.messages.length).to eq(1)
|
127
|
+
|
128
|
+
error_message = error.messages[0]
|
129
|
+
expect(error_message.field).to eq('base')
|
130
|
+
expect(error_message.code).to eq('internal_application_error')
|
131
|
+
expect(error_message.message).to eq('A general application error occurred')
|
132
|
+
expect(error_message.params).to include("request_id" => 2771875643610572878)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'is raised when too many requests have been issued' do
|
136
|
+
CurrencyCloud.login_id = 'rjnienaber@gmail.com2'
|
137
|
+
|
138
|
+
error = nil
|
139
|
+
begin
|
140
|
+
CurrencyCloud.session
|
141
|
+
|
142
|
+
raise 'Should have failed'
|
143
|
+
rescue CurrencyCloud::TooManyRequestsError => error
|
144
|
+
end
|
145
|
+
|
146
|
+
expect(error.code).to eq('too_many_requests')
|
147
|
+
expect(error.raw_response).to_not be_nil
|
148
|
+
expect(error.status_code).to eq(429)
|
149
|
+
expect(error.messages.length).to eq(1)
|
150
|
+
|
151
|
+
error_message = error.messages[0]
|
152
|
+
expect(error_message.field).to eq('base')
|
153
|
+
expect(error_message.code).to eq('too_many_requests')
|
154
|
+
expect(error_message.message).to eq('Too many requests have been made to the api. Please refer to the Developer Center for more information')
|
155
|
+
expect(error_message.params).to be_empty
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Rates', :vcr => true do
|
4
|
+
before do
|
5
|
+
CurrencyCloud.reset_session
|
6
|
+
CurrencyCloud.environment = :demonstration
|
7
|
+
CurrencyCloud.token = '242993ca94b9d1c6c1d8f7d3275a6f36'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can #find' do
|
11
|
+
rates = CurrencyCloud::Rate.find(currency_pair: 'GBPUSD,EURGBP')
|
12
|
+
|
13
|
+
expect(rates).to_not be_nil
|
14
|
+
expect(rates.currencies).to_not be_empty
|
15
|
+
|
16
|
+
currencies = rates.currencies
|
17
|
+
expect(currencies.length).to eq(2)
|
18
|
+
|
19
|
+
currencies.each do |b|
|
20
|
+
expect(b).to_not be_nil
|
21
|
+
expect(b).to be_a_kind_of(CurrencyCloud::Rate)
|
22
|
+
end
|
23
|
+
|
24
|
+
rate = currencies.first
|
25
|
+
expect(rate.currency_pair).to eq('EURGBP')
|
26
|
+
expect(rate.bid).to eq('0.71445')
|
27
|
+
expect(rate.offer).to eq('0.71508')
|
28
|
+
|
29
|
+
expect(rates.unavailable).to be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can provided #detailed rate' do
|
33
|
+
detailed_rate = CurrencyCloud::Rate.detailed(buy_currency: 'GBP', sell_currency: 'USD', fixed_side: 'buy', amount: '10000')
|
34
|
+
|
35
|
+
expect(detailed_rate).to be_a_kind_of(CurrencyCloud::Rate)
|
36
|
+
expect(detailed_rate.client_sell_amount).to eq('15234.00')
|
37
|
+
expect(detailed_rate.settlement_cut_off_time).to eq('2015-04-29T14:00:00Z')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Reference', :vcr => true do
|
4
|
+
before do
|
5
|
+
CurrencyCloud.reset_session
|
6
|
+
CurrencyCloud.environment = :demonstration
|
7
|
+
CurrencyCloud.token = '1c9da5726314246acfb09ec5651307a5'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can retrieve #beneficiary_required_details' do
|
11
|
+
details = CurrencyCloud::Reference.beneficiary_required_details(:currency => 'GBP', :bank_account_country => 'GB', :beneficiary_country => 'GB')
|
12
|
+
expect(details).to_not be_empty
|
13
|
+
|
14
|
+
details = details.first
|
15
|
+
expect(details['payment_type']).to eq('priority')
|
16
|
+
expect(details["payment_type"]).to eq("priority")
|
17
|
+
expect(details["beneficiary_entity_type"]).to eq("individual")
|
18
|
+
expect(details["beneficiary_address"]).to eq("^.{1,255}")
|
19
|
+
expect(details["beneficiary_city"]).to eq("^.{1,255}")
|
20
|
+
expect(details["beneficiary_country"]).to eq("^[A-z]{2}$")
|
21
|
+
expect(details["beneficiary_first_name"]).to eq("^.{1,255}")
|
22
|
+
expect(details["beneficiary_last_name"]).to eq("^.{1,255}")
|
23
|
+
expect(details["acct_number"]).to eq("^[0-9A-Z]{1,50}$")
|
24
|
+
expect(details["sort_code"]).to eq("^\\d{6}$")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can retrieve #conversion_dates' do
|
28
|
+
dates = CurrencyCloud::Reference.conversion_dates(:conversion_pair => 'GBPUSD')
|
29
|
+
|
30
|
+
expect(dates.invalid_conversion_dates).to_not be_empty
|
31
|
+
invalid_conversion_date = dates.invalid_conversion_dates.first
|
32
|
+
expect(invalid_conversion_date).to eq(["2015-05-02", "No trading on Saturday"])
|
33
|
+
expect(dates.first_conversion_date).to eq('2015-04-30')
|
34
|
+
expect(dates.default_conversion_date).to eq('2015-04-30')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can retrieve #currencies' do
|
38
|
+
currencies = CurrencyCloud::Reference.currencies
|
39
|
+
expect(currencies).to_not be_empty
|
40
|
+
|
41
|
+
currency = currencies.first
|
42
|
+
expect(currency).to be_a_kind_of(CurrencyCloud::Currency)
|
43
|
+
expect(currency.code).to eq('AED')
|
44
|
+
expect(currency.name).to eq('United Arab Emirates Dirham')
|
45
|
+
expect(currency.decimal_places).to eq(2)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can retrieve #settlement_accounts' do
|
49
|
+
settlement_accounts = CurrencyCloud::Reference.settlement_accounts(:currency => 'GBP')
|
50
|
+
expect(settlement_accounts).to_not be_empty
|
51
|
+
|
52
|
+
settlement_account = settlement_accounts.first
|
53
|
+
expect(settlement_account).to be_a_kind_of(CurrencyCloud::SettlementAccount)
|
54
|
+
expect(settlement_account.bank_account_holder_name).to eq("The Currency Cloud GBP - Client Seg A/C")
|
55
|
+
expect(settlement_account.bank_address).to be_empty
|
56
|
+
end
|
57
|
+
end
|