starling-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +8 -0
  3. data/.gitignore +1 -0
  4. data/.reek +27 -0
  5. data/.rubocop.yml +6 -4
  6. data/CHANGELOG.md +17 -0
  7. data/Gemfile.lock +37 -2
  8. data/README.md +102 -17
  9. data/bin/console +2 -6
  10. data/lib/starling.rb +40 -7
  11. data/lib/starling/api_service.rb +45 -37
  12. data/lib/starling/client.rb +165 -6
  13. data/lib/starling/errors/api_error.rb +35 -2
  14. data/lib/starling/errors/base_error.rb +6 -24
  15. data/lib/starling/middlewares/raise_starling_errors.rb +11 -10
  16. data/lib/starling/request.rb +17 -19
  17. data/lib/starling/resources/account_balance_resource.rb +14 -6
  18. data/lib/starling/resources/account_resource.rb +10 -0
  19. data/lib/starling/resources/address_resource.rb +26 -0
  20. data/lib/starling/resources/addresses_resource.rb +18 -0
  21. data/lib/starling/resources/base_resource.rb +34 -9
  22. data/lib/starling/resources/card_resource.rb +46 -0
  23. data/lib/starling/resources/contact_account_resource.rb +31 -0
  24. data/lib/starling/resources/contact_resource.rb +16 -0
  25. data/lib/starling/resources/customer_resource.rb +36 -0
  26. data/lib/starling/resources/direct_debit_mandate_resource.rb +43 -0
  27. data/lib/starling/resources/direct_debit_transaction_resource.rb +54 -0
  28. data/lib/starling/resources/inbound_faster_payments_transaction_resource.rb +56 -0
  29. data/lib/starling/resources/mastercard_transaction_resource.rb +73 -0
  30. data/lib/starling/resources/me_resource.rb +26 -0
  31. data/lib/starling/resources/merchant_location_resource.rb +33 -0
  32. data/lib/starling/resources/merchant_resource.rb +34 -0
  33. data/lib/starling/resources/outbound_faster_payments_transaction_resource.rb +56 -0
  34. data/lib/starling/resources/payment_resource.rb +78 -0
  35. data/lib/starling/resources/transaction_resource.rb +42 -0
  36. data/lib/starling/services/account_balance_service.rb +11 -2
  37. data/lib/starling/services/account_service.rb +16 -3
  38. data/lib/starling/services/addresses_service.rb +26 -0
  39. data/lib/starling/services/base_service.rb +22 -1
  40. data/lib/starling/services/card_service.rb +26 -0
  41. data/lib/starling/services/contact_accounts_service.rb +54 -0
  42. data/lib/starling/services/contacts_service.rb +73 -0
  43. data/lib/starling/services/customer_service.rb +25 -0
  44. data/lib/starling/services/direct_debit_mandates_service.rb +61 -0
  45. data/lib/starling/services/direct_debit_transactions_service.rb +46 -0
  46. data/lib/starling/services/inbound_faster_payments_transactions_service.rb +46 -0
  47. data/lib/starling/services/mastercard_transactions_service.rb +30 -0
  48. data/lib/starling/services/me_service.rb +26 -0
  49. data/lib/starling/services/merchant_locations_service.rb +34 -0
  50. data/lib/starling/services/merchants_service.rb +26 -0
  51. data/lib/starling/services/outbound_faster_payments_transactions_service.rb +46 -0
  52. data/lib/starling/services/payments_service.rb +30 -0
  53. data/lib/starling/services/transactions_service.rb +44 -0
  54. data/lib/starling/utils.rb +30 -0
  55. data/lib/starling/version.rb +1 -1
  56. data/starling-ruby.gemspec +2 -0
  57. metadata +63 -2
