revolut-connect 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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/connect.rb +1 -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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b08af3f8efdfcf2b02fce80fce21004a59b416ee3915c78e1747791878129a3
|
4
|
+
data.tar.gz: b84ccc92e6ee0605242a3f729ab18b0ed1fce145dd4d232b3e4d36e5dff51df3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73771ea0352ef2cf70b509c24ff84e536bd77058fe208097da4fe3277657d129350e08753077348a6b43d809426b7d39d5c80aa3f5a9fa1daee7e31e7e031ea9
|
7
|
+
data.tar.gz: 225d751bebc87dafb3920bc8a4d613a926f771cc7ab0a264323919e642a4ff693e9e1171a0332a4d69e3f351e935e4640b404ed609fec71467f970d5f4d56cca
|
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.2)
|
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
|
+
| [![Tests](https://github.com/moraki-finance/revolut-connect/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/moraki-finance/revolut-connect/actions/workflows/main.yml) | [![Codecov Coverage](https://codecov.io/github/moraki-finance/revolut-connect/graph/badge.svg?token=SKTT14JJGV)](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
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "../revolut"
|
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.2
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- Rakefile
|
76
76
|
- lib/revolut.rb
|
77
77
|
- lib/revolut/client.rb
|
78
|
+
- lib/revolut/connect.rb
|
78
79
|
- lib/revolut/http.rb
|
79
80
|
- lib/revolut/middlewares/catch_error.rb
|
80
81
|
- lib/revolut/resources/account.rb
|