starling_terminal 0.1.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 +7 -0
- data/.circleci/config.yml +75 -0
- data/.gitignore +10 -0
- data/.reek +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +115 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/exe/starling +7 -0
- data/lib/starling_terminal.rb +17 -0
- data/lib/starling_terminal/errors/invalid_access_token_error.rb +11 -0
- data/lib/starling_terminal/errors/missing_access_token_error.rb +14 -0
- data/lib/starling_terminal/statement.rb +88 -0
- data/lib/starling_terminal/transaction_row.rb +27 -0
- data/lib/starling_terminal/utils.rb +44 -0
- data/lib/starling_terminal/version.rb +5 -0
- data/starling_terminal.gemspec +38 -0
- metadata +235 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 169b0cbf514f24ae52ab5a025c299abbf95fe032
|
4
|
+
data.tar.gz: 6c7204b1e8561dab223d87127e97d5bee0b65ce3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da1e12faef1fe5c31d33cc387dcd984ca9c6f3193247fbedce6b037820417b19940372606ee15d0ef47af50adde8167b80e2ef0e55b955796b2c6ee2717fd4fb
|
7
|
+
data.tar.gz: f13cbd13cdf823c2a547f3f097ed650e1dd1bceff082268ff6ed955df1eaf3dea092b5836a2f983b1ccda4df15507e9fe49b132b91fdc374017d7a48553224d0
|
@@ -0,0 +1,75 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
working_directory: /home/circleci/starling-terminal
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.4.1-node
|
7
|
+
steps:
|
8
|
+
- run:
|
9
|
+
name: Trigger Jobs
|
10
|
+
command: |
|
11
|
+
function trigger_job() {
|
12
|
+
job_name=$1
|
13
|
+
curl -u ${CIRCLE_API_TOKEN}: \
|
14
|
+
-d build_parameters[CIRCLE_JOB]=${job_name} \
|
15
|
+
-d revision=$CIRCLE_SHA1 \
|
16
|
+
https://circleci.com/api/v1.1/project/github/timrogers/starling-terminal/tree/$CIRCLE_BRANCH
|
17
|
+
}
|
18
|
+
trigger_job build-ruby241
|
19
|
+
trigger_job build-ruby234
|
20
|
+
trigger_job build-ruby227
|
21
|
+
build-ruby241:
|
22
|
+
docker:
|
23
|
+
- image: circleci/ruby:2.4.1-node
|
24
|
+
working_directory: /home/circleci/starling-terminal
|
25
|
+
steps: &common-steps
|
26
|
+
- checkout
|
27
|
+
|
28
|
+
# Restore bundle cache
|
29
|
+
- type: cache-restore
|
30
|
+
key: starling-terminal-{{ checksum "Gemfile.lock" }}
|
31
|
+
|
32
|
+
# Update bundler
|
33
|
+
- run: gem install bundler
|
34
|
+
|
35
|
+
# Bundle install dependencies
|
36
|
+
- run: bundle install --path vendor/bundle
|
37
|
+
|
38
|
+
# Store bundle cache
|
39
|
+
- type: cache-save
|
40
|
+
key: starling-terminal-{{ checksum "Gemfile.lock" }}
|
41
|
+
paths:
|
42
|
+
- vendor/bundle
|
43
|
+
|
44
|
+
# Run RSpec in parallel
|
45
|
+
- type: shell
|
46
|
+
command: |
|
47
|
+
bundle exec rspec --profile 10 \
|
48
|
+
--format RspecJunitFormatter \
|
49
|
+
--out /tmp/test-results/rspec.xml \
|
50
|
+
--format progress \
|
51
|
+
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
|
52
|
+
|
53
|
+
# Run Rubocop
|
54
|
+
- type: shell
|
55
|
+
command: |
|
56
|
+
bundle exec rubocop
|
57
|
+
|
58
|
+
# Run Reek
|
59
|
+
- type: shell
|
60
|
+
command: |
|
61
|
+
bundle exec reek lib
|
62
|
+
|
63
|
+
# Save artifacts
|
64
|
+
- type: store_test_results
|
65
|
+
path: /tmp/test-results
|
66
|
+
build-ruby234:
|
67
|
+
docker:
|
68
|
+
- image: circleci/ruby:2.3.4-node
|
69
|
+
working_directory: /home/circleci/starling-terminal
|
70
|
+
steps: *common-steps
|
71
|
+
build-ruby227:
|
72
|
+
docker:
|
73
|
+
- image: circleci/ruby:2.2.7-node
|
74
|
+
working_directory: /home/circleci/starling-terminal
|
75
|
+
steps: *common-steps
|
data/.gitignore
ADDED
data/.reek
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tim@gocardless.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
starling_terminal (0.1.0)
|
5
|
+
colorize (~> 0.8.1)
|
6
|
+
starling-ruby (~> 0.2.0)
|
7
|
+
terminal-table (~> 1.8.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.5.1)
|
13
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
14
|
+
ast (2.3.0)
|
15
|
+
axiom-types (0.1.1)
|
16
|
+
descendants_tracker (~> 0.0.4)
|
17
|
+
ice_nine (~> 0.11.0)
|
18
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
19
|
+
builder (3.2.3)
|
20
|
+
codeclimate-engine-rb (0.4.0)
|
21
|
+
virtus (~> 1.0)
|
22
|
+
coderay (1.1.1)
|
23
|
+
coercible (1.0.0)
|
24
|
+
descendants_tracker (~> 0.0.1)
|
25
|
+
colorize (0.8.1)
|
26
|
+
crack (0.4.3)
|
27
|
+
safe_yaml (~> 1.0.0)
|
28
|
+
descendants_tracker (0.0.4)
|
29
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
30
|
+
diff-lcs (1.3)
|
31
|
+
equalizer (0.0.11)
|
32
|
+
faraday (0.9.2)
|
33
|
+
multipart-post (>= 1.2, < 3)
|
34
|
+
hashdiff (0.3.4)
|
35
|
+
ice_nine (0.11.2)
|
36
|
+
method_source (0.8.2)
|
37
|
+
multipart-post (2.0.0)
|
38
|
+
parallel (1.11.2)
|
39
|
+
parser (2.4.0.0)
|
40
|
+
ast (~> 2.2)
|
41
|
+
powerpack (0.1.1)
|
42
|
+
pry (0.10.4)
|
43
|
+
coderay (~> 1.1.0)
|
44
|
+
method_source (~> 0.8.1)
|
45
|
+
slop (~> 3.4)
|
46
|
+
public_suffix (2.0.5)
|
47
|
+
rainbow (2.2.2)
|
48
|
+
rake
|
49
|
+
rake (12.0.0)
|
50
|
+
reek (4.7.0)
|
51
|
+
codeclimate-engine-rb (~> 0.4.0)
|
52
|
+
parser (>= 2.4.0.0, < 2.5)
|
53
|
+
rainbow (~> 2.0)
|
54
|
+
rspec (3.6.0)
|
55
|
+
rspec-core (~> 3.6.0)
|
56
|
+
rspec-expectations (~> 3.6.0)
|
57
|
+
rspec-mocks (~> 3.6.0)
|
58
|
+
rspec-core (3.6.0)
|
59
|
+
rspec-support (~> 3.6.0)
|
60
|
+
rspec-expectations (3.6.0)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.6.0)
|
63
|
+
rspec-mocks (3.6.0)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.6.0)
|
66
|
+
rspec-snapshot (0.1.1)
|
67
|
+
rspec (> 3.0.0)
|
68
|
+
rspec-support (3.6.0)
|
69
|
+
rspec_junit_formatter (0.2.3)
|
70
|
+
builder (< 4)
|
71
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
72
|
+
rubocop (0.49.1)
|
73
|
+
parallel (~> 1.10)
|
74
|
+
parser (>= 2.3.3.1, < 3.0)
|
75
|
+
powerpack (~> 0.1)
|
76
|
+
rainbow (>= 1.99.1, < 3.0)
|
77
|
+
ruby-progressbar (~> 1.7)
|
78
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
79
|
+
ruby-progressbar (1.8.1)
|
80
|
+
safe_yaml (1.0.4)
|
81
|
+
slop (3.6.0)
|
82
|
+
starling-ruby (0.2.0)
|
83
|
+
faraday (>= 0.8.9, < 0.10)
|
84
|
+
terminal-table (1.8.0)
|
85
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
86
|
+
thread_safe (0.3.6)
|
87
|
+
unicode-display_width (1.2.1)
|
88
|
+
virtus (1.0.5)
|
89
|
+
axiom-types (~> 0.1)
|
90
|
+
coercible (~> 1.0)
|
91
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
92
|
+
equalizer (~> 0.0, >= 0.0.9)
|
93
|
+
webmock (3.0.1)
|
94
|
+
addressable (>= 2.3.6)
|
95
|
+
crack (>= 0.3.2)
|
96
|
+
hashdiff
|
97
|
+
yard (0.8.7.6)
|
98
|
+
|
99
|
+
PLATFORMS
|
100
|
+
ruby
|
101
|
+
|
102
|
+
DEPENDENCIES
|
103
|
+
bundler (~> 1.15)
|
104
|
+
pry (~> 0.10.4)
|
105
|
+
reek (~> 4.7.0)
|
106
|
+
rspec (~> 3.0)
|
107
|
+
rspec-snapshot (~> 0.1.1)
|
108
|
+
rspec_junit_formatter (~> 0.2.3)
|
109
|
+
rubocop (~> 0.49.0)
|
110
|
+
starling_terminal!
|
111
|
+
webmock (~> 3.0.1)
|
112
|
+
yard (~> 0.8.7.6)
|
113
|
+
|
114
|
+
BUNDLED WITH
|
115
|
+
1.15.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Tim Rogers
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Starling Terminal
|
2
|
+
|
3
|
+
Starling Terminal lets you view your [Starling Bank](https://starlingbank.com) statement
|
4
|
+
right from your terminal. It's built on the open-source
|
5
|
+
[starling-ruby](https://github.com/timrogers/starling-ruby) library for the
|
6
|
+
[Starling Bank API](https://developer.starlingbank.com).
|
7
|
+
|
8
|
+
[](https://circleci.com/gh/timrogers/starling-terminal/tree/master)
|
9
|
+
[](https://badge.fury.io/rb/starling_terminal)
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Install the gem:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install starling_terminal
|
17
|
+
```
|
18
|
+
|
19
|
+
You'll need to get a personal access token for your Starling account. To get set up,
|
20
|
+
head to the Starling Developers
|
21
|
+
["Get Started" page](https://developer.starlingbank.com/get-started) and then scroll
|
22
|
+
down to the "Personal Access" section for instructions. Set your access token as
|
23
|
+
the environment variable `$STARLING_ACCESS_TOKEN`.
|
24
|
+
|
25
|
+
View your Starling Bank statement from your terminal:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
starling
|
29
|
+
```
|
30
|
+
|
31
|
+
## Tests
|
32
|
+
|
33
|
+
The library must pass code checks by RSpec, Rubocop and Reek:
|
34
|
+
|
35
|
+
* `bundle exec rspec spec`: checks the library against automated tests we've written
|
36
|
+
* `bundle exec rubocop`: checks the code against established Ruby code style
|
37
|
+
* `bundle exec reek lib`: checks the code for "code smells"
|
38
|
+
|
39
|
+
As part of our continuous integration (CI) process, we run RSpec, Rubocop and Reek in
|
40
|
+
CircleCI on Ruby 2.4, Ruby 2.3 and Ruby 2.2. Feel free to push up your branch and open
|
41
|
+
a pull request to have Circle test your code.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
All contributions are welcome - just make a pull request, making sure you include tests
|
46
|
+
and documentation for any public methods, and write a good, informative commit
|
47
|
+
message/pull request body.
|
48
|
+
|
49
|
+
Check out
|
50
|
+
[CODE_OF_CONDUCT.md](https://github.com/timrogers/starling-terminal/blob/master/CODE_OF_CONDUCT.md)
|
51
|
+
to learn about how we can best work together as an open source community to make the
|
52
|
+
Starling Ruby library as good as it can be.
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/starling
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'colorize'
|
4
|
+
require 'terminal-table'
|
5
|
+
require 'starling'
|
6
|
+
|
7
|
+
require 'starling_terminal/version'
|
8
|
+
require 'starling_terminal/utils'
|
9
|
+
require 'starling_terminal/errors/missing_access_token_error'
|
10
|
+
require 'starling_terminal/errors/invalid_access_token_error'
|
11
|
+
require 'starling_terminal/transaction_row'
|
12
|
+
require 'starling_terminal/statement'
|
13
|
+
|
14
|
+
# Starling Terminal lets you view your [Starling Bank](https://starlingbank.com)
|
15
|
+
# statement right from your terminal.
|
16
|
+
module StarlingTerminal
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StarlingTerminal
|
4
|
+
# Raised if the Starling Bank API access token provided is invalid
|
5
|
+
class InvalidAccessTokenError < StandardError
|
6
|
+
def message
|
7
|
+
'The Starling access token you provided is invalid'
|
8
|
+
end
|
9
|
+
alias to_s message
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StarlingTerminal
|
4
|
+
# Raised if there is no access token provided for accessing the Starling Bank API
|
5
|
+
class MissingAccessTokenError < StandardError
|
6
|
+
def message
|
7
|
+
'Starling Terminal needs an access token to access the Starling Bank API on your' \
|
8
|
+
' behalf. Head to the Personal Access section at https://developer.starlingbank.' \
|
9
|
+
'com/get-started to get started, then set the environment variable ' \
|
10
|
+
'$STARLING_ACCESS_TOKEN.'
|
11
|
+
end
|
12
|
+
alias to_s message
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StarlingTerminal
|
4
|
+
# Builds a Starling statement for output to the terminal
|
5
|
+
class Statement
|
6
|
+
# The headings to be displayed in our table of transactions
|
7
|
+
TRANSACTIONS_TABLE_HEADINGS = ['Narrative',
|
8
|
+
'Amount',
|
9
|
+
'Date and time',
|
10
|
+
'Source'].freeze
|
11
|
+
|
12
|
+
# @param access_token [String] The Starling Bank API access token
|
13
|
+
# @raise [MissingAccessTokenError] if no access token was provided, or it is `nil`
|
14
|
+
def initialize(access_token: ENV['STARLING_ACCESS_TOKEN'])
|
15
|
+
raise MissingAccessTokenError unless access_token
|
16
|
+
@access_token = access_token
|
17
|
+
end
|
18
|
+
|
19
|
+
# Outputs a complete statement to the provided output
|
20
|
+
# @param output [#puts] The output to print the statement to
|
21
|
+
# @raise [InvalidAccessTokenError] if the Starling Bank API access token provided is
|
22
|
+
# invalid
|
23
|
+
# @raise [Starling::Errors::ApiError] if something else goes wrong with the Starling
|
24
|
+
# Bank API
|
25
|
+
# @return [#puts] the output
|
26
|
+
def generate(output: STDOUT)
|
27
|
+
output.puts balance_line
|
28
|
+
output.puts pending_transactions_line
|
29
|
+
output.puts available_to_spend_line
|
30
|
+
output.puts "#{transactions_table}\n\n"
|
31
|
+
output
|
32
|
+
rescue Starling::Errors::ApiError => error
|
33
|
+
raise InvalidAccessTokenError if [401, 403].include?(error.status)
|
34
|
+
raise
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :access_token, :output
|
40
|
+
|
41
|
+
def balance_line
|
42
|
+
amount = account_balance.amount
|
43
|
+
balance_colour = Utils.colour_for_amount(amount)
|
44
|
+
balance = Utils.float_to_currency(amount, currency: account_balance.currency)
|
45
|
+
|
46
|
+
"\n\nBalance: #{balance}".colorize(balance_colour)
|
47
|
+
end
|
48
|
+
|
49
|
+
def pending_transactions_line
|
50
|
+
pending_transactions = Utils.float_to_currency(
|
51
|
+
account_balance.pending_transactions,
|
52
|
+
currency: account_balance.currency
|
53
|
+
)
|
54
|
+
|
55
|
+
"Pending: #{pending_transactions}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def available_to_spend_line
|
59
|
+
available_to_spend = Utils.float_to_currency(
|
60
|
+
account_balance.available_to_spend,
|
61
|
+
currency: account_balance.currency
|
62
|
+
)
|
63
|
+
|
64
|
+
"Available to spend: #{available_to_spend}\n\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
def transactions_table
|
68
|
+
Terminal::Table.new(headings: TRANSACTIONS_TABLE_HEADINGS,
|
69
|
+
rows: transaction_rows)
|
70
|
+
end
|
71
|
+
|
72
|
+
def transaction_rows
|
73
|
+
@transaction_rows = transactions.map { |tx| TransactionRow.present(tx) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def starling
|
77
|
+
@starling ||= Starling::Client.new(access_token: access_token)
|
78
|
+
end
|
79
|
+
|
80
|
+
def account_balance
|
81
|
+
@account_balance ||= starling.account_balance.get
|
82
|
+
end
|
83
|
+
|
84
|
+
def transactions
|
85
|
+
@transactions ||= starling.transactions.list
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StarlingTerminal
|
4
|
+
# A presenter to convert Starling::Resources::TransactionResource instances to
|
5
|
+
# presented rows for our transactions table
|
6
|
+
class TransactionRow
|
7
|
+
# Converts a Starling Bank transaction into a row to be displayed in our transactions
|
8
|
+
# table
|
9
|
+
#
|
10
|
+
# @param transaction [Starling::Resources::TransactionResource] the transaction
|
11
|
+
# resource returned
|
12
|
+
# from the Starling
|
13
|
+
# Bank API
|
14
|
+
# @return [Array<String>] a row suitable for presentation through `Terminal::Table`
|
15
|
+
def self.present(transaction)
|
16
|
+
amount = transaction.amount
|
17
|
+
|
18
|
+
[
|
19
|
+
transaction.narrative,
|
20
|
+
Utils.float_to_currency(amount, currency: transaction.currency)
|
21
|
+
.colorize(Utils.colour_for_amount(amount)),
|
22
|
+
Utils.present_time(transaction.created),
|
23
|
+
transaction.source.to_s
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StarlingTerminal
|
4
|
+
# Utility functions for building, formatting and styling the statement
|
5
|
+
module Utils
|
6
|
+
# A map from currency code (e.g. "GBP", "EUR") to symbol for display in the table
|
7
|
+
CURRENCY_SYMBOLS = {
|
8
|
+
'GBP' => '£',
|
9
|
+
'USD' => '$',
|
10
|
+
'EUR' => '€'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
# Converts a Float to a currency valuable with symbol or code, suitable for display
|
14
|
+
#
|
15
|
+
# @param float [Float] the float to convert to currency
|
16
|
+
# @param currency [String] the currency code (e.g. "GBP", "EUR") which will be
|
17
|
+
# converted to a symbol if possible, or displayed in full
|
18
|
+
# @return [String] the currency amount, suitable for display (e.g. $5.99, 50 UAH)
|
19
|
+
def self.float_to_currency(float, currency:)
|
20
|
+
currency_symbol = CURRENCY_SYMBOLS.fetch(currency, nil)
|
21
|
+
|
22
|
+
return format("#{currency_symbol}%.2f", float) if currency_symbol
|
23
|
+
format("%.2f #{currency}", float)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Presents a Time as a string in the standard UK format
|
27
|
+
#
|
28
|
+
# @param time [Time] the time
|
29
|
+
# @return [String] the string formatted in the standard UK form (e.g.
|
30
|
+
# "4/6/2017 10:00")
|
31
|
+
def self.present_time(time)
|
32
|
+
time.strftime('%-d/%-m/%Y %H:%M')
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the colour an amount should be displayed in (red for negative amounts,
|
36
|
+
# green for positive)
|
37
|
+
#
|
38
|
+
# @param amount [Float] the amount
|
39
|
+
# @return [:red, :green] the colour the amount should be displayed in
|
40
|
+
def self.colour_for_amount(amount)
|
41
|
+
amount.positive? ? :green : :red
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'starling_terminal/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'starling_terminal'
|
10
|
+
spec.version = StarlingTerminal::VERSION
|
11
|
+
spec.authors = ['Tim Rogers']
|
12
|
+
spec.email = ['tim@gocardless.com']
|
13
|
+
|
14
|
+
spec.summary = 'A tool for viewing your Starling Bank statement from your terminal'
|
15
|
+
spec.homepage = 'https://github.com/timrogers/starling-terminal'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'starling-ruby', '~> 0.2.0'
|
26
|
+
spec.add_dependency 'terminal-table', '~> 1.8.0'
|
27
|
+
spec.add_dependency 'colorize', '~> 0.8.1'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.49.0'
|
32
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
33
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.2.3'
|
34
|
+
spec.add_development_dependency 'reek', '~> 4.7.0'
|
35
|
+
spec.add_development_dependency 'rspec-snapshot', '~> 0.1.1'
|
36
|
+
spec.add_development_dependency 'webmock', '~> 3.0.1'
|
37
|
+
spec.add_development_dependency 'yard', '~> 0.8.7.6'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: starling_terminal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Rogers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: starling-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: terminal-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.15'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.15'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.49.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.49.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.10.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.4
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec_junit_formatter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.2.3
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.2.3
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: reek
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 4.7.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 4.7.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-snapshot
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.1.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.1.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 3.0.1
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 3.0.1
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.8.7.6
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.8.7.6
|
181
|
+
description:
|
182
|
+
email:
|
183
|
+
- tim@gocardless.com
|
184
|
+
executables:
|
185
|
+
- starling
|
186
|
+
extensions: []
|
187
|
+
extra_rdoc_files: []
|
188
|
+
files:
|
189
|
+
- ".circleci/config.yml"
|
190
|
+
- ".gitignore"
|
191
|
+
- ".reek"
|
192
|
+
- ".rspec"
|
193
|
+
- ".rubocop.yml"
|
194
|
+
- CODE_OF_CONDUCT.md
|
195
|
+
- Gemfile
|
196
|
+
- Gemfile.lock
|
197
|
+
- LICENSE.txt
|
198
|
+
- README.md
|
199
|
+
- bin/console
|
200
|
+
- bin/setup
|
201
|
+
- exe/starling
|
202
|
+
- lib/starling_terminal.rb
|
203
|
+
- lib/starling_terminal/errors/invalid_access_token_error.rb
|
204
|
+
- lib/starling_terminal/errors/missing_access_token_error.rb
|
205
|
+
- lib/starling_terminal/statement.rb
|
206
|
+
- lib/starling_terminal/transaction_row.rb
|
207
|
+
- lib/starling_terminal/utils.rb
|
208
|
+
- lib/starling_terminal/version.rb
|
209
|
+
- starling_terminal.gemspec
|
210
|
+
homepage: https://github.com/timrogers/starling-terminal
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
metadata: {}
|
214
|
+
post_install_message:
|
215
|
+
rdoc_options: []
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
requirements: []
|
229
|
+
rubyforge_project:
|
230
|
+
rubygems_version: 2.6.11
|
231
|
+
signing_key:
|
232
|
+
specification_version: 4
|
233
|
+
summary: A tool for viewing your Starling Bank statement from your terminal
|
234
|
+
test_files: []
|
235
|
+
has_rdoc:
|