uphold 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +335 -0
  8. data/Rakefile +14 -0
  9. data/lib/uphold/api/auth_token.rb +17 -0
  10. data/lib/uphold/api/card.rb +36 -0
  11. data/lib/uphold/api/contact.rb +34 -0
  12. data/lib/uphold/api/endpoints.rb +26 -0
  13. data/lib/uphold/api/private_transaction.rb +58 -0
  14. data/lib/uphold/api/public_transaction.rb +23 -0
  15. data/lib/uphold/api/ticker.rb +23 -0
  16. data/lib/uphold/api/transparency.rb +15 -0
  17. data/lib/uphold/api/user.rb +23 -0
  18. data/lib/uphold/api.rb +22 -0
  19. data/lib/uphold/client.rb +14 -0
  20. data/lib/uphold/entities/asset.rb +9 -0
  21. data/lib/uphold/entities/auth_token.rb +9 -0
  22. data/lib/uphold/entities/base_entity.rb +27 -0
  23. data/lib/uphold/entities/card.rb +15 -0
  24. data/lib/uphold/entities/contact.rb +13 -0
  25. data/lib/uphold/entities/error.rb +8 -0
  26. data/lib/uphold/entities/ledger_entry.rb +10 -0
  27. data/lib/uphold/entities/oauth_error.rb +9 -0
  28. data/lib/uphold/entities/phone.rb +12 -0
  29. data/lib/uphold/entities/ticker.rb +10 -0
  30. data/lib/uphold/entities/transaction.rb +17 -0
  31. data/lib/uphold/entities/user.rb +18 -0
  32. data/lib/uphold/helpers.rb +23 -0
  33. data/lib/uphold/options.rb +39 -0
  34. data/lib/uphold/pagination.rb +9 -0
  35. data/lib/uphold/request.rb +70 -0
  36. data/lib/uphold/request_data.rb +7 -0
  37. data/lib/uphold/version.rb +3 -0
  38. data/lib/uphold.rb +46 -0
  39. data/spec/fixtures/vcr_cassettes/ledger.yml +56 -0
  40. data/spec/fixtures/vcr_cassettes/me/card.yml +61 -0
  41. data/spec/fixtures/vcr_cassettes/me/cards.yml +67 -0
  42. data/spec/fixtures/vcr_cassettes/me/contact.yml +61 -0
  43. data/spec/fixtures/vcr_cassettes/me/contacts.yml +61 -0
  44. data/spec/fixtures/vcr_cassettes/me/created_card.yml +61 -0
  45. data/spec/fixtures/vcr_cassettes/me/created_contact.yml +61 -0
  46. data/spec/fixtures/vcr_cassettes/me/phones.yml +61 -0
  47. data/spec/fixtures/vcr_cassettes/me/transactions/cancel.yml +61 -0
  48. data/spec/fixtures/vcr_cassettes/me/transactions/commit.yml +62 -0
  49. data/spec/fixtures/vcr_cassettes/me/transactions/create.yml +61 -0
  50. data/spec/fixtures/vcr_cassettes/me/transactions/create_waiting_cancel.yml +118 -0
  51. data/spec/fixtures/vcr_cassettes/me/transactions/create_waiting_resend.yml +118 -0
  52. data/spec/fixtures/vcr_cassettes/me/transactions/resend.yml +61 -0
  53. data/spec/fixtures/vcr_cassettes/me.yml +185 -0
  54. data/spec/fixtures/vcr_cassettes/pats.yml +61 -0
  55. data/spec/fixtures/vcr_cassettes/reserve/transaction.yml +60 -0
  56. data/spec/fixtures/vcr_cassettes/reserve/transactions.yml +60 -0
  57. data/spec/fixtures/vcr_cassettes/tickers.yml +60 -0
  58. data/spec/fixtures/vcr_cassettes/transparency.yml +60 -0
  59. data/spec/integration/api/auth_token_spec.rb +20 -0
  60. data/spec/integration/api/card_spec.rb +47 -0
  61. data/spec/integration/api/contact_spec.rb +53 -0
  62. data/spec/integration/api/private_transactions_spec.rb +74 -0
  63. data/spec/integration/api/public_transaction_spec.rb +35 -0
  64. data/spec/integration/api/ticker_spec.rb +21 -0
  65. data/spec/integration/api/transparency_spec.rb +33 -0
  66. data/spec/integration/api/user_spec.rb +32 -0
  67. data/spec/spec_helper.rb +26 -0
  68. data/spec/support/vcr.rb +8 -0
  69. data/spec/support/webmock.rb +11 -0
  70. data/spec/unit/api/auth_spec.rb +21 -0
  71. data/spec/unit/api/card_spec.rb +47 -0
  72. data/spec/unit/api/contact_spec.rb +53 -0
  73. data/spec/unit/api/private_transaction_spec.rb +114 -0
  74. data/spec/unit/api/public_transaction_spec.rb +34 -0
  75. data/spec/unit/api/ticker_spec.rb +34 -0
  76. data/spec/unit/api/transparency_spec.rb +33 -0
  77. data/spec/unit/api/user_spec.rb +33 -0
  78. data/spec/unit/client_spec.rb +33 -0
  79. data/spec/unit/entities/base_entity_spec.rb +36 -0
  80. data/spec/unit/helper_spec.rb +37 -0
  81. data/spec/unit/request_spec.rb +94 -0
  82. data/uphold.gemspec +30 -0
  83. metadata +296 -0
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.uphold.com/v0/reserve/statistics
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer <UPHOLD_AUTH_TOKEN>
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - cloudflare-nginx
19
+ Date:
20
+ - Tue, 27 Jan 2015 17:53:26 GMT
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Content-Length:
24
+ - '5014'
25
+ Connection:
26
+ - keep-alive
27
+ Set-Cookie:
28
+ - __cfduid=d7978a65b9f913d33a9c44a2636303f921422381205; expires=Wed, 27-Jan-16
29
+ 17:53:25 GMT; path=/; domain=.uphold.com; HttpOnly
30
+ X-Content-Security-Policy:
31
+ - default-src "none"
32
+ Content-Security-Policy:
33
+ - default-src "none"
34
+ X-Webkit-Csp:
35
+ - default-src "none"
36
+ Strict-Transport-Security:
37
+ - max-age=31536000
38
+ X-Xss-Protection:
39
+ - 1; mode=block
40
+ X-Content-Type-Options:
41
+ - nosniff
42
+ - nosniff
43
+ X-Frame-Options:
44
+ - DENY
45
+ X-Uphold-Request-Id:
46
+ - 96f0ec67-bab8-4d0c-af23-ee44c83d9f68
47
+ X-Ratelimit-Limit:
48
+ - '300'
49
+ X-Ratelimit-Remaining:
50
+ - '299'
51
+ X-Ratelimit-Reset:
52
+ - '1422381505'
53
+ Cf-Ray:
54
+ - 1af6cf43e12e0db7-MAD
55
+ body:
56
+ encoding: UTF-8
57
+ string: '[{"currency":"BTC","values":[{"assets":"2956.170063","currency":"BTC","liabilities":"2100.194772","rate":"1.00"},{"assets":"782010.45","currency":"USD","liabilities":"555575.02","rate":"264.53500"},{"assets":"689330.03","currency":"EUR","liabilities":"489730.72","rate":"233.18231"},{"assets":"514768.42","currency":"GBP","liabilities":"365714.39","rate":"174.13280"},{"assets":"4881543.83","currency":"CNY","liabilities":"3468065.95","rate":"1651.30683"},{"assets":"92155630.48","currency":"JPY","liabilities":"65471460.44","rate":"31173.99480"},{"assets":"599.43912564","currency":"XAU","liabilities":"425.86822749","rate":"0.20277401"}],"totals":{"commissions":"107.23285","transactions":"25676.77009","assets":"4217.24016714","liabilities":"3475.47358198"}},{"currency":"USD","values":[{"assets":"1014.49210879","currency":"BTC","liabilities":"844.99087077","rate":"0.00378021"},{"assets":"268368.67","currency":"USD","liabilities":"223529.66","rate":"1.00"},{"assets":"236562.80","currency":"EUR","liabilities":"197037.91","rate":"0.88148"},{"assets":"176657.12","currency":"GBP","liabilities":"147141.27","rate":"0.65826"},{"assets":"1675237.75","currency":"CNY","liabilities":"1395339.20","rate":"6.24230"},{"assets":"31625771.73","currency":"JPY","liabilities":"26341741.02","rate":"117.84450"},{"assets":"205.71423425","currency":"XAU","liabilities":"171.34352098","rate":"0.00076653"}],"totals":{"commissions":"27242.14","transactions":"6666477.64","assets":"1115607.63","liabilities":"919384.40"}},{"currency":"EUR","values":[{"assets":"0.00","currency":"BTC","liabilities":"35.32129964","rate":"0.00428845"},{"assets":"0.00","currency":"USD","liabilities":"9343.72","rate":"1.13445"},{"assets":"0.00","currency":"EUR","liabilities":"8236.34","rate":"1.00"},{"assets":"0.00","currency":"GBP","liabilities":"6150.90","rate":"0.74680"},{"assets":"0.00","currency":"CNY","liabilities":"58326.47","rate":"7.08160"},{"assets":"0.00","currency":"JPY","liabilities":"1101105.59","rate":"133.68870"},{"assets":"0.00","currency":"XAU","liabilities":"7.16229732","rate":"0.00086958"}],"totals":{"commissions":"22930.89","transactions":"5595783.62","assets":"983390.75","liabilities":"810420.12"}},{"currency":"GBP","values":[{"assets":"0.00","currency":"BTC","liabilities":"273.01755911","rate":"0.0057427"},{"assets":"0.00","currency":"USD","liabilities":"72222.70","rate":"1.51915"},{"assets":"0.00","currency":"EUR","liabilities":"63660.31","rate":"1.33904"},{"assets":"0.00","currency":"GBP","liabilities":"47541.52","rate":"1.00"},{"assets":"0.00","currency":"CNY","liabilities":"450826.73","rate":"9.48280"},{"assets":"0.00","currency":"JPY","liabilities":"8510852.01","rate":"179.01935"},{"assets":"0.00","currency":"XAU","liabilities":"55.36129618","rate":"0.00116447"}],"totals":{"commissions":"17756.96","transactions":"4338799.64","assets":"734363.04","liabilities":"605196.91"}},{"currency":"CNY","values":[{"assets":"0.00","currency":"BTC","liabilities":"9.36598182","rate":"0.00060555"},{"assets":"0.00","currency":"USD","liabilities":"2477.63","rate":"0.16019"},{"assets":"0.00","currency":"EUR","liabilities":"2183.98","rate":"0.14121"},{"assets":"0.00","currency":"GBP","liabilities":"1630.96","rate":"0.10545"},{"assets":"0.00","currency":"CNY","liabilities":"15466.10","rate":"1.00"},{"assets":"0.00","currency":"JPY","liabilities":"291813.21","rate":"18.86792"},{"assets":"0.00","currency":"XAU","liabilities":"1.89919247","rate":"0.00012279"}],"totals":{"commissions":"168786.32","transactions":"41287185.08","assets":"6963957.51","liabilities":"5739069.19"}},{"currency":"JPY","values":[{"assets":"0.00","currency":"BTC","liabilities":"5.2773735","rate":"0.00003205"},{"assets":"0.00","currency":"USD","liabilities":"1396.05","rate":"0.00848"},{"assets":"0.00","currency":"EUR","liabilities":"1230.59","rate":"0.00748"},{"assets":"0.00","currency":"GBP","liabilities":"918.99","rate":"0.00558"},{"assets":"0.00","currency":"CNY","liabilities":"8719.38","rate":"0.05300"},{"assets":"0.00","currency":"JPY","liabilities":"164516.59","rate":"1.00"},{"assets":"0.00","currency":"XAU","liabilities":"1.07012252","rate":"0.0000065"}],"totals":{"commissions":"3185951.27","transactions":"780072808.88","assets":"131468223.36","liabilities":"108344036.46"}},{"currency":"XAU","values":[{"assets":"246.57799535","currency":"BTC","liabilities":"207.30572514","rate":"4.9315495"},{"assets":"65228.51","currency":"USD","liabilities":"54839.62","rate":"1304.57025"},{"assets":"57497.92","currency":"EUR","liabilities":"48340.27","rate":"1149.95258"},{"assets":"42937.50","currency":"GBP","liabilities":"36098.88","rate":"858.74641"},{"assets":"407175.93","currency":"CNY","liabilities":"342325.36","rate":"8143.51887"},{"assets":"7686821.15","currency":"JPY","liabilities":"6462547.60","rate":"153736.42882"},{"assets":"50.00","currency":"XAU","liabilities":"42.036544","rate":"1.00"}],"totals":{"commissions":"18.24159","transactions":"4371.57899","assets":"855.15335989","liabilities":"704.74120096"}}]'
58
+ http_version:
59
+ recorded_at: Tue, 27 Jan 2015 17:53:27 GMT
60
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe AuthToken do
6
+ let(:client) { Client.new }
7
+
8
+ context '#generate_access_token' do
9
+ it 'generates a personal access token' do
10
+ VCR.use_cassette('pats') do
11
+ token = client.generate_access_token(username: 'example', password: 'Password123', otp: '5960110')
12
+
13
+ expect(token).to be_a(Entities::AuthToken)
14
+ expect(token.access_token).to be_a(String)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe Card do
6
+ let(:client) { Client.new }
7
+
8
+ context '#all_cards' do
9
+ it 'gets all the cards' do
10
+ VCR.use_cassette('me/cards') do
11
+ cards = client.all_cards
12
+
13
+ expect(cards).to be_a(Array)
14
+ expect(cards.first).to be_a(Entities::Card)
15
+ expect(cards.first.id).to be_a(String)
16
+ end
17
+ end
18
+ end
19
+
20
+ context '#find_card' do
21
+ it 'gets a specific card' do
22
+ VCR.use_cassette('me/card') do
23
+ id = 'd9cfb5ec-27b3-427a-8ee6-084a7c6b5d2a'
24
+
25
+ card = client.find_card(id: id)
26
+
27
+ expect(card).to be_a(Entities::Card)
28
+ expect(card.id).to eq id
29
+ end
30
+ end
31
+ end
32
+
33
+ context '#create_card' do
34
+ it 'creates a card' do
35
+ VCR.use_cassette('me/created_card') do
36
+ data = { label: 'New card', currency: 'EUR' }
37
+
38
+ card = client.create_card(data)
39
+
40
+ expect(card).to be_a(Entities::Card)
41
+ expect(card.label).to eq data[:label]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe Contact do
6
+ let(:client) { Uphold::Client.new }
7
+
8
+ context '#all_contacts' do
9
+ it 'gets all the contacts' do
10
+ VCR.use_cassette('me/contacts') do
11
+ contacts = client.all_contacts
12
+
13
+ expect(contacts).to be_a(Array)
14
+ expect(contacts.first).to be_a(Entities::Contact)
15
+ expect(contacts.first.id).to be_a(String)
16
+ end
17
+ end
18
+ end
19
+
20
+ context '#find_contact' do
21
+ it 'gets a specific contact' do
22
+ VCR.use_cassette('me/contact') do
23
+ id = '6a0fc9d7-605b-43a3-8675-f1188ab2e005'
24
+
25
+ contact = client.find_contact(id: id)
26
+
27
+ expect(contact).to be_a(Entities::Contact)
28
+ expect(contact.id).to eq id
29
+ end
30
+ end
31
+ end
32
+
33
+ context '#create_contact' do
34
+ it 'creates a contact' do
35
+ VCR.use_cassette('me/created_contact') do
36
+ data = {
37
+ first_name: 'first-name',
38
+ last_name: 'last-name',
39
+ emails: ['fake@email.com'],
40
+ company: 'company-name',
41
+ addresses: []
42
+ }
43
+
44
+ contact = client.create_contact(data)
45
+
46
+ expect(contact).to be_a(Entities::Contact)
47
+ expect(contact.first_name).to eq(data[:first_name])
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe PrivateTransaction do
6
+ let(:client) { Client.new }
7
+
8
+ context '#commit_transaction' do
9
+ it 'it creates and commits a transaction' do
10
+ card_id = 'a4feff08-2977-40f8-a339-4f546ae5c7e2'
11
+ created_transaction = nil
12
+
13
+ VCR.use_cassette('me/transactions/create') do
14
+ destination = 'a0e20123-47c8-4784-9e71-0defb34d18a7'
15
+ created_transaction = client.create_transaction(card_id: card_id, currency: 'BTC', amount: 0.0001, destination: destination)
16
+
17
+ expect(created_transaction).to be_a(Entities::Transaction)
18
+ expect(created_transaction.id).to be_a(String)
19
+ expect(created_transaction.status).to eq 'pending'
20
+ end
21
+
22
+ VCR.use_cassette('me/transactions/commit') do
23
+ transaction = client.commit_transaction(card_id: card_id, transaction_id: created_transaction.id)
24
+
25
+ expect(transaction).to be_a(Entities::Transaction)
26
+ expect(transaction.id).to eq created_transaction.id
27
+ expect(transaction.status).to eq 'completed'
28
+ end
29
+ end
30
+ end
31
+
32
+ context '#cancel_transaction' do
33
+ it 'cancels a transaction' do
34
+ card_id = 'a4feff08-2977-40f8-a339-4f546ae5c7e2'
35
+ waiting_transaction = create_waiting_transaction(card_id, :cancel)
36
+
37
+ VCR.use_cassette('me/transactions/cancel') do
38
+ transaction = client.cancel_transaction(card_id: card_id, transaction_id: waiting_transaction.id)
39
+
40
+ expect(transaction).to be_a(Entities::Transaction)
41
+ expect(transaction.id).to eq waiting_transaction.id
42
+ expect(transaction.status).to eq 'cancelled'
43
+ end
44
+ end
45
+ end
46
+
47
+ context '#resend_transaction' do
48
+ it 'resends a transaction' do
49
+ card_id = 'a4feff08-2977-40f8-a339-4f546ae5c7e2'
50
+ waiting_transaction = create_waiting_transaction(card_id, :resend)
51
+
52
+ VCR.use_cassette('me/transactions/resend') do
53
+ transaction = client.resend_transaction(card_id: card_id, transaction_id: waiting_transaction.id)
54
+
55
+ expect(transaction).to be_a(Entities::Transaction)
56
+ expect(transaction.id).to eq waiting_transaction.id
57
+ expect(transaction.status).to eq 'waiting'
58
+ end
59
+ end
60
+ end
61
+
62
+ def create_waiting_transaction(card_id, action)
63
+ VCR.use_cassette("me/transactions/create_waiting_#{action}") do
64
+ destination = 'non-user@example.com'
65
+ created_transaction = client.create_transaction(card_id: card_id, currency: 'BTC', amount: 0.0001, destination: destination)
66
+ waiting_transaction = client.commit_transaction(card_id: card_id, transaction_id: created_transaction.id)
67
+
68
+ expect(waiting_transaction.status).to eq 'waiting'
69
+ waiting_transaction
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe PublicTransaction do
6
+ let(:client) { Client.new }
7
+
8
+ context '#all_public_transactions' do
9
+ it 'gets all public transactions' do
10
+ VCR.use_cassette('reserve/transactions') do
11
+ transactions = client.all_public_transactions
12
+
13
+ expect(transactions).to be_a(Array)
14
+ expect(transactions.total_size).to eq 2
15
+ expect(transactions.first).to be_a(Entities::Transaction)
16
+ expect(transactions.first.id).to be_a(String)
17
+ end
18
+ end
19
+ end
20
+
21
+ context '#find_public_transaction' do
22
+ it 'gets a public transaction' do
23
+ VCR.use_cassette('reserve/transaction') do
24
+ id = 'a97bb994-6e24-4a89-b653-e0a6d0bcf634'
25
+
26
+ transaction = client.find_public_transaction(id: id)
27
+
28
+ expect(transaction).to be_a(Entities::Transaction)
29
+ expect(transaction.id).to eq id
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe Ticker do
6
+ let(:client) { Uphold::Client.new }
7
+
8
+ context '#all_tickers' do
9
+ it 'gets all the tickers' do
10
+ VCR.use_cassette('tickers') do
11
+ tickers = client.all_tickers
12
+
13
+ expect(tickers).to be_a(Array)
14
+ expect(tickers.first).to be_a(Entities::Ticker)
15
+ expect(tickers.first.ask).to be_a(String)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe Transparency do
6
+ let(:client) { Uphold::Client.new }
7
+
8
+ context '#statistics' do
9
+ it 'gets all the tickers' do
10
+ VCR.use_cassette('transparency') do
11
+ assets = client.statistics
12
+
13
+ expect(assets).to be_a(Array)
14
+ expect(assets.first).to be_a(Entities::Asset)
15
+ expect(assets.first.currency).to be_a(String)
16
+ end
17
+ end
18
+ end
19
+
20
+ context '#ledger' do
21
+ it 'gets all the ledger entries' do
22
+ VCR.use_cassette('ledger') do
23
+ assets = client.ledger
24
+
25
+ expect(assets).to be_a(Array)
26
+ expect(assets.first).to be_a(Entities::LedgerEntry)
27
+ expect(assets.first.type).to be_a(String)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe User do
6
+ let(:client) { Uphold::Client.new }
7
+
8
+ context '#me' do
9
+ it 'gets my personal information' do
10
+ VCR.use_cassette('me') do
11
+ me = client.me
12
+
13
+ expect(me).to be_a(Entities::User)
14
+ expect(me.email).to be_a(String)
15
+ end
16
+ end
17
+ end
18
+
19
+ context '#phones' do
20
+ it 'gets my associated phone numbers' do
21
+ VCR.use_cassette('me/phones') do
22
+ phones = client.phones
23
+
24
+ expect(phones).to be_a(Array)
25
+ expect(phones.first).to be_a(Entities::Phone)
26
+ expect(phones.first.id).to be_a(String)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ if ENV['CI']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require 'uphold'
7
+ require 'climate_control'
8
+ require 'pry'
9
+
10
+ Dir[File.join(Uphold::ROOT_PATH, '..', 'spec/support/**/*.rb')].each { |f| require f }
11
+
12
+ class DummyLogger
13
+ def self.info(_message); end
14
+ def self.debug(_message); end
15
+ end
16
+ Uphold.logger = DummyLogger
17
+
18
+ def with_modified_env(options, &block)
19
+ ClimateControl.modify(options, &block)
20
+ end
21
+
22
+ RSpec.configure do |config|
23
+ config.mock_with :rspec do |mocks|
24
+ mocks.verify_doubled_constant_names = true
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |config|
4
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ config.hook_into :webmock
6
+
7
+ config.filter_sensitive_data('<UPHOLD_AUTH_TOKEN>') { ENV['UPHOLD_AUTH_TOKEN'] }
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'webmock/rspec'
2
+ require 'uri'
3
+
4
+ WebMock.disable_net_connect!(allow: 'codeclimate.com')
5
+
6
+ module WebMockHelpers
7
+ def self.uphold_stub_request(method, url, response = [], status: 200)
8
+ WebMock::API.stub_request(method, Uphold::Request.base_uri + url).
9
+ to_return(body: response.to_json, status: status, headers: { 'Content-Type' => 'application/json' })
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe AuthToken do
6
+ let(:client) { Client.new }
7
+
8
+ context '#generate_access_token' do
9
+ it 'generates a personal access token' do
10
+ auth = { username: 'user', password: 'pass', otp: 'otp' }
11
+ allow(Request).to receive(:perform_with_object)
12
+
13
+ client.generate_access_token(auth)
14
+
15
+ expect(Request).to have_received(:perform_with_object).
16
+ with(:post, anything)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe Card do
6
+ let(:client) { Client.new }
7
+
8
+ context '#all_cards' do
9
+ it 'gets all the cards' do
10
+ request_data = RequestData.new(Endpoints::CARD, Entities::Card, client.authorization_header)
11
+ allow(Request).to receive(:perform_with_objects)
12
+
13
+ client.all_cards
14
+
15
+ expect(Request).to have_received(:perform_with_objects).
16
+ with(:get, request_data)
17
+ end
18
+ end
19
+
20
+ context '#find_card' do
21
+ it 'gets a specific card' do
22
+ id = '1234'
23
+ request_data = RequestData.new(Endpoints::CARD + "/#{id}", Entities::Card, client.authorization_header)
24
+ allow(Request).to receive(:perform_with_object)
25
+
26
+ client.find_card(id: id)
27
+
28
+ expect(Request).to have_received(:perform_with_object).
29
+ with(:get, request_data)
30
+ end
31
+ end
32
+
33
+ context '#create_card' do
34
+ it 'creates a card' do
35
+ data = { label: 'New card', currency: 'EUR' }
36
+ request_data = RequestData.new(Endpoints::CARD, Entities::Card, client.authorization_header, data)
37
+ allow(Request).to receive(:perform_with_object)
38
+
39
+ client.create_card(data)
40
+
41
+ expect(Request).to have_received(:perform_with_object).
42
+ with(:post, request_data)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module Uphold
4
+ module API
5
+ describe Card do
6
+ let(:client) { Uphold::Client.new }
7
+
8
+ context '#all_contacts' do
9
+ it 'gets all the contacts' do
10
+ request_data = RequestData.new(Endpoints::USER_CONTACTS, Entities::Contact, client.authorization_header)
11
+ allow(Request).to receive(:perform_with_objects)
12
+
13
+ client.all_contacts
14
+
15
+ expect(Request).to have_received(:perform_with_objects).
16
+ with(:get, request_data)
17
+ end
18
+ end
19
+
20
+ context '#find_contact' do
21
+ it 'gets a specific contact' do
22
+ id = '1234'
23
+ request_data = RequestData.new(Endpoints::USER_CONTACTS + "/#{id}", Entities::Contact, client.authorization_header)
24
+ allow(Request).to receive(:perform_with_object)
25
+
26
+ client.find_contact(id: id)
27
+
28
+ expect(Request).to have_received(:perform_with_object).
29
+ with(:get, request_data)
30
+ end
31
+ end
32
+
33
+ context '#create_contact' do
34
+ it 'creates a contact' do
35
+ data = {
36
+ first_name: 'first-name',
37
+ last_name: 'last-name',
38
+ emails: ['fake@email.com'],
39
+ company: 'company-name',
40
+ addresses: ['fake-address-1', 'fake-address-2']
41
+ }
42
+ request_data = RequestData.new(Endpoints::USER_CONTACTS, Entities::Contact, client.authorization_header, Uphold::Helpers.camelized_hash(data))
43
+ allow(Request).to receive(:perform_with_object)
44
+
45
+ client.create_contact(data)
46
+
47
+ expect(Request).to have_received(:perform_with_object).
48
+ with(:post, request_data)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end