ecoportal-api 0.7.3 → 0.7.4
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 +13 -0
- data/ecoportal-api.gemspec +1 -1
- data/lib/ecoportal/api.rb +1 -0
- data/lib/ecoportal/api/common/base_model.rb +4 -4
- data/lib/ecoportal/api/common/client.rb +9 -2
- data/lib/ecoportal/api/internal/account.rb +3 -3
- data/lib/ecoportal/api/v1/person.rb +1 -1
- data/lib/ecoportal/api/v2.rb +47 -0
- data/lib/ecoportal/api/v2/field.rb +9 -0
- data/lib/ecoportal/api/v2/page.rb +30 -0
- data/lib/ecoportal/api/v2/pages.rb +46 -0
- data/lib/ecoportal/api/v2/register_search_result.rb +20 -0
- data/lib/ecoportal/api/v2/registers.rb +65 -0
- data/lib/ecoportal/api/v2/stage.rb +9 -0
- data/lib/ecoportal/api/version.rb +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 275ffcb5e9bfe17f44295a7c4438b9e169dc87f22afe19591752425ef008cdba
|
4
|
+
data.tar.gz: aeb53e930f75dc7299fc400a8a00624428dfe496b77a5fdf1af1075b144a6944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e2e4c03089ccf675057b335a9c9e46a5a40a92d3720b256fb9a679eec6431885889171960bf106e3586efbc77d9b2384262c9e4aa52cdf34b6c291be78b76dd
|
7
|
+
data.tar.gz: c1df25f369172d215ba64bf932b63d78514871579540edabc991719a737999a5700828352bceca140d5715861b47cb6b2e4e56fab4b7b916fe5ef42627ec7e4f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.7.4] - 2021-01-2
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- changed `compact` to `compact!`:
|
10
|
+
- `Ecoportal::API::V1::Person#filter_tags=`
|
11
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids=`
|
12
|
+
- `Ecoportal::API::Internal::Account#login_provider_ids=`
|
13
|
+
- `Ecoportal::API::Internal::Account#starred_ids=`
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
4
17
|
## [0.7.3] - 2020-11-30
|
5
18
|
|
6
19
|
### Added
|
data/ecoportal-api.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
|
28
28
|
spec.add_development_dependency "pry" , "~> 0.13"
|
29
29
|
|
30
|
-
spec.add_dependency 'http', '~>
|
30
|
+
spec.add_dependency 'http', '~> 4'
|
31
31
|
spec.add_dependency 'hash-polyfill', '~> 0'
|
32
32
|
end
|
data/lib/ecoportal/api.rb
CHANGED
@@ -119,11 +119,18 @@ module Ecoportal
|
|
119
119
|
Ecoportal::API::Common::Response.new(response)
|
120
120
|
end
|
121
121
|
|
122
|
-
# Creates a HTTP object adding the `X-ApiKey` param to the header.
|
122
|
+
# Creates a HTTP object adding the `X-ApiKey` or `X-ECOPORTAL-API-KEY` param to the header, depending on the API version.
|
123
123
|
# @note It configures HTTP so it only allows body data in json format.
|
124
124
|
# @return [HTTP] HTTP object.
|
125
125
|
def base_request
|
126
|
-
@base_request ||=
|
126
|
+
@base_request ||= begin
|
127
|
+
case @version
|
128
|
+
when "v2"
|
129
|
+
HTTP.headers("X-ECOPORTAL-API-KEY" => @api_key).accept(:json)
|
130
|
+
else
|
131
|
+
HTTP.headers("X-ApiKey" => @api_key).accept(:json)
|
132
|
+
end
|
133
|
+
end
|
127
134
|
end
|
128
135
|
|
129
136
|
# Full URl builder of the request
|
@@ -24,7 +24,7 @@ module Ecoportal
|
|
24
24
|
ini_ids = (original_doc && original_doc["policy_group_ids"]) || []
|
25
25
|
# preserve original order to avoid false updates
|
26
26
|
doc["policy_group_ids"] = (ini_ids & value) + (value - ini_ids)
|
27
|
-
doc["policy_group_ids"].compact
|
27
|
+
doc["policy_group_ids"].compact
|
28
28
|
end
|
29
29
|
|
30
30
|
# @return [Array<String>] the policy group ids of this user.
|
@@ -37,7 +37,7 @@ module Ecoportal
|
|
37
37
|
unless value.is_a?(Array)
|
38
38
|
raise "login_provider_ids= needs to be passed an Array, got #{value.class}"
|
39
39
|
end
|
40
|
-
doc["login_provider_ids"] = value.compact
|
40
|
+
doc["login_provider_ids"] = value.compact
|
41
41
|
end
|
42
42
|
|
43
43
|
# @return [Array<String>] the login provider ids of this user.
|
@@ -50,7 +50,7 @@ module Ecoportal
|
|
50
50
|
unless value.is_a?(Array)
|
51
51
|
raise "starred_ids= needs to be passed an Array, got #{value.class}"
|
52
52
|
end
|
53
|
-
doc["starred_ids"] = value.compact
|
53
|
+
doc["starred_ids"] = value.compact
|
54
54
|
end
|
55
55
|
|
56
56
|
# @return [Array<String>] the starred page ids of this user.
|
@@ -69,7 +69,7 @@ module Ecoportal
|
|
69
69
|
ini_tags = (original_doc && original_doc["filter_tags"]) || []
|
70
70
|
# preserve original order to avoid false updates
|
71
71
|
doc["filter_tags"] = (ini_tags & end_tags) + (end_tags - ini_tags)
|
72
|
-
doc["filter_tags"].compact
|
72
|
+
doc["filter_tags"].compact
|
73
73
|
end
|
74
74
|
|
75
75
|
# @return [Array<String>] the filter tags of this person.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
4
|
+
# @attr_reader logger [Logger] the logger.
|
5
|
+
class V2
|
6
|
+
extend Common::BaseClass
|
7
|
+
include Common::Logging
|
8
|
+
|
9
|
+
VERSION = "v2"
|
10
|
+
class_resolver :registers_class, "Ecoportal::API::V2::Registers"
|
11
|
+
class_resolver :pages_class, "Ecoportal::API::V2::Pages"
|
12
|
+
|
13
|
+
attr_reader :client, :logger
|
14
|
+
|
15
|
+
# Creates an `V2` object to scope version specific api requests.
|
16
|
+
# @note
|
17
|
+
# - The const `VERSION` determineds the api version that client will query against.
|
18
|
+
# - This means that each subclass of `V2` should define their own `VERSION` constant.
|
19
|
+
# @param api_key [String] the key version to stablish the api connection.
|
20
|
+
# @param host [String] api server domain.
|
21
|
+
# @param logger [Logger] an object with `Logger` interface to generate logs.
|
22
|
+
# @return [V2] an object with the api version suit.
|
23
|
+
def initialize(api_key, version: VERSION, host: "live.ecoportal.com", logger: default_logger)
|
24
|
+
@logger = logger
|
25
|
+
@client = Common::Client.new(
|
26
|
+
api_key: api_key,
|
27
|
+
host: host,
|
28
|
+
version: self.class::VERSION,
|
29
|
+
logger: @logger
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Obtain specific object for register api requests.
|
34
|
+
# @return [Register] an instance object ready to make register api requests.
|
35
|
+
def registers
|
36
|
+
registers_class.new(client)
|
37
|
+
end
|
38
|
+
|
39
|
+
def pages
|
40
|
+
pages_class.new(client)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'ecoportal/api/v2/registers'
|
47
|
+
require 'ecoportal/api/v2/pages'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
class Page < Common::BaseModel
|
5
|
+
passthrough :id, :name, :state
|
6
|
+
|
7
|
+
class_resolver :stage_class, "Ecoportal::API::V2::Stage"
|
8
|
+
class_resolver :field_class, "Ecoportal::API::V2::Field"
|
9
|
+
|
10
|
+
def stages
|
11
|
+
return nil unless doc["evolution"]
|
12
|
+
return @stages if defined?(@stages)
|
13
|
+
@stages = (doc["evolution"]["stages"] || []).each_with_index.map do |stage, i|
|
14
|
+
stage_class.new(stage, parent: self, key: ["stages", i])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def fields
|
19
|
+
return @fields if defined?(@fields)
|
20
|
+
@fields = (doc["components"] || []).each_with_index.map do |component, i|
|
21
|
+
field_class.new(component, parent: self, key: ["components", i])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'ecoportal/api/v2/stage'
|
30
|
+
require 'ecoportal/api/v2/field'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
5
|
+
class Pages
|
6
|
+
extend Common::BaseClass
|
7
|
+
include Enumerable
|
8
|
+
include Common::DocHelpers
|
9
|
+
|
10
|
+
attr_reader :client
|
11
|
+
|
12
|
+
class_resolver :page_class, "Ecoportal::API::V2::Page"
|
13
|
+
|
14
|
+
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
15
|
+
# @return [People] an instance object ready to make people api requests.
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(id, stage_id: nil)
|
21
|
+
if stage_id
|
22
|
+
response = get_with_stage_id(id, stage_id)
|
23
|
+
return page_class.new(response.body["data"])
|
24
|
+
end
|
25
|
+
|
26
|
+
response = client.get("/pages/#{id}")
|
27
|
+
# we get a 302 back when there's stages for the page
|
28
|
+
# let's follow it
|
29
|
+
if response.status == 302
|
30
|
+
stage_id = response.body["data"].match(/stages\/(.*)/)[1]
|
31
|
+
response = get_with_stage_id(id, stage_id)
|
32
|
+
end
|
33
|
+
page_class.new(response.body["data"])
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def get_with_stage_id(id, stage_id)
|
39
|
+
client.get("/pages/#{id}/stages/#{stage_id}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'ecoportal/api/v2/page'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
class RegisterSearchResult < Common::BaseModel
|
5
|
+
passthrough :id, :name, :state
|
6
|
+
|
7
|
+
class_resolver :stage_class, "Ecoportal::API::V2::Stage"
|
8
|
+
|
9
|
+
def stages
|
10
|
+
return @stages if defined?(@stages)
|
11
|
+
@stages = (doc["stages"] || []).each_with_index.map do |stage, i|
|
12
|
+
stage_class.new(stage, parent: self, key: ["stages", i])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'ecoportal/api/v2/stage'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
5
|
+
class Registers
|
6
|
+
extend Common::BaseClass
|
7
|
+
include Enumerable
|
8
|
+
include Common::DocHelpers
|
9
|
+
|
10
|
+
class_resolver :register_search_result_class, "Ecoportal::API::V2::RegisterSearchResult"
|
11
|
+
|
12
|
+
attr_reader :client
|
13
|
+
|
14
|
+
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
15
|
+
# @return [People] an instance object ready to make people api requests.
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def search(register_id, options = {})
|
21
|
+
# supply a query string
|
22
|
+
# or a filter array (copy/paste from dev tools in the browser)
|
23
|
+
options = {query: nil, filters: []}.update(options)
|
24
|
+
options = {}.tap do |ret|
|
25
|
+
options.each do |key, value|
|
26
|
+
if key == :filters && value.any?
|
27
|
+
ret[key] = {filters: value}.to_json
|
28
|
+
else
|
29
|
+
ret[key] = value if key
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
cursor_id = nil
|
35
|
+
results = 0
|
36
|
+
loop do
|
37
|
+
options.update(cursor_id: cursor_id) if cursor_id
|
38
|
+
response = client.get("/registers/#{register_id}/search", params: options)
|
39
|
+
raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
|
40
|
+
|
41
|
+
data = response.body["data"]
|
42
|
+
unless (total = data["total"]) == 0
|
43
|
+
results += data["results"].length
|
44
|
+
percent = results * 100 / total
|
45
|
+
msg = "Registers SEARCH"
|
46
|
+
print "#{msg}: #{percent.round}% (of #{total})\r"
|
47
|
+
$stdout.flush
|
48
|
+
end
|
49
|
+
|
50
|
+
data["results"].each do |result|
|
51
|
+
object = register_search_result_class.new(result)
|
52
|
+
yield object
|
53
|
+
end
|
54
|
+
|
55
|
+
# break unless (cursor_id = data["cursor_id"])
|
56
|
+
break if total == results
|
57
|
+
end
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
require 'ecoportal/api/v2/register_search_result'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapio Saarinen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,14 +124,14 @@ dependencies:
|
|
124
124
|
requirements:
|
125
125
|
- - "~>"
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
127
|
+
version: '4'
|
128
128
|
type: :runtime
|
129
129
|
prerelease: false
|
130
130
|
version_requirements: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
132
|
- - "~>"
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version: '
|
134
|
+
version: '4'
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: hash-polyfill
|
137
137
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,13 @@ files:
|
|
205
205
|
- lib/ecoportal/api/v1/person_schemas.rb
|
206
206
|
- lib/ecoportal/api/v1/schema_field.rb
|
207
207
|
- lib/ecoportal/api/v1/schema_field_value.rb
|
208
|
+
- lib/ecoportal/api/v2.rb
|
209
|
+
- lib/ecoportal/api/v2/field.rb
|
210
|
+
- lib/ecoportal/api/v2/page.rb
|
211
|
+
- lib/ecoportal/api/v2/pages.rb
|
212
|
+
- lib/ecoportal/api/v2/register_search_result.rb
|
213
|
+
- lib/ecoportal/api/v2/registers.rb
|
214
|
+
- lib/ecoportal/api/v2/stage.rb
|
208
215
|
- lib/ecoportal/api/version.rb
|
209
216
|
homepage: https://www.ecoportal.com
|
210
217
|
licenses:
|