revolut-connect 0.1.0 → 0.1.1
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/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +15 -5
- data/lib/revolut/client.rb +2 -0
- data/lib/revolut/http.rb +1 -1
- data/lib/revolut/middlewares/catch_error.rb +15 -10
- data/lib/revolut/resources/auth.rb +26 -5
- data/lib/revolut/version.rb +1 -1
- data/lib/revolut.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaa3d08b4482201ea41200d2968900654790c24c29aaa7d2b9f2d55708711343
|
4
|
+
data.tar.gz: ac2db034b2f14493f620052056cb2691b57162289f242ed6fa16bf03d84a26a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8014cbb4379beb6eccd20b0a8dc7c67e3746638eb1ad0435b522d998aa12f87ced1672e2b33627b266bff390c3ab3ebd240543179f29861c6b5e94e627cd1ba3
|
7
|
+
data.tar.gz: f1c2c09b9fc86fb9319befb7fe9e97bb55b823f1f8a4dca8731f0414365da4b9a0ee0a3abd6d9612a93924920c80e3c75e19caebdc4d30ebb1240a2f95a8f97a
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
revolut-connect (0.1.
|
4
|
+
revolut-connect (0.1.1)
|
5
5
|
faraday (>= 1)
|
6
6
|
faraday-retry (>= 1)
|
7
7
|
jwt (>= 1)
|
@@ -114,6 +114,7 @@ GEM
|
|
114
114
|
standard-performance (1.3.1)
|
115
115
|
lint_roller (~> 1.1)
|
116
116
|
rubocop-performance (~> 1.20.2)
|
117
|
+
timecop (0.9.8)
|
117
118
|
unicode-display_width (2.5.0)
|
118
119
|
uri (0.13.0)
|
119
120
|
webmock (3.23.0)
|
@@ -137,6 +138,7 @@ DEPENDENCIES
|
|
137
138
|
simplecov
|
138
139
|
simplecov-cobertura
|
139
140
|
standard (~> 1.3)
|
141
|
+
timecop
|
140
142
|
webmock (~> 3.23.0)
|
141
143
|
|
142
144
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Revolut Connect
|
2
2
|
|
3
|
-
<a href="https://codecov.io/github/moraki-finance/revolut-connect" >
|
4
|
-
<img src="https://codecov.io/github/moraki-finance/revolut-connect/graph/badge.svg?token=SKTT14JJGV"/>
|
5
|
-
</a>
|
6
3
|
|
7
|
-
|
4
|
+
| Tests | Coverage |
|
5
|
+
|:-:|:-:|
|
6
|
+
| [](https://github.com/moraki-finance/revolut-connect/actions/workflows/main.yml) | [](https://codecov.io/github/moraki-finance/revolut-connect) |
|
8
7
|
|
9
|
-
A lightweight API
|
8
|
+
A lightweight API client for Revolut featuring authentication, permission scopes, token expiration and automatic renewal.
|
9
|
+
|
10
|
+
Revolut docs: <https://developer.revolut.com/>
|
10
11
|
|
11
12
|
_:warning: The extracted API objects don't do input parameters validations. It's a simple faraday wrapper that allows you to send as many inputs as you want. The Revolut API might fail when passing a wrong set of parameters._
|
12
13
|
|
@@ -131,6 +132,15 @@ Revolut.configure do |config|
|
|
131
132
|
# Default: example.com
|
132
133
|
config.iss = ENV["REVOLUT_ISS"]
|
133
134
|
|
135
|
+
# Optional: JWT token duration. After this duration, the token will be renewed (for security reasons, in case of token leakage)
|
136
|
+
# Default: 120 seconds (2 minutes).
|
137
|
+
config.token_duration = ENV["REVOLUT_TOKEN_DURATION"]
|
138
|
+
|
139
|
+
# Optional: Revolut authorization scope. You can restrict which features the app will have access to by passing different scopes.
|
140
|
+
# More info in https://developer.revolut.com/docs/business/business-api
|
141
|
+
# Default: nil
|
142
|
+
config.scope = ENV["REVOLUT_SCOPE"]
|
143
|
+
|
134
144
|
# Optional: Timeout of the underlying faraday requests.
|
135
145
|
# Default: 120
|
136
146
|
config.request_timeout = 120
|
data/lib/revolut/client.rb
CHANGED
data/lib/revolut/http.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
# Helper middleware only intended to be used in the console.
|
2
2
|
# The idea is to have a fast extraction of the API error message from the response body.
|
3
|
-
class CatchError < Faraday::Middleware
|
4
|
-
def on_complete(env)
|
5
|
-
raise_error_middleware.on_complete(env)
|
6
|
-
rescue Faraday::Error => e
|
7
|
-
raise e, JSON.parse(e.response[:body])["message"]
|
8
|
-
end
|
9
3
|
|
10
|
-
|
4
|
+
module Revolut
|
5
|
+
module Middleware
|
6
|
+
class CatchError < Faraday::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
raise_error_middleware.on_complete(env)
|
9
|
+
rescue Faraday::Error => e
|
10
|
+
raise e, JSON.parse(e.response[:body])["message"]
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
def raise_error_middleware
|
16
|
+
@raise_error_middleware ||= Faraday::Response::RaiseError.new
|
17
|
+
end
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
|
-
Faraday::Response.register_middleware catch_error: CatchError
|
22
|
+
Faraday::Response.register_middleware catch_error: Revolut::Middleware::CatchError
|
@@ -2,6 +2,8 @@ require "jwt"
|
|
2
2
|
|
3
3
|
module Revolut
|
4
4
|
class Auth < Resource
|
5
|
+
shallow
|
6
|
+
|
5
7
|
class NotAuthorizedError < StandardError
|
6
8
|
def initialize
|
7
9
|
super(
|
@@ -21,7 +23,11 @@ module Revolut
|
|
21
23
|
#
|
22
24
|
# @return [String] The authorization URL.
|
23
25
|
def authorize_url
|
24
|
-
|
26
|
+
URI::HTTPS.build(
|
27
|
+
host: authorize_uri_host,
|
28
|
+
path: "/app-confirm",
|
29
|
+
query: "client_id=#{Revolut.config.client_id}&redirect_uri=#{Revolut.config.authorize_redirect_uri}&response_type=code" + (Revolut.config.scope ? "&scope=#{Revolut.config.scope}" : "")
|
30
|
+
).to_s + "#authorise"
|
25
31
|
end
|
26
32
|
|
27
33
|
# Exchanges the authorization code for an access token.
|
@@ -90,6 +96,15 @@ module Revolut
|
|
90
96
|
expires_at && Time.now.to_i >= @expires_at
|
91
97
|
end
|
92
98
|
|
99
|
+
# Checks if the user is authenticated.
|
100
|
+
#
|
101
|
+
# Returns:
|
102
|
+
# - true if the access token is present and not expired
|
103
|
+
# - false otherwise
|
104
|
+
def authenticated?
|
105
|
+
!@access_token.nil? && !expired?
|
106
|
+
end
|
107
|
+
|
93
108
|
# Loads authentication information from environment variable REVOLUT_AUTH_JSON.
|
94
109
|
#
|
95
110
|
# If the access token is not already set and the environment variable REVOLUT_AUTH_JSON is present,
|
@@ -107,12 +122,18 @@ module Revolut
|
|
107
122
|
load(JSON.parse(env_json))
|
108
123
|
end
|
109
124
|
|
125
|
+
# Clears the authentication information.
|
126
|
+
def clear
|
127
|
+
@access_token = nil
|
128
|
+
@token_type = nil
|
129
|
+
@expires_at = nil
|
130
|
+
@refresh_token = nil
|
131
|
+
end
|
132
|
+
|
110
133
|
private
|
111
134
|
|
112
|
-
def
|
113
|
-
Revolut.sandbox? ?
|
114
|
-
"https://sandbox-business.revolut.com/app-confirm" :
|
115
|
-
"https://business.revolut.com/app-confirm"
|
135
|
+
def authorize_uri_host
|
136
|
+
Revolut.sandbox? ? "sandbox-business.revolut.com" : "business.revolut.com"
|
116
137
|
end
|
117
138
|
end
|
118
139
|
end
|
data/lib/revolut/version.rb
CHANGED
data/lib/revolut.rb
CHANGED
@@ -21,13 +21,14 @@ module Revolut
|
|
21
21
|
class NotImplementedError < Error; end
|
22
22
|
|
23
23
|
class Configuration
|
24
|
-
attr_accessor :request_timeout, :global_headers, :environment
|
24
|
+
attr_accessor :request_timeout, :global_headers, :environment, :token_duration, :scope
|
25
25
|
attr_writer :client_id, :signing_key, :iss, :authorize_redirect_uri
|
26
26
|
attr_reader :base_uri
|
27
27
|
|
28
28
|
DEFAULT_BASE_URI = "https://sandbox-b2b.revolut.com/api/1.0/"
|
29
29
|
DEFAULT_ENVIRONMENT = "sandbox"
|
30
30
|
DEFAULT_REQUEST_TIMEOUT = 120
|
31
|
+
DEFAULT_TOKEN_DURATION = 120 # 2 minutes
|
31
32
|
|
32
33
|
def initialize
|
33
34
|
@request_timeout = DEFAULT_REQUEST_TIMEOUT
|
@@ -36,6 +37,8 @@ module Revolut
|
|
36
37
|
@signing_key = ENV["REVOLUT_SIGNING_KEY"]&.gsub("\\n", "\n")
|
37
38
|
@iss = ENV.fetch("REVOLUT_ISS", "example.com")
|
38
39
|
@authorize_redirect_uri = ENV["REVOLUT_AUTHORIZE_REDIRECT_URI"]
|
40
|
+
@token_duration = ENV.fetch("REVOLUT_TOKEN_DURATION", DEFAULT_TOKEN_DURATION)
|
41
|
+
@scope = ENV["REVOLUT_SCOPE"]
|
39
42
|
@environment = ENV.fetch("REVOLUT_ENVIRONMENT", DEFAULT_ENVIRONMENT).to_sym
|
40
43
|
@base_uri = (environment == :sandbox) ? "https://sandbox-b2b.revolut.com/api/1.0/" : "https://b2b.revolut.com/api/1.0/"
|
41
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revolut-connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Mochetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|