@@ -0,0 +1,73 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Contact's API's Get Contacts, Get Contact, Delete
4
+ # Contact and Create Contact and Account endpoints
5
+ class ContactsService < BaseService
6
+ # @param id [String] The Starling internal ID of the contact
7
+ # @param params [Hash] Parameters which will be included in the HTTP request,
8
+ # included in the URL as a query string
9
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
10
+ # top of the headers set at the {Client} level
11
+ # @return [Resources::ContactResource]
12
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
13
+ # was unsuccessful
14
+ def get(id, params: {}, headers: {})
15
+ response = api_service.make_request(:get, "/contacts/#{id}", params: params,
16
+ headers: headers)
17
+ resource.new(response: response)
18
+ end
19
+
20
+ # @param id [String] The Starling internal ID of the contact
21
+ # @param params [Hash] Parameters which will be included in the HTTP request,
22
+ # included in the body
23
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
24
+ # top of the headers set at the {Client} level
25
+ # @return [Faraday::Response] the raw response from the Starling Bank API
26
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
27
+ # was unsuccessful
28
+ def delete(id, params: {}, headers: {})
29
+ api_service.make_request(:delete, "/contacts/#{id}", params: params,
30
+ headers: headers)
31
+ end
32
+
33
+ # @param params [Hash] Parameters which will be included in the HTTP request,
34
+ # included in the URL as a query string
35
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
36
+ # top of the headers set at the {Client} level
37
+ # @return [Array<Resources::ContactResource>]
38
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
39
+ # was unsuccessful
40
+ def list(params: {}, headers: {})
41
+ response = api_service.make_request(:get, '/contacts', params: params,
42
+ headers: headers)
43
+ build_collection_from_embedded_key(response, key: 'contacts', resource: resource)
44
+ end
45
+
46
+ # @param params [Hash] Parameters which will be included in the HTTP request,
47
+ # included in the body
48
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
49
+ # top of the headers set at the {Client} level
50
+ # @return [Resources::ContactResource] the created contact
51
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
52
+ # was unsuccessful
53
+ def create(params:, headers: {})
54
+ post_response = api_service.make_request(:post, '/contacts', params: params,
55
+ headers: headers)
56
+
57
+ get_response = api_service.make_request(
58
+ :get,
59
+ convert_location_header_to_relative_path(post_response.headers['Location']),
60
+ headers: headers
61
+ )
62
+
63
+ resource.new(response: get_response)
64
+ end
65
+
66
+ private
67
+
68
+ def resource
69
+ Resources::ContactResource
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,25 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Customer API
4
+ class CustomerService < BaseService
5
+ # @param params [Hash] Parameters which will be included in the HTTP request,
6
+ # included in the URL as a query string
7
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
8
+ # top of the headers set at the {Client} level
9
+ # @return [Resources::CustomerResource]
10
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
11
+ # was unsuccessful
12
+ def get(params: {}, headers: {})
13
+ response = api_service.make_request(:get, '/customers', params: params,
14
+ headers: headers)
15
+ resource.new(response: response)
16
+ end
17
+
18
+ private
19
+
20
+ def resource
21
+ Resources::CustomerResource
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,61 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Direct Debit Mandates API
4
+ class DirectDebitMandatesService < BaseService
5
+ # @param id [String] The Starling internal ID of the Direct Debit mandate
6
+ # @param params [Hash] Parameters which will be included in the HTTP request,
7
+ # included in the URL as a query string
8
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
9
+ # top of the headers set at the {Client} level
10
+ # @return [Resources::DirectDebitMandateResource]
11
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
12
+ # was unsuccessful
13
+ def get(id, params: {}, headers: {})
14
+ response = api_service.make_request(:get,
15
+ "/direct-debit/mandates/#{id}",
16
+ params: params,
17
+ headers: headers)
18
+ resource.new(response: response)
19
+ end
20
+
21
+ # Cancels a Direct Debit mandate
22
+ #
23
+ # @param id [String] The Starling internal ID of the Direct Debit mandate
24
+ # @param params [Hash] Parameters which will be included in the HTTP request,
25
+ # included in the body
26
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
27
+ # top of the headers set at the {Client} level
28
+ # @return [Faraday::Response] the raw response from the Starling Bank API
29
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
30
+ # was unsuccessful
31
+ def delete(id, params: {}, headers: {})
32
+ api_service.make_request(:delete,
33
+ "/direct-debit/mandates/#{id}",
34
+ params: params,
35
+ headers: headers)
36
+ end
37
+
38
+ # @param params [Hash] Parameters which will be included in the HTTP request,
39
+ # included in the URL as a query string
40
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
41
+ # top of the headers set at the {Client} level
42
+ # @return [Array<Resources::DirectDebitMandateResource>]
43
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
44
+ # was unsuccessful
45
+ def list(params: {}, headers: {})
46
+ response = api_service.make_request(:get,
47
+ '/direct-debit/mandates',
48
+ params: params,
49
+ headers: headers)
50
+
51
+ build_collection_from_embedded_key(response, key: 'mandates', resource: resource)
52
+ end
53
+
54
+ private
55
+
56
+ def resource
57
+ Resources::DirectDebitMandateResource
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Transaction Direct Debit API
4
+ class DirectDebitTransactionsService < BaseService
5
+ # @param id [String] The Starling internal ID of the transaction
6
+ # @param params [Hash] Parameters which will be included in the HTTP request,
7
+ # included in the URL as a query string
8
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
9
+ # top of the headers set at the {Client} level
10
+ # @return [Resources::DirectDebitTransactionResource]
11
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
12
+ # was unsuccessful
13
+ def get(id, params: {}, headers: {})
14
+ response = api_service.make_request(:get,
15
+ "/transactions/direct-debit/#{id}",
16
+ params: params,
17
+ headers: headers)
18
+ resource.new(response: response)
19
+ end
20
+
21
+ # @param params [Hash] Parameters which will be included in the HTTP request,
22
+ # included in the URL as a query string
23
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
24
+ # top of the headers set at the {Client} level
25
+ # @return [Array<Resources::DirectDebitTransactionResource>]
26
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
27
+ # was unsuccessful
28
+ def list(params: {}, headers: {})
29
+ response = api_service.make_request(:get,
30
+ '/transactions/direct-debit',
31
+ params: params,
32
+ headers: headers)
33
+
34
+ build_collection_from_embedded_key(response,
35
+ key: 'transactions',
36
+ resource: resource)
37
+ end
38
+
39
+ private
40
+
41
+ def resource
42
+ Resources::DirectDebitTransactionResource
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Transaction Faster Payment In API
4
+ class InboundFasterPaymentsTransactionsService < BaseService
5
+ # @param id [String] The Starling internal ID of the transaction
6
+ # @param params [Hash] Parameters which will be included in the HTTP request,
7
+ # included in the URL as a query string
8
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
9
+ # top of the headers set at the {Client} level
10
+ # @return [Resources::InboundFasterPaymentsTransactionResource]
11
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
12
+ # was unsuccessful
13
+ def get(id, params: {}, headers: {})
14
+ response = api_service.make_request(:get,
15
+ "/transactions/fps/in/#{id}",
16
+ params: params,
17
+ headers: headers)
18
+ resource.new(response: response)
19
+ end
20
+
21
+ # @param params [Hash] Parameters which will be included in the HTTP request,
22
+ # included in the URL as a query string
23
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
24
+ # top of the headers set at the {Client} level
25
+ # @return [Array<Resources::InboundFasterPaymentsTransactionResource>]
26
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
27
+ # was unsuccessful
28
+ def list(params: {}, headers: {})
29
+ response = api_service.make_request(:get,
30
+ '/transactions/fps/in',
31
+ params: params,
32
+ headers: headers)
33
+
34
+ build_collection_from_embedded_key(response,
35
+ key: 'transactions',
36
+ resource: resource)
37
+ end
38
+
39
+ private
40
+
41
+ def resource
42
+ Resources::InboundFasterPaymentsTransactionResource
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Transaction Mastercard API
4
+ class MastercardTransactionsService < BaseService
5
+ # @param params [Hash] Parameters which will be included in the HTTP request,
6
+ # included in the URL as a query string
7
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
8
+ # top of the headers set at the {Client} level
9
+ # @return [Array<Resources::MastercardTransactionResource>]
10
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
11
+ # was unsuccessful
12
+ def list(params: {}, headers: {})
13
+ response = api_service.make_request(:get,
14
+ '/transactions/mastercard',
15
+ params: params,
16
+ headers: headers)
17
+
18
+ build_collection_from_embedded_key(response,
19
+ key: 'transactions',
20
+ resource: resource)
21
+ end
22
+
23
+ private
24
+
25
+ def resource
26
+ Resources::MastercardTransactionResource
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Who Am I API
4
+ class MeService < BaseService
5
+ # @param params [Hash] Parameters which will be included in the HTTP request,
6
+ # included in the URL as a query string
7
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
8
+ # top of the headers set at the {Client} level
9
+ # @return [Resources::MeResource]
10
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
11
+ # was unsuccessful
12
+ def get(params: {}, headers: {})
13
+ response = api_service.make_request(:get, '/me', params: params,
14
+ headers: headers)
15
+
16
+ resource.new(response: response)
17
+ end
18
+
19
+ private
20
+
21
+ def resource
22
+ Resources::MeResource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Merchant API's Get Location endpoint
4
+ class MerchantLocationsService < BaseService
5
+ # @param merchant_id [String] The Starling internal ID of the merchant the merchant
6
+ # location belongs to
7
+ # @param merchant_location_id [String] The Starling internal ID of the merchant
8
+ # location
9
+ # @param params [Hash] Parameters which will be included in the HTTP request,
10
+ # included in the URL as a query string
11
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
12
+ # top of the headers set at the {Client} level
13
+ # @return [Resources::MerchantLocationResource]
14
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
15
+ # was unsuccessful
16
+ def get(merchant_id, merchant_location_id, params: {}, headers: {})
17
+ response = api_service.make_request(
18
+ :get,
19
+ "/merchants/#{merchant_id}/locations/#{merchant_location_id}",
20
+ params: params,
21
+ headers: headers
22
+ )
23
+
24
+ resource.new(response: response)
25
+ end
26
+
27
+ private
28
+
29
+ def resource
30
+ Resources::MerchantLocationResource
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Merchant API's Get Merchant endpoint
4
+ class MerchantsService < BaseService
5
+ # @param id [String] The Starling internal ID of the merchant
6
+ # @param params [Hash] Parameters which will be included in the HTTP request,
7
+ # included in the URL as a query string
8
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
9
+ # top of the headers set at the {Client} level
10
+ # @return [Resources:MerchantResource]
11
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
12
+ # was unsuccessful
13
+ def get(id, params: {}, headers: {})
14
+ response = api_service.make_request(:get, "/merchants/#{id}", params: params,
15
+ headers: headers)
16
+ resource.new(response: response)
17
+ end
18
+
19
+ private
20
+
21
+ def resource
22
+ Resources::MerchantResource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Transaction Faster Payment Out API
4
+ class OutboundFasterPaymentsTransactionsService < BaseService
5
+ # @param id [String] The Starling internal ID of the transaction
6
+ # @param params [Hash] Parameters which will be included in the HTTP request,
7
+ # included in the URL as a query string
8
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
9
+ # top of the headers set at the {Client} level
10
+ # @return [Resources::OutboundFasterPaymentsTransactionResource]
11
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
12
+ # was unsuccessful
13
+ def get(id, params: {}, headers: {})
14
+ response = api_service.make_request(:get,
15
+ "/transactions/fps/out/#{id}",
16
+ params: params,
17
+ headers: headers)
18
+ resource.new(response: response)
19
+ end
20
+
21
+ # @param params [Hash] Parameters which will be included in the HTTP request,
22
+ # included in the URL as a query string
23
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
24
+ # top of the headers set at the {Client} level
25
+ # @return [Array<Resources::OutboundFasterPaymentsTransactionResource>]
26
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
27
+ # was unsuccessful
28
+ def list(params: {}, headers: {})
29
+ response = api_service.make_request(:get,
30
+ '/transactions/fps/out',
31
+ params: params,
32
+ headers: headers)
33
+
34
+ build_collection_from_embedded_key(response,
35
+ key: 'transactions',
36
+ resource: resource)
37
+ end
38
+
39
+ private
40
+
41
+ def resource
42
+ Resources::OutboundFasterPaymentsTransactionResource
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module Starling
2
+ module Services
3
+ # A service for accessing the Payment API
4
+ class PaymentsService < BaseService
5
+ # @param params [Hash] Parameters which will be included in the HTTP request,
6
+ # included in the URL as a query string
7
+ # @param headers [Hash] Headers which be included in the HTTP request, merged on
8
+ # top of the headers set at the {Client} level
9
+ # @return [Array<Resources::PaymentResource>]
10
+ # @raise [Errors::ApiError] if the HTTP request returns a status indicating that it
11
+ # was unsuccessful
12
+ def list(params: {}, headers: {})
13
+ response = api_service.make_request(:get,
14
+ '/payments/scheduled',
15
+ params: params,
16
+ headers: headers)
17
+
18
+ build_collection_from_embedded_key(response,
19
+ key: 'paymentOrders',
20
+ resource: resource)
21
+ end
22
+
23
+ private
24
+
25
+ def resource
26
+ Resources::PaymentResource
27
+ end
28
+ end
29
+ end
30
+ end