ecoportal-api-graphql 0.3.1 → 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 +28 -1
- data/ecoportal-api-graphql.gemspec +1 -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/base/location_node.rb +1 -0
- data/lib/ecoportal/api/graphql/fragment/location_node.rb +1 -0
- data/lib/ecoportal/api/graphql/helpers/locations_tree.rb +6 -7
- data/lib/ecoportal/api/graphql.rb +3 -2
- data/lib/ecoportal/api/graphql_version.rb +1 -1
- metadata +11 -11
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
|
|
@@ -11,8 +11,35 @@ All notable changes to this project will be documented in this file.
|
|
|
11
11
|
- Add update operation for `ContractorEntity`
|
|
12
12
|
- Add currentOrganization.action
|
|
13
13
|
- Analyse how to "DSL" currentOrganization.action.activities
|
|
14
|
+
|
|
14
15
|
- review `path` tracking
|
|
15
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
|
+
|
|
33
|
+
## [0.3.3] - 2023-04-02
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- `Ecoportal::API::GraphQL::Base::LocationNode` **added** attribute `archivedToken`
|
|
37
|
+
|
|
38
|
+
## [0.3.2] - 2023-04-02
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
- `Ecoportal::API::GraphQL::Helpers::LocationsTree#treeify` added support for `archived_token`
|
|
42
|
+
|
|
16
43
|
## [0.3.1] - 2023-03-09
|
|
17
44
|
|
|
18
45
|
### Added
|
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
23
|
spec.require_paths = ["lib"]
|
|
24
24
|
|
|
25
|
-
spec.add_development_dependency "bundler", ">= 2.
|
|
25
|
+
spec.add_development_dependency "bundler", ">= 2.4.9", "< 2.5"
|
|
26
26
|
spec.add_development_dependency "rspec", ">= 3.10.0", "< 3.11"
|
|
27
27
|
spec.add_development_dependency "rake", ">= 13.0.3", "< 13.1"
|
|
28
28
|
spec.add_development_dependency "yard", ">= 0.9.26", "< 0.10"
|
|
@@ -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,13 +15,14 @@ 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
|
-
"id"
|
|
23
|
-
"name"
|
|
24
|
-
"weight"
|
|
20
|
+
"id" => child.id,
|
|
21
|
+
"name" => child.name,
|
|
22
|
+
"weight" => child.weight,
|
|
25
23
|
"archived" => child.archived,
|
|
26
|
-
"
|
|
24
|
+
"archived_token" => child.archivedToken,
|
|
25
|
+
"nodes" => get_children(child.id, parents).compact
|
|
27
26
|
}
|
|
28
27
|
end
|
|
29
28
|
end
|
|
@@ -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
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-03
|
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,20 +16,20 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 2.
|
|
19
|
+
version: 2.4.9
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '2.
|
|
22
|
+
version: '2.5'
|
|
23
23
|
type: :development
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 2.
|
|
29
|
+
version: 2.4.9
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '2.
|
|
32
|
+
version: '2.5'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: rspec
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -164,7 +164,7 @@ dependencies:
|
|
|
164
164
|
- - "<"
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
166
|
version: '0.8'
|
|
167
|
-
description:
|
|
167
|
+
description:
|
|
168
168
|
email:
|
|
169
169
|
- oscar@ecoportal.co.nz
|
|
170
170
|
executables: []
|
|
@@ -301,7 +301,7 @@ homepage: https://www.ecoportal.com
|
|
|
301
301
|
licenses:
|
|
302
302
|
- MIT
|
|
303
303
|
metadata: {}
|
|
304
|
-
post_install_message:
|
|
304
|
+
post_install_message:
|
|
305
305
|
rdoc_options: []
|
|
306
306
|
require_paths:
|
|
307
307
|
- lib
|
|
@@ -316,8 +316,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
316
316
|
- !ruby/object:Gem::Version
|
|
317
317
|
version: '0'
|
|
318
318
|
requirements: []
|
|
319
|
-
rubygems_version: 3.
|
|
320
|
-
signing_key:
|
|
319
|
+
rubygems_version: 3.1.4
|
|
320
|
+
signing_key:
|
|
321
321
|
specification_version: 4
|
|
322
322
|
summary: A collection of helpers for interacting with the ecoPortal GraphQL API
|
|
323
323
|
test_files: []
|