starling-ruby 0.1.0 → 0.2.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/.circleci/config.yml +8 -0
- data/.gitignore +1 -0
- data/.reek +27 -0
- data/.rubocop.yml +6 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +37 -2
- data/README.md +102 -17
- data/bin/console +2 -6
- data/lib/starling.rb +40 -7
- data/lib/starling/api_service.rb +45 -37
- data/lib/starling/client.rb +165 -6
- data/lib/starling/errors/api_error.rb +35 -2
- data/lib/starling/errors/base_error.rb +6 -24
- data/lib/starling/middlewares/raise_starling_errors.rb +11 -10
- data/lib/starling/request.rb +17 -19
- data/lib/starling/resources/account_balance_resource.rb +14 -6
- data/lib/starling/resources/account_resource.rb +10 -0
- data/lib/starling/resources/address_resource.rb +26 -0
- data/lib/starling/resources/addresses_resource.rb +18 -0
- data/lib/starling/resources/base_resource.rb +34 -9
- data/lib/starling/resources/card_resource.rb +46 -0
- data/lib/starling/resources/contact_account_resource.rb +31 -0
- data/lib/starling/resources/contact_resource.rb +16 -0
- data/lib/starling/resources/customer_resource.rb +36 -0
- data/lib/starling/resources/direct_debit_mandate_resource.rb +43 -0
- data/lib/starling/resources/direct_debit_transaction_resource.rb +54 -0
- data/lib/starling/resources/inbound_faster_payments_transaction_resource.rb +56 -0
- data/lib/starling/resources/mastercard_transaction_resource.rb +73 -0
- data/lib/starling/resources/me_resource.rb +26 -0
- data/lib/starling/resources/merchant_location_resource.rb +33 -0
- data/lib/starling/resources/merchant_resource.rb +34 -0
- data/lib/starling/resources/outbound_faster_payments_transaction_resource.rb +56 -0
- data/lib/starling/resources/payment_resource.rb +78 -0
- data/lib/starling/resources/transaction_resource.rb +42 -0
- data/lib/starling/services/account_balance_service.rb +11 -2
- data/lib/starling/services/account_service.rb +16 -3
- data/lib/starling/services/addresses_service.rb +26 -0
- data/lib/starling/services/base_service.rb +22 -1
- data/lib/starling/services/card_service.rb +26 -0
- data/lib/starling/services/contact_accounts_service.rb +54 -0
- data/lib/starling/services/contacts_service.rb +73 -0
- data/lib/starling/services/customer_service.rb +25 -0
- data/lib/starling/services/direct_debit_mandates_service.rb +61 -0
- data/lib/starling/services/direct_debit_transactions_service.rb +46 -0
- data/lib/starling/services/inbound_faster_payments_transactions_service.rb +46 -0
- data/lib/starling/services/mastercard_transactions_service.rb +30 -0
- data/lib/starling/services/me_service.rb +26 -0
- data/lib/starling/services/merchant_locations_service.rb +34 -0
- data/lib/starling/services/merchants_service.rb +26 -0
- data/lib/starling/services/outbound_faster_payments_transactions_service.rb +46 -0
- data/lib/starling/services/payments_service.rb +30 -0
- data/lib/starling/services/transactions_service.rb +44 -0
- data/lib/starling/utils.rb +30 -0
- data/lib/starling/version.rb +1 -1
- data/starling-ruby.gemspec +2 -0
- metadata +63 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8a9d85c10f82c31df8e74a368d3180e01d16d76
|
4
|
+
data.tar.gz: b844476947553b58c50ad54e927746bf21978af1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df6103bb3533d7d5ae0abccf312c3939f5c06c07cf49fe19fd502274c969798ea33691ffa217e6fee52c2c670d29ff5b27cfef47aa245d7107b305e21330d85a
|
7
|
+
data.tar.gz: 10c9a6efe88bf5f4b65654513d7e2aae5ce9a96230a39b51887d5764274f9ab5cb35ffddb8fa16a197402b6b29b23d35762203e7ef7c7f02cbe0265f2562e278
|
data/.circleci/config.yml
CHANGED
@@ -11,6 +11,9 @@ jobs:
|
|
11
11
|
- type: cache-restore
|
12
12
|
key: starling-{{ checksum "Gemfile.lock" }}
|
13
13
|
|
14
|
+
# Update bundler
|
15
|
+
- run: gem install bundler
|
16
|
+
|
14
17
|
# Bundle install dependencies
|
15
18
|
- run: bundle install --path vendor/bundle
|
16
19
|
|
@@ -34,6 +37,11 @@ jobs:
|
|
34
37
|
command: |
|
35
38
|
bundle exec rubocop
|
36
39
|
|
40
|
+
# Run Reek
|
41
|
+
- type: shell
|
42
|
+
command: |
|
43
|
+
bundle exec reek lib
|
44
|
+
|
37
45
|
# Save artifacts
|
38
46
|
- type: store_test_results
|
39
47
|
path: /tmp/test-results
|
data/.gitignore
CHANGED
data/.reek
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
UtilityFunction:
|
2
|
+
public_methods_only: true
|
3
|
+
|
4
|
+
IrresponsibleModule:
|
5
|
+
enabled: false
|
6
|
+
|
7
|
+
TooManyInstanceVariables:
|
8
|
+
exclude:
|
9
|
+
- "Starling::Request"
|
10
|
+
|
11
|
+
LongParameterList:
|
12
|
+
max_params: 4
|
13
|
+
exclude:
|
14
|
+
- "Starling::ApiService#make_request"
|
15
|
+
|
16
|
+
DataClump:
|
17
|
+
min_clump_size: 4
|
18
|
+
|
19
|
+
ControlParameter:
|
20
|
+
exclude:
|
21
|
+
# This looks like a false positive to me! `parsed_data` doesn't control the method.
|
22
|
+
- "Starling::Resources::BaseResource#initialize"
|
23
|
+
|
24
|
+
TooManyMethods:
|
25
|
+
exclude:
|
26
|
+
# Starling::Client has to have lots of methods, since it has one for each service
|
27
|
+
- "Starling::Client"
|
data/.rubocop.yml
CHANGED
@@ -3,10 +3,12 @@ AllCops:
|
|
3
3
|
|
4
4
|
Metrics/LineLength:
|
5
5
|
Max: 90
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
Exclude:
|
7
|
+
# We have a very long line in this file in our YARD documentation comments to link to
|
8
|
+
# a PDF on the MasterCard website. This can't be broken into separate lines, and
|
9
|
+
# adding a rubocop:disable comment appears in the docs, so let's disable it here.
|
10
|
+
- lib/starling/resources/merchant_location_resource.rb
|
9
11
|
|
10
12
|
Metrics/BlockLength:
|
11
13
|
Exclude:
|
12
|
-
|
14
|
+
- spec/**/*
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
## v0.2.0 - 4 Jun 2017
|
2
|
+
|
3
|
+
* Add support for the Transaction Faster Payments In, Transaction Faster Payments Out,
|
4
|
+
Transaction Direct Debit, Payment and Transaction Mastercard APIs
|
5
|
+
* Improve error handling behaviour to raise errors at the right time with clear,
|
6
|
+
accessible information about what went wrong
|
7
|
+
* Use Ruby 2.0+ keyword arguments rather than passing around `Hash`es
|
8
|
+
* Add full [YARD](http://yardoc.org/) documentation
|
9
|
+
* Consistently return `Float`s for all API attributes which can be integers or floats
|
10
|
+
* Refactor `Request` to remove private methods
|
11
|
+
* Refactor `Resources::BaseResource`
|
12
|
+
* Check for common code smells with [Reek](https://github.com/troessner/reek) as part of
|
13
|
+
the CI process
|
14
|
+
|
15
|
+
## v0.1.0 - 30 May 2017
|
16
|
+
|
17
|
+
* Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
starling-ruby (0.
|
4
|
+
starling-ruby (0.2.0)
|
5
5
|
faraday (>= 0.8.9, < 0.10)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,14 +10,27 @@ GEM
|
|
10
10
|
addressable (2.5.1)
|
11
11
|
public_suffix (~> 2.0, >= 2.0.2)
|
12
12
|
ast (2.3.0)
|
13
|
+
axiom-types (0.1.1)
|
14
|
+
descendants_tracker (~> 0.0.4)
|
15
|
+
ice_nine (~> 0.11.0)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
13
17
|
builder (3.2.3)
|
18
|
+
codeclimate-engine-rb (0.4.0)
|
19
|
+
virtus (~> 1.0)
|
14
20
|
coderay (1.1.1)
|
21
|
+
coercible (1.0.0)
|
22
|
+
descendants_tracker (~> 0.0.1)
|
15
23
|
crack (0.4.3)
|
16
24
|
safe_yaml (~> 1.0.0)
|
25
|
+
descendants_tracker (0.0.4)
|
26
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
17
27
|
diff-lcs (1.3)
|
28
|
+
equalizer (0.0.11)
|
18
29
|
faraday (0.9.2)
|
19
30
|
multipart-post (>= 1.2, < 3)
|
31
|
+
ffi (1.9.18-java)
|
20
32
|
hashdiff (0.3.4)
|
33
|
+
ice_nine (0.11.2)
|
21
34
|
method_source (0.8.2)
|
22
35
|
multipart-post (2.0.0)
|
23
36
|
parallel (1.11.2)
|
@@ -28,10 +41,19 @@ GEM
|
|
28
41
|
coderay (~> 1.1.0)
|
29
42
|
method_source (~> 0.8.1)
|
30
43
|
slop (~> 3.4)
|
44
|
+
pry (0.10.4-java)
|
45
|
+
coderay (~> 1.1.0)
|
46
|
+
method_source (~> 0.8.1)
|
47
|
+
slop (~> 3.4)
|
48
|
+
spoon (~> 0.0)
|
31
49
|
public_suffix (2.0.5)
|
32
50
|
rainbow (2.2.2)
|
33
51
|
rake
|
34
52
|
rake (10.5.0)
|
53
|
+
reek (4.7.0)
|
54
|
+
codeclimate-engine-rb (~> 0.4.0)
|
55
|
+
parser (>= 2.4.0.0, < 2.5)
|
56
|
+
rainbow (~> 2.0)
|
35
57
|
rspec (3.6.0)
|
36
58
|
rspec-core (~> 3.6.0)
|
37
59
|
rspec-expectations (~> 3.6.0)
|
@@ -61,20 +83,32 @@ GEM
|
|
61
83
|
ruby-progressbar (1.8.1)
|
62
84
|
safe_yaml (1.0.4)
|
63
85
|
slop (3.6.0)
|
86
|
+
spoon (0.0.6)
|
87
|
+
ffi
|
88
|
+
thread_safe (0.3.6)
|
89
|
+
thread_safe (0.3.6-java)
|
64
90
|
unicode-display_width (1.2.1)
|
65
91
|
values (1.8.0)
|
92
|
+
virtus (1.0.5)
|
93
|
+
axiom-types (~> 0.1)
|
94
|
+
coercible (~> 1.0)
|
95
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
96
|
+
equalizer (~> 0.0, >= 0.0.9)
|
66
97
|
webmock (3.0.1)
|
67
98
|
addressable (>= 2.3.6)
|
68
99
|
crack (>= 0.3.2)
|
69
100
|
hashdiff
|
101
|
+
yard (0.8.7.6)
|
70
102
|
|
71
103
|
PLATFORMS
|
104
|
+
java
|
72
105
|
ruby
|
73
106
|
|
74
107
|
DEPENDENCIES
|
75
108
|
bundler (~> 1.14)
|
76
109
|
pry (~> 0.10.4)
|
77
110
|
rake (~> 10.0)
|
111
|
+
reek (~> 4.7.0)
|
78
112
|
rspec (~> 3.0)
|
79
113
|
rspec-its (~> 1.2.0)
|
80
114
|
rspec_junit_formatter (~> 0.2.3)
|
@@ -82,6 +116,7 @@ DEPENDENCIES
|
|
82
116
|
starling-ruby!
|
83
117
|
values (~> 1.8.0)
|
84
118
|
webmock (~> 3.0.1)
|
119
|
+
yard (~> 0.8.7.6)
|
85
120
|
|
86
121
|
BUNDLED WITH
|
87
|
-
1.15.
|
122
|
+
1.15.1
|
data/README.md
CHANGED
@@ -3,17 +3,28 @@
|
|
3
3
|
The Starling Ruby library provides a simple, idiomatic interface to the [Starling Bank API](https://developer.starlingbank.com).
|
4
4
|
|
5
5
|
[](https://circleci.com/gh/timrogers/starling-ruby/tree/master)
|
6
|
+
[](https://badge.fury.io/rb/starling-ruby)
|
6
7
|
|
7
8
|
## Getting started
|
8
9
|
|
9
10
|
Install the gem by adding it to your Gemfile, and then run `bundle`:
|
10
11
|
|
11
12
|
```ruby
|
12
|
-
|
13
|
-
gem 'starling-ruby', github: "timrogers/starling-ruby"
|
13
|
+
gem 'starling-ruby', '~> 0.2.0', require: 'starling'
|
14
14
|
```
|
15
15
|
|
16
|
-
You
|
16
|
+
You'll need to get a personal access token for your Starling account. To get set up,
|
17
|
+
head to the Starling Developers
|
18
|
+
["Get Started" page](https://developer.starlingbank.com/get-started) and then scroll
|
19
|
+
down to the "Personal Access" section for instructions.
|
20
|
+
|
21
|
+
At the moment, the library is not designed to
|
22
|
+
support OAuth applications (it can't handle refreshing access tokens) or endpoints
|
23
|
+
requiring the [`pay-local:create` scope](https://developer.starlingbank.com/tiers),
|
24
|
+
which is not granted to personal access tokens.
|
25
|
+
|
26
|
+
You can now initialise the client, providing your access token, and optionally an
|
27
|
+
environment (either `:sandbox` or `:production`, defaulting to :production):
|
17
28
|
|
18
29
|
```ruby
|
19
30
|
starling = Starling::Client.new(
|
@@ -25,11 +36,15 @@ starling = Starling::Client.new(
|
|
25
36
|
|
26
37
|
## Usage
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
|
39
|
+
Now you've initialised a `Starling::Client` with your access token, you can start making
|
40
|
+
requests to the API.
|
41
|
+
|
42
|
+
All APIs are supported except "Get Photo" under the Contact API (it doesn't seem to
|
43
|
+
actually be possible to set a photo...) and the Payment APIs for creating an immediate or scheduled payment (which are not supported for personal access tokens).
|
31
44
|
|
32
|
-
|
45
|
+
See below for a few simple examples, or head to our
|
46
|
+
[full documentation](http://www.rubydoc.info/github/timrogers/starling-ruby/master) for
|
47
|
+
complete details:
|
33
48
|
|
34
49
|
### Check your balance
|
35
50
|
|
@@ -42,14 +57,16 @@ puts "Your balance is #{balance.amount} #{balance.currency}!"
|
|
42
57
|
|
43
58
|
```ruby
|
44
59
|
account = starling.account.get
|
45
|
-
puts "Your sort code is #{account.sort_code} and your account number is
|
60
|
+
puts "Your sort code is #{account.sort_code} and your account number is " \
|
61
|
+
"#{account.number}."
|
46
62
|
```
|
47
63
|
|
48
64
|
### List transactions
|
49
65
|
|
50
66
|
```ruby
|
51
67
|
transaction = starling.transactions.list.first
|
52
|
-
puts "Your most recent transaction was for #{transaction.amount} on
|
68
|
+
puts "Your most recent transaction was for #{transaction.amount} on " \
|
69
|
+
"#{transaction.created}"
|
53
70
|
```
|
54
71
|
|
55
72
|
### Fetch a transaction by ID
|
@@ -59,27 +76,95 @@ transaction = starling.transactions.get("insert-uuid-here")
|
|
59
76
|
puts "Your transaction was for #{transaction.amount} on #{transaction.created}"
|
60
77
|
```
|
61
78
|
|
79
|
+
### Fetch a merchant by ID
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
merchant = starling.merchants.get("insert-uuid-here")
|
83
|
+
puts "You can call #{merchant.name} on #{merchant.phone_number}"
|
84
|
+
```
|
85
|
+
|
86
|
+
### Fetch a merchant location by ID
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
merchant_location = starling.merchant_locations.get(
|
90
|
+
"insert-merchant-uid-here",
|
91
|
+
"insert-merchant-location-uid-here"
|
92
|
+
)
|
93
|
+
|
94
|
+
puts "This location for #{merchant_location.merchant_name} is called " \
|
95
|
+
"#{merchant_location.location_name}"
|
96
|
+
```
|
97
|
+
|
98
|
+
## Philosophy
|
99
|
+
|
100
|
+
Once you've initialised a `Starling::Client`, it exposes a number of services (living
|
101
|
+
in `lib/starling/services`) which have methods calling out to the API.
|
102
|
+
|
103
|
+
Philosophically, these services represent "kinds of things" (i.e. resources) returned by
|
104
|
+
or manipulated by the API. __These do not necessarily match up with the APIs listed in
|
105
|
+
Starling's [documentation](https://developer.starlingbank.com/docs), which is grouped slightly differently__.
|
106
|
+
|
107
|
+
The benefit is that we can have a small, predictable set of methods in our
|
108
|
+
services exposing API endpoints: `#get`, `#list`, `#create` and `#delete`.
|
109
|
+
|
110
|
+
This is best shown through an example - let's look at the Merchant API. It has two
|
111
|
+
endpoints listed under it: "Get Merchant" and "Get Location". The former operates on
|
112
|
+
a "kind of thing" called a "contact", and the latter operates on a "kind of thing" called
|
113
|
+
a "contact account". You could potentially group these together, but then you'd have to
|
114
|
+
have a slightly odd method name (something like `get_location`). Instead, we keep things
|
115
|
+
consistent, like follows:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
starling.merchants.get(merchant_id)
|
119
|
+
starling.merchant_locations.get(merchant_id, merchant_location_id)
|
120
|
+
```
|
121
|
+
|
122
|
+
Other parts of the Starling Bank API exhibit similar difficulties - for example, the
|
123
|
+
Contact API operates on Contacts, Contact Accounts and Contact Photos.
|
124
|
+
|
125
|
+
Methods on the services for accessing the API return resources (found in
|
126
|
+
`lib/starling/resources`), arrays of resources or, rarely, `Faraday::Response`s in the
|
127
|
+
case of `DELETE` requests.
|
128
|
+
|
129
|
+
## Backwards compatability
|
130
|
+
|
131
|
+
This gem is versioned using [Semantic Versioning](http://semver.org/), so you can be
|
132
|
+
confident when updating that there will not be breaking changes outside of a major
|
133
|
+
version (following format MAJOR.MINOR.PATCH, so for instance moving from 2.3.0 to 3.0.0
|
134
|
+
would be allowed to include incompatible API changes). See
|
135
|
+
[CHANGELOG.md](https://github.com/timrogers/starling-ruby/tree/master/CHANGELOG.md) for
|
136
|
+
details on what has changed in each version.
|
137
|
+
|
138
|
+
Until we reach v1.0, minor versions may contain backwards-incompatible changes, as the
|
139
|
+
API stabilises. Any such changes will be flagged in the changelog.
|
140
|
+
|
62
141
|
## Tests
|
63
142
|
|
64
|
-
The recommended way to run tests on the project is using CircleCI's local Docker
|
65
|
-
- this is the best way to make sure that what passes tests locally in development
|
66
|
-
work when you push it and it runs through our automated CI.
|
143
|
+
The recommended way to run tests on the project is using CircleCI's local Docker
|
144
|
+
testing - this is the best way to make sure that what passes tests locally in development
|
145
|
+
will work when you push it and it runs through our automated CI.
|
67
146
|
|
68
147
|
```bash
|
69
148
|
# Download the circleci binary (assuming /usr/local/bin is in your PATH)
|
70
|
-
curl -o /usr/local/bin/circleci
|
149
|
+
curl -o /usr/local/bin/circleci \
|
150
|
+
https://circle-downloads.s3.amazonaws.com/releases/build_agent_wrapper/circleci
|
151
|
+
|
152
|
+
chmod +x /usr/local/bin/circleci
|
71
153
|
|
72
|
-
# Run the full CI process, including tests and
|
154
|
+
# Run the full CI process, including tests, Rubocop and Reek. You'll need Docker
|
155
|
+
# installed.
|
73
156
|
circleci build
|
74
157
|
```
|
75
158
|
|
76
|
-
You can also run tests in your own environment by running `bundle exec rake`,
|
77
|
-
run Rubocop by running `bundle exec rubocop
|
159
|
+
You can also run tests in your own environment by running `bundle exec rake`, can
|
160
|
+
run Rubocop by running `bundle exec rubocop` and can run Reek by running `bundle exec
|
161
|
+
reek lib`.
|
78
162
|
|
79
163
|
## Contributing
|
80
164
|
|
81
165
|
All contributions are welcome - just make a pull request, making sure you include tests
|
82
|
-
and write a good, informative commit
|
166
|
+
and documentation for any public methods, and write a good, informative commit
|
167
|
+
message/pull request body.
|
83
168
|
|
84
169
|
Check out
|
85
170
|
[CODE_OF_CONDUCT.md](https://github.com/timrogers/starling-ruby/blob/master/CODE_OF_CONDUCT.md)
|
data/bin/console
CHANGED
@@ -6,9 +6,5 @@ require 'starling'
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|
9
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/lib/starling.rb
CHANGED
@@ -1,18 +1,51 @@
|
|
1
|
+
require 'starling/utils'
|
1
2
|
require 'starling/version'
|
2
|
-
require 'starling/client'
|
3
|
-
require 'starling/api_service'
|
4
3
|
require 'starling/request'
|
4
|
+
require 'starling/api_service'
|
5
|
+
require 'starling/client'
|
5
6
|
require 'starling/errors/base_error'
|
6
7
|
require 'starling/errors/api_error'
|
7
8
|
require 'starling/middlewares/raise_starling_errors'
|
8
|
-
|
9
|
-
require 'starling/services/account_service'
|
10
|
-
require 'starling/services/account_balance_service'
|
11
|
-
require 'starling/services/transactions_service'
|
9
|
+
|
12
10
|
require 'starling/resources/base_resource'
|
13
|
-
require 'starling/resources/account_resource'
|
14
11
|
require 'starling/resources/account_balance_resource'
|
12
|
+
require 'starling/resources/account_resource'
|
13
|
+
require 'starling/resources/address_resource'
|
14
|
+
require 'starling/resources/addresses_resource'
|
15
|
+
require 'starling/resources/card_resource'
|
16
|
+
require 'starling/resources/contact_account_resource'
|
17
|
+
require 'starling/resources/contact_resource'
|
18
|
+
require 'starling/resources/customer_resource'
|
19
|
+
require 'starling/resources/direct_debit_mandate_resource'
|
20
|
+
require 'starling/resources/direct_debit_transaction_resource'
|
21
|
+
require 'starling/resources/inbound_faster_payments_transaction_resource'
|
22
|
+
require 'starling/resources/mastercard_transaction_resource'
|
23
|
+
require 'starling/resources/me_resource'
|
24
|
+
require 'starling/resources/merchant_location_resource'
|
25
|
+
require 'starling/resources/merchant_resource'
|
26
|
+
require 'starling/resources/outbound_faster_payments_transaction_resource'
|
27
|
+
require 'starling/resources/payment_resource'
|
15
28
|
require 'starling/resources/transaction_resource'
|
16
29
|
|
30
|
+
require 'starling/services/base_service'
|
31
|
+
require 'starling/services/account_balance_service'
|
32
|
+
require 'starling/services/account_service'
|
33
|
+
require 'starling/services/addresses_service'
|
34
|
+
require 'starling/services/card_service'
|
35
|
+
require 'starling/services/contact_accounts_service'
|
36
|
+
require 'starling/services/contacts_service'
|
37
|
+
require 'starling/services/customer_service'
|
38
|
+
require 'starling/services/direct_debit_mandates_service'
|
39
|
+
require 'starling/services/direct_debit_transactions_service'
|
40
|
+
require 'starling/services/inbound_faster_payments_transactions_service'
|
41
|
+
require 'starling/services/mastercard_transactions_service'
|
42
|
+
require 'starling/services/me_service'
|
43
|
+
require 'starling/services/merchant_locations_service'
|
44
|
+
require 'starling/services/merchants_service'
|
45
|
+
require 'starling/services/outbound_faster_payments_transactions_service'
|
46
|
+
require 'starling/services/payments_service'
|
47
|
+
require 'starling/services/transactions_service'
|
48
|
+
|
49
|
+
# A Ruby client for accessing the Starling Bank API
|
17
50
|
module Starling
|
18
51
|
end
|
data/lib/starling/api_service.rb
CHANGED
@@ -1,31 +1,57 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
3
|
module Starling
|
4
|
+
# The API client under the hood, used by services publicly exposed by
|
5
|
+
# {Starling::Client} to dispatch requests to the Starling Bank API
|
4
6
|
class ApiService
|
7
|
+
# The default adapter which will be used by Faraday to make requests. This can be
|
8
|
+
# customised by passing a :http_adapter when instantiating the ApiService.
|
5
9
|
DEFAULT_ADAPTER = :net_http
|
6
|
-
BASE_PATH = '/api/v1'.freeze
|
7
|
-
|
8
|
-
def initialize(base_url, options = {})
|
9
|
-
@access_token = options.fetch(:access_token)
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# The path of the API version which will be prepended to request paths
|
12
|
+
BASE_PATH = '/api/v1'.freeze
|
13
13
|
|
14
|
+
# Instantiates a {ApiService} for dispatching requests to the Starling Bank API
|
15
|
+
#
|
16
|
+
# @param base_url [String] The base URL for the Starling API, including the protocol
|
17
|
+
# and hostname, to which the {BASE_PATH} and request paths
|
18
|
+
# will be added
|
19
|
+
# @param access_token [String] A personal access token for the Starling Bank API
|
20
|
+
# @param http_adapter [Array] The HTTP adapter to be used, defaulting to
|
21
|
+
# {DEFAULT_ADAPTER}
|
22
|
+
# @param connection_options [Hash] A hash of options to be passed in when
|
23
|
+
# instantiating Faraday (for example for setting
|
24
|
+
# the request timeout)
|
25
|
+
# @param default_headers [Hash] A set of user-provided HTTP headers to add to each
|
26
|
+
# request, alongside the library's defaults defined in
|
27
|
+
# {#library_default_headers}
|
28
|
+
# @return [Starling::ApiService] The configured ApiService
|
29
|
+
def initialize(base_url, access_token:, http_adapter: [DEFAULT_ADAPTER],
|
30
|
+
connection_options: {}, default_headers: {})
|
14
31
|
@connection = Faraday.new(base_url, connection_options) do |faraday|
|
15
32
|
faraday.response(:raise_starling_errors)
|
16
33
|
faraday.adapter(*http_adapter)
|
17
34
|
end
|
18
35
|
|
19
|
-
|
20
|
-
|
36
|
+
@headers = library_default_headers(access_token: access_token)
|
37
|
+
.merge(default_headers)
|
21
38
|
end
|
22
39
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
40
|
+
# Makes an HTTP request to the Starling Bank API with the specified method and path
|
41
|
+
#
|
42
|
+
# @param method [Symbol] The HTTP method which will be used for the request
|
43
|
+
# @param path [String] The path of the API endpoint, which will be appended to the
|
44
|
+
# {BASE_PATH}
|
45
|
+
# @param params [Hash] The parameters which will be included in the request, either
|
46
|
+
# in the URL or the body, depending on the method
|
47
|
+
# @param headers [Hash] Additional headers to be included in your request, which will
|
48
|
+
# be merged on top of the service's default headers
|
49
|
+
# @return [Faraday::Response] The response from the server to the dispatched request
|
50
|
+
def make_request(method, path, params: {}, headers: {})
|
51
|
+
headers = @headers.merge(headers)
|
52
|
+
|
53
|
+
Request.new(@connection, method, build_path(path), params: params,
|
54
|
+
headers: headers)
|
29
55
|
.make_request
|
30
56
|
end
|
31
57
|
|
@@ -35,9 +61,9 @@ module Starling
|
|
35
61
|
"#{BASE_PATH}#{path}"
|
36
62
|
end
|
37
63
|
|
38
|
-
def
|
64
|
+
def library_default_headers(access_token:)
|
39
65
|
{
|
40
|
-
'Authorization' => "Bearer #{
|
66
|
+
'Authorization' => "Bearer #{access_token}",
|
41
67
|
'Accept' => 'application/json',
|
42
68
|
'User-Agent' => user_agent
|
43
69
|
}
|
@@ -47,32 +73,14 @@ module Starling
|
|
47
73
|
@user_agent ||=
|
48
74
|
begin
|
49
75
|
comment = [
|
50
|
-
"#{ruby_engine}/#{ruby_version}",
|
51
|
-
"#{RUBY_ENGINE}/#{interpreter_version}",
|
76
|
+
"#{Utils.ruby_engine}/#{Utils.ruby_version}",
|
77
|
+
"#{RUBY_ENGINE}/#{Utils.interpreter_version}",
|
52
78
|
RUBY_PLATFORM.to_s,
|
53
79
|
"faraday/#{Faraday::VERSION}"
|
54
80
|
]
|
55
81
|
|
56
|
-
"#{gem_info} #{comment.join(' ')}"
|
82
|
+
"#{Utils.gem_info} #{comment.join(' ')}"
|
57
83
|
end
|
58
84
|
end
|
59
|
-
|
60
|
-
def gem_info
|
61
|
-
return 'starling-ruby' unless defined?(Starling::VERSION)
|
62
|
-
"starling-ruby/v#{Starling::VERSION}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def ruby_engine
|
66
|
-
defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
|
67
|
-
end
|
68
|
-
|
69
|
-
def ruby_version
|
70
|
-
return RUBY_VERSION unless defined?(RUBY_PATCHLEVEL)
|
71
|
-
RUBY_VERSION + "p#{RUBY_PATCHLEVEL}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def interpreter_version
|
75
|
-
defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION
|
76
|
-
end
|
77
85
|
end
|
78
86
|
end
|