ecoportal-api-graphql 0.3.3 → 0.3.5
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 +17 -1
- data/lib/ecoportal/api/common/graphql/auth_service.rb +48 -4
- data/lib/ecoportal/api/common/graphql/client.rb +1 -1
- data/lib/ecoportal/api/graphql/helpers/locations_tree.rb +1 -3
- data/lib/ecoportal/api/graphql.rb +3 -2
- data/lib/ecoportal/api/graphql_version.rb +1 -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: 0d37cda00c6ee7d64fb29829b592c73838b384726cb328b57cd228969f0e6103
|
4
|
+
data.tar.gz: 5d18a917e0e338e46f65d9132b96b4b032979856da5524426d2d92e43cbf5aee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11d595232646fe8fc8b3096e77bcedd1d6ee635b74cdc25c6c6743607727c9e8e4a98f0538fb60226d6337407105cb6b8c347ebad4d3cf6dcbacf3329baf0ea9
|
7
|
+
data.tar.gz: '0926f7ce7f600ca7b8d1badabe4a7f9c6733daa5d5ebb535e5ced1835e1bc52015138409034cb5229c32534d3f0e4f2799bf58d15f4f5b94eafda33fd713059d'
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [0.3.
|
4
|
+
## [0.3.6] - 2023-04-xx
|
5
5
|
|
6
6
|
### Added
|
7
7
|
### Changed
|
@@ -14,6 +14,22 @@ All notable changes to this project will be documented in this file.
|
|
14
14
|
|
15
15
|
- review `path` tracking
|
16
16
|
|
17
|
+
## [0.3.5] - 2023-04-03
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- `Ecoportal::API::GraphQL::Helpers::LocationsTree#treeify`
|
21
|
+
- Make it real id-case-insensitive (parents in lower case were being missed due to this)
|
22
|
+
|
23
|
+
## [0.3.4] - 2023-04-03
|
24
|
+
|
25
|
+
### Added
|
26
|
+
- `Ecoportal::API::Common::GraphQL::AuthService`
|
27
|
+
- `#session_token` added **token auto-renew** functionality (when token expires in less than 90 minutes)
|
28
|
+
- `#session_token_renewed`
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
- Enabled to specify `host` (other than `live.ecoportal.com`) by the user
|
32
|
+
|
17
33
|
## [0.3.3] - 2023-04-02
|
18
34
|
|
19
35
|
### Fixed
|
@@ -3,20 +3,64 @@ module Ecoportal
|
|
3
3
|
module Common
|
4
4
|
module GraphQL
|
5
5
|
module AuthService
|
6
|
-
DEFAULT_SERVER
|
6
|
+
DEFAULT_SERVER = "live.ecoportal.com"
|
7
|
+
TOKEN_AUTORENEW = 90 # minutes
|
7
8
|
|
8
9
|
module InstanceMethods
|
9
|
-
def session_token(host: server, version: nil)
|
10
|
+
def session_token(host: server, version: nil, auto_renew: true)
|
11
|
+
session_token_data(host: host, version: version).yield_self do |body|
|
12
|
+
return nil unless body
|
13
|
+
if auto_renew && token_renew?(body["expires_in"])
|
14
|
+
session_token_renewed(host: host, version: version, refresh_token: body["refresh_token"])
|
15
|
+
else
|
16
|
+
body["access_token"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def session_token_renewed(host: server, version: nil, refresh_token: nil)
|
22
|
+
unless refresh_token
|
23
|
+
return nil unless body = session_token_data(host: host, version: version)
|
24
|
+
return nil unless refresh_token = body["resfresh_token"]
|
25
|
+
end
|
26
|
+
session_refresh_token_data(host: host, version: version, refresh_token: refresh_token).yield_self do |body|
|
27
|
+
return nil unless body
|
28
|
+
body["access_token"] if body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def session_token_data(host: server, version: nil)
|
10
35
|
http_client(host: host, version: version).post("/oauth/token", data: {
|
11
36
|
"grant_type" => "password",
|
12
37
|
"email" => user_email,
|
13
38
|
"password" => user_pass
|
14
39
|
}).yield_self do |response|
|
15
|
-
|
40
|
+
if response.success?
|
41
|
+
response.body
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
16
45
|
end
|
17
46
|
end
|
18
47
|
|
19
|
-
|
48
|
+
def session_refresh_token_data(host: server, version: nil, refresh_token:)
|
49
|
+
http_client(host: host, version: version).post("/oauth/token", data: {
|
50
|
+
"grant_type" => "refresh_token",
|
51
|
+
"refresh_token" => refresh_token
|
52
|
+
}).yield_self do |response|
|
53
|
+
if response.success?
|
54
|
+
response.body
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def token_renew?(seconds)
|
62
|
+
(TOKEN_AUTORENEW * 60) > seconds
|
63
|
+
end
|
20
64
|
|
21
65
|
def http_client(host: server, version: nil)
|
22
66
|
@http_client ||= Ecoportal::API::Common::GraphQL::HttpClient.new(host: host, version: version)
|
@@ -6,8 +6,6 @@ module Ecoportal
|
|
6
6
|
def treeify(nodes)
|
7
7
|
parents = nodes.each_with_object({}) do |node, parents|
|
8
8
|
parent = node.parent
|
9
|
-
# puts "Node '#{node.name}' with ID: '#{node.id}'. "
|
10
|
-
# puts " • Parent '#{parent.name}' with ID: '#{parent.id}'." if parent
|
11
9
|
parentId = parent && parent.id.upcase
|
12
10
|
(parents[parentId] ||= []).push(node)
|
13
11
|
end
|
@@ -17,7 +15,7 @@ module Ecoportal
|
|
17
15
|
private
|
18
16
|
|
19
17
|
def get_children(node_id, parents)
|
20
|
-
(parents[node_id] ||= []).each_with_object([]) do |child, results|
|
18
|
+
(parents[node_id&.upcase] ||= []).each_with_object([]) do |child, results|
|
21
19
|
results << {
|
22
20
|
"id" => child.id,
|
23
21
|
"name" => child.name,
|
@@ -11,8 +11,9 @@ module Ecoportal
|
|
11
11
|
# @param org_id [String] the id of the target organization.
|
12
12
|
# It defaults to the environmental variable `ORGANIZATION_ID`, if defined
|
13
13
|
# @param logger [Logger] an object with `Logger` interface to generate logs.
|
14
|
-
def initialize(email: nil, pass: nil, org_id: nil)
|
15
|
-
|
14
|
+
def initialize(email: nil, pass: nil, org_id: nil, host: "live.ecoportal.com")
|
15
|
+
kargs = {email: email, pass: pass, host: host, org_id: org_id, no_schema: true}
|
16
|
+
@client = Ecoportal::API::Common::GraphQL::Client.new(**kargs)
|
16
17
|
@fragments = Ecoportal::API::GraphQL::Fragment.new(client)
|
17
18
|
end
|
18
19
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|