tide-api 0.2.0 → 0.3.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/CHANGELOG.md +7 -0
- data/README.md +65 -10
- data/bin/tide +9 -0
- data/lib/tide/api/auth_server.rb +68 -0
- data/lib/tide/api/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08178e48252d17a39c560d70c0d82cb68bb70c0eb7723789c34a927a0f6f585d'
|
4
|
+
data.tar.gz: ab105cfc9a5d77a36d8c2c256fc2ce43780333ac816d6593e275f506b2ab1b49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a50e7f1673260d44648ef43c65f15608ccb2e01f3b08b12433f0dbdbaf5fb8e5a29bd88cddf38f40636b8e70c754be9a84e731d87d1c04d800079d63cb0fbcc
|
7
|
+
data.tar.gz: 1b0c7f27c1b17f4cda5b4349dc41662ed19d7053b734839963eed9bcdcb5d04caf3ac42565389d3ab80da57a3e1eb3b170cd3a159c9e7a96391b2cdbce0c0458
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.3.0] - 2019-06-30
|
8
|
+
### Added
|
9
|
+
- An HTTP server to capture Authentication Grant Codes from OAuth2 callbacks
|
10
|
+
|
7
11
|
## [0.2.0] - 2019-06-30
|
8
12
|
### Added
|
9
13
|
- Initial core business logic
|
@@ -11,3 +15,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
11
15
|
## [0.1.0] - 2019-05-26
|
12
16
|
### Added
|
13
17
|
- Codebase maintenance tools
|
18
|
+
|
19
|
+
[0.3.0]: https://github.com/wilsonsilva/tide-api/compare/v0.2.0...v0.3.0
|
20
|
+
[0.2.0]: https://github.com/wilsonsilva/tide-api/compare/v0.1.0...v0.2.0
|
data/README.md
CHANGED
@@ -9,6 +9,20 @@
|
|
9
9
|
|
10
10
|
Ruby interface to Tide's bank RESTful API.
|
11
11
|
|
12
|
+
## Table of contents
|
13
|
+
- [Installation](#installation)
|
14
|
+
- [Usage](#usage)
|
15
|
+
- [Authentication](#authentication)
|
16
|
+
- [Obtaining an Authorization Grant Code](#obtaining-an-azuthorization-grant-code)
|
17
|
+
- [Exchanging an Authorisation Grant for an Access Token](#exchanging-an-authorisation-grant-for-an-access-token)
|
18
|
+
- [Fetching Companies](#fetching-companies)
|
19
|
+
- [Fetching Accounts](#fetching-accounts)
|
20
|
+
- [Fetching Transactions](#fetching-transactions)
|
21
|
+
- [Development](#development)
|
22
|
+
- [Contributing](#contributing)
|
23
|
+
- [License](#license)
|
24
|
+
- [Code of Conduct](#code-of-conduct)
|
25
|
+
|
12
26
|
## Installation
|
13
27
|
|
14
28
|
Add this line to your application's Gemfile:
|
@@ -27,28 +41,69 @@ Or install it yourself as:
|
|
27
41
|
|
28
42
|
## Usage
|
29
43
|
|
30
|
-
|
31
|
-
|
44
|
+
### Authentication
|
45
|
+
|
46
|
+
Tide uses `Access Tokens` to allow access to the API via OAuth 2. Tide uses `Access Token`s to allow access to the
|
47
|
+
API via OAuth 2. You can obtain an OAuth 2 `Access Toke`n by navigating to the below url, either in the web application
|
48
|
+
or through an in-app browser window:
|
49
|
+
|
50
|
+
`https://api.tide.co/tide-backend/oauth/index.html?redirect_url={url}&client_id={unique_id}`
|
51
|
+
|
52
|
+
| Parameter | Type | Description |
|
53
|
+
| --- | --- | --- |
|
54
|
+
| `redirect_uri` | string | Fully qualified URL to which `Authorisation Grants` will be delivered to. Grants will be delivered only on successful authorisation by resource owner. |
|
55
|
+
| `client_id` | string | Unique identifier for the requester. |
|
56
|
+
|
57
|
+
Once the page loads, the user needs to enter the unique email address, which is registered on their Tide account.
|
32
58
|
|
33
|
-
|
34
|
-
automate the
|
59
|
+
### Obtaining an Authorization Grant Code
|
60
|
+
Use the bundled minimalistic AuthServer to automate the process above:
|
35
61
|
|
36
62
|
```ruby
|
37
63
|
require 'tide/api'
|
64
|
+
require 'tide/api/auth_server'
|
38
65
|
|
39
|
-
|
66
|
+
server = Tide::API::AuthServer.new
|
67
|
+
auth_grant_code = server.run
|
68
|
+
```
|
69
|
+
|
70
|
+
`Authorisation Grants` can only be used once off by the client, once used they are expired and cannot be used to issue
|
71
|
+
new `Access Tokens`.
|
40
72
|
|
41
|
-
|
42
|
-
|
73
|
+
### Exchanging an Authorisation Grant for an Access Token
|
74
|
+
Exchange the authorisation grant code with the method `fetch_tokens`:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
client = Tide::API::Client.new
|
43
78
|
tokens = client.fetch_tokens(auth_grant_code)
|
44
79
|
|
45
|
-
#
|
80
|
+
# Tokens contains an access token and a refresh token
|
81
|
+
tokens.access_token
|
82
|
+
tokens.refresh_token
|
83
|
+
````
|
84
|
+
|
85
|
+
Fetch tokens will configure the client the behind the scenes to make authenticated requests.
|
86
|
+
|
87
|
+
## Fetching Companies
|
88
|
+
This method retrieves a collection of companies with the user. The user is determined from authorization header.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
client = Tide::API::Client.new
|
46
92
|
companies = client.fetch_companies
|
93
|
+
````
|
94
|
+
|
95
|
+
## Fetching Accounts
|
96
|
+
This method retrieves a collection of company accounts associated with the user. The user is determined from
|
97
|
+
authorization header.
|
47
98
|
|
48
|
-
|
99
|
+
```ruby
|
49
100
|
accounts = client.fetch_accounts(companies.first.id)
|
101
|
+
````
|
50
102
|
|
51
|
-
|
103
|
+
## Fetching Transactions
|
104
|
+
This method retrieves a collection of an account's transactions:
|
105
|
+
|
106
|
+
```ruby
|
52
107
|
transactions = client.fetch_transactions(accounts.first.id)
|
53
108
|
```
|
54
109
|
|
data/bin/tide
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# typed: true
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module Tide
|
5
|
+
module API
|
6
|
+
# Receives an authorization grant code from the OAuth2 callback.
|
7
|
+
class AuthServer
|
8
|
+
# This is the ID shown in the authorization page of the mobile app
|
9
|
+
CLIENT_ID = 'tide-api-gem'.freeze
|
10
|
+
# Complete HTTP response
|
11
|
+
RESPONSE = "HTTP/1.1 200 OK\r\n" \
|
12
|
+
"Content-Type: text/plain\r\n" \
|
13
|
+
"Content-Length: 31\r\n" \
|
14
|
+
"Connection: close\r\n" \
|
15
|
+
"\r\n" \
|
16
|
+
"You can now close this window.\n".freeze
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@server = TCPServer.new('localhost', 0)
|
20
|
+
@port = server.addr[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Runs a tiny HTTP server to receive OAuth2 callbacks.
|
24
|
+
#
|
25
|
+
# @return [String] The authentication grant code from Tide.
|
26
|
+
#
|
27
|
+
def run
|
28
|
+
puts 'Waiting for the authorization code...'
|
29
|
+
request_auth_nonce
|
30
|
+
|
31
|
+
socket = server.accept
|
32
|
+
auth_nonce = extract_auth_nonce(socket.gets)
|
33
|
+
|
34
|
+
puts 'Authorization code received.'
|
35
|
+
|
36
|
+
socket.print RESPONSE
|
37
|
+
socket.close
|
38
|
+
|
39
|
+
auth_nonce
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# @api private
|
45
|
+
def request_auth_nonce
|
46
|
+
system("open '#{auth_page_url}'")
|
47
|
+
end
|
48
|
+
|
49
|
+
# @api private
|
50
|
+
def redirect_url
|
51
|
+
"http://localhost:#{port}&client_id=#{CLIENT_ID}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# @api private
|
55
|
+
def auth_page_url
|
56
|
+
"https://api.tide.co/tide-backend/oauth/index.html?redirect_url=#{redirect_url}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# @api private
|
60
|
+
def extract_auth_nonce(http_response_line)
|
61
|
+
http_response_line.split('=').last.split.first
|
62
|
+
end
|
63
|
+
|
64
|
+
# @api private
|
65
|
+
attr_reader :server, :port
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/tide/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tide-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Silva
|
@@ -343,8 +343,10 @@ files:
|
|
343
343
|
- Rakefile
|
344
344
|
- bin/console
|
345
345
|
- bin/setup
|
346
|
+
- bin/tide
|
346
347
|
- lib/tide/api.rb
|
347
348
|
- lib/tide/api/account.rb
|
349
|
+
- lib/tide/api/auth_server.rb
|
348
350
|
- lib/tide/api/client.rb
|
349
351
|
- lib/tide/api/company.rb
|
350
352
|
- lib/tide/api/error.rb
|