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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2afaf2e4ef28b96b6e1c7bac6e4d97b7c53299a127aed1e22e990a4ca4ac9e3
4
- data.tar.gz: 5883d799e43fa71151674b91a2c7557fd968f2552895a86fe656b86e16617460
3
+ metadata.gz: 275ffcb5e9bfe17f44295a7c4438b9e169dc87f22afe19591752425ef008cdba
4
+ data.tar.gz: aeb53e930f75dc7299fc400a8a00624428dfe496b77a5fdf1af1075b144a6944
5
5
  SHA512:
6
- metadata.gz: 33ffe71c4bb72543ab2289d5a945aed1264f955adeae5432a8f6580d5311590f258448a64d49b8ed2e1f73fdabf1482d936fc290d0e92152ba6830b36905b961
7
- data.tar.gz: 2038ebf5714308446d54ab0b56a70612b6f8ab02b96f28ca8f860e21f1223dc9e2879e53bb05fe25592c7482b3b6d24877c07ed08d872e5086a32fe6ae231464
6
+ metadata.gz: 2e2e4c03089ccf675057b335a9c9e46a5a40a92d3720b256fb9a679eec6431885889171960bf106e3586efbc77d9b2384262c9e4aa52cdf34b6c291be78b76dd
7
+ data.tar.gz: c1df25f369172d215ba64bf932b63d78514871579540edabc991719a737999a5700828352bceca140d5715861b47cb6b2e4e56fab4b7b916fe5ef42627ec7e4f
@@ -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
@@ -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', '~> 3'
30
+ spec.add_dependency 'http', '~> 4'
31
31
  spec.add_dependency 'hash-polyfill', '~> 0'
32
32
  end
@@ -11,4 +11,5 @@ end
11
11
  require "ecoportal/api/logger"
12
12
  require "ecoportal/api/common"
13
13
  require "ecoportal/api/v1"
14
+ require "ecoportal/api/v2"
14
15
  require "ecoportal/api/internal"
@@ -108,10 +108,10 @@ module Ecoportal
108
108
  end
109
109
  end
110
110
 
111
- def pretty_print
112
- puts JSON.pretty_generate(as_json)
113
- self
114
- end
111
+ # def pretty_print
112
+ # puts JSON.pretty_generate(as_json)
113
+ # self
114
+ # end
115
115
 
116
116
  protected
117
117
 
@@ -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 ||= HTTP.headers("X-ApiKey" => @api_key).accept(:json)
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,9 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Field < Common::BaseModel
5
+ passthrough :id, :label, :value, :type
6
+ end
7
+ end
8
+ end
9
+ end
@@ -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'
@@ -0,0 +1,9 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Stage < Common::BaseModel
5
+ passthrough :id, :name, :state
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.7.3"
3
+ VERSION = "0.7.4"
4
4
  end
5
5
  end
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.3
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: 2020-11-30 00:00:00.000000000 Z
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: '3'
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: '3'
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: