ecoportal-api 0.5.8 → 0.7.3

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: 168542de09c5a87edcd4952acdf84cdf01944c03339238a27c310e29b71e9c14
4
- data.tar.gz: 2f43b32d289f6232eccff32516717ab82cd86cbe0144d6f8f2eac74f30637cd8
3
+ metadata.gz: f2afaf2e4ef28b96b6e1c7bac6e4d97b7c53299a127aed1e22e990a4ca4ac9e3
4
+ data.tar.gz: 5883d799e43fa71151674b91a2c7557fd968f2552895a86fe656b86e16617460
5
5
  SHA512:
6
- metadata.gz: 1c539315189039d7baed7c48db646969525a47d51cdd88b63a2ac53b651f089aa6e219fa91624943700c1c73144525d9482f4cff8b9e1ca5cbbc9862c0a138e4
7
- data.tar.gz: 3c145a2fcea2c476fb39ad914b6b3ec2ff390ffe5378ab9795ddd466238f0af55fbbae59a5e87cadb415a49165cf0e05d6697e45dc74bd6235581c30268d1e45
6
+ metadata.gz: 33ffe71c4bb72543ab2289d5a945aed1264f955adeae5432a8f6580d5311590f258448a64d49b8ed2e1f73fdabf1482d936fc290d0e92152ba6830b36905b961
7
+ data.tar.gz: 2038ebf5714308446d54ab0b56a70612b6f8ab02b96f28ca8f860e21f1223dc9e2879e53bb05fe25592c7482b3b6d24877c07ed08d872e5086a32fe6ae231464
@@ -1,13 +1,86 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.7.3] - 2020-11-30
5
+
6
+ ### Added
7
+
8
+ ### Fixed
9
+ - `Ecoportal::API::V1::Person#email=`: was not showing the incorrect value in the error message
10
+ - added `compact` to remove `null` values on:
11
+ - `Ecoportal::API::V1::Person#filter_tags=`
12
+ - `Ecoportal::API::Internal::Account#policy_group_ids=`
13
+ - `Ecoportal::API::Internal::Account#login_provider_ids=`
14
+ - `Ecoportal::API::Internal::Account#starred_ids=`
15
+
16
+ ### Changed
17
+
18
+
19
+ ## [0.7.2] - 2020-10-19
20
+
21
+ ### Added
22
+ - `Ecoportal::API::V1::Person#email=`:
23
+ - do a minimum validation (no blanks in the email)
24
+ - set in lower case (as this is how it's in the server)
25
+ ### Fixed
26
+ - `Ecoportal::API::V1::People#each`: when `silent` it shouldn't print a blank line
27
+ - fixed so they return empty array `[]` when `nil`:
28
+ - `Ecoportal::API::V1::Person#filter_tags`
29
+ - `Ecoportal::API::Internal::Account#policy_group_ids`
30
+ - `Ecoportal::API::Internal::Account#login_provider_ids`
31
+ - `Ecoportal::API::Internal::Account#starred_ids`
32
+ ### Changed
33
+ - made it so some methods the `Array` with `uniq` values:
34
+ - `Ecoportal::API::V1::Person#filter_tags=`
35
+ - `Ecoportal::API::Internal::Account#policy_group_ids=`
36
+ - made it so it only updates the keys defined in the `Hash` passed to the setter:
37
+ - `Ecoportal::API::Internal::Account#permissions_custom=`
38
+ - `Ecoportal::API::Internal::Account#preferences=`
39
+
40
+
41
+ ## [0.7.1] - 2020-09-30
42
+
43
+ ### Added
44
+ - `Ecoportal::API::Internal::Permissions`: **update for new ability `tasks` of ecoPortal release `1.5.3`**
45
+ - `Ecoportal::API::V1::People#each`: added keyword argument `silent:` to display download progress
46
+ ### Fixed
47
+ - `Ecoportal::API::V1::People#each`: when no block provided, it was creating an `Enumarator` without preserving the parameters (i.e. `:q` or `per_page` were lost)
48
+
49
+ ## [0.7.0] - 2020-09-11
50
+
51
+ ### Added
52
+ ### Changed
53
+ - `Ecoportal::API::Internal::Permissions`: **update for new abilities of ecoPortal release `1.5.2`**
54
+ - decoupled abilities: `person_core` into `person_core_create`, `person_core_edit`
55
+ ### Fixed
56
+
57
+
58
+ ## [0.6.0] - 2020-07-14
59
+
60
+ ### Added
61
+ - `Ecoportal::API::Common::BaseModel#initial_doc`: `#consolidate!` modifies `original_doc`
62
+ - this helper allows to know what was the initial document the object was created with
63
+ - `Ecoportal::API::Common::BaseModel#as_update`: added parameter (default: `:last` => compare with `original_doc`)
64
+ - calling it with `:total` will compare the current `doc` with the `initial_doc`
65
+ ### Changed
66
+ - `Ecoportal::API::Internal::Permissions`: **update for new abilities of ecoPortal release `1.5.0`**
67
+ - added abilities: `person_core`, `person_account`, `person_details`
68
+ - removed ability: `people`
69
+ - renamed `print` to `pretty_print` to avoid overriding `$stdout.print`, on:
70
+ - `Ecoportal::API::Common::BaseModel`
71
+ - `Ecoportal::API::Common::BatchReponse`
72
+ - `Ecoportal::API::Common::Response`
73
+ - `Ecoportal::API::Common::WrappedResponse`
74
+ ### Fixed
75
+ - `Ecoportal::API::Internal::Preferences`: **kiosk** settings should default to `false` (`nil`)
76
+
4
77
  ## [0.5.8] - 2020-06-23
5
78
 
6
79
  ### Added
7
80
  ### Changed
8
81
  ### Fixed
9
- - `Ecoportal::API::V1::Person#filter_tags=`: `original_doc["filter_tags"]` is `nil` when creating a person
10
- - `Ecoportal::API::Internal::Account#policy_group_ids=`: `original_doc["account"]` is `nil` when creating a person
82
+ - `Ecoportal::API::V1::Person#filter_tags=`: `original_doc["filter_tags"]` is `nil` when creating a person
83
+ - `Ecoportal::API::Internal::Account#policy_group_ids=`: `original_doc["account"]` is `nil` when creating a person
11
84
 
12
85
 
13
86
  ## [0.5.7] - 2020-06-22
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rspec", "~> 3", ">= 3.9"
26
26
  spec.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
27
27
  spec.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
28
- spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "pry" , "~> 0.13"
29
29
 
30
30
  spec.add_dependency 'http', '~> 3'
31
31
  spec.add_dependency 'hash-polyfill', '~> 0'
@@ -48,6 +48,7 @@ module Ecoportal
48
48
  if !_parent || !_key
49
49
  @doc = doc
50
50
  @original_doc = JSON.parse(@doc.to_json)
51
+ @initial_doc = JSON.parse(@doc.to_json)
51
52
  end
52
53
  end
53
54
 
@@ -63,6 +64,12 @@ module Ecoportal
63
64
  _parent.original_doc.dig(*[_key].flatten)
64
65
  end
65
66
 
67
+ def initial_doc
68
+ raise UnlinkedModel.new unless linked?
69
+ return @initial_doc if is_root?
70
+ _parent.initial_doc.dig(*[_key].flatten)
71
+ end
72
+
66
73
  def as_json
67
74
  doc
68
75
  end
@@ -71,9 +78,10 @@ module Ecoportal
71
78
  doc.to_json(*args)
72
79
  end
73
80
 
74
- def as_update
81
+ def as_update(ref = :last)
75
82
  new_doc = as_json
76
- Common::HashDiff.diff(new_doc, original_doc)
83
+ ref_doc = ref == :total ? initial_doc : original_doc
84
+ Common::HashDiff.diff(new_doc, ref_doc)
77
85
  end
78
86
 
79
87
  def dirty?
@@ -100,7 +108,7 @@ module Ecoportal
100
108
  end
101
109
  end
102
110
 
103
- def print
111
+ def pretty_print
104
112
  puts JSON.pretty_generate(as_json)
105
113
  self
106
114
  end
@@ -20,10 +20,10 @@ module Ecoportal
20
20
  yield doc
21
21
  end
22
22
  end
23
-
24
- def print
23
+
24
+ def pretty_print
25
25
  if success?
26
- each(&:print)
26
+ each(&:pretty_print)
27
27
  else
28
28
  puts "Request failed."
29
29
  end
@@ -19,8 +19,8 @@ module Ecoportal
19
19
  def success?
20
20
  @status.success?
21
21
  end
22
-
23
- def print
22
+
23
+ def pretty_print
24
24
  puts "Status: #{@status.code}"
25
25
  puts "Body:"
26
26
  puts JSON.pretty_generate(@body)
@@ -40,14 +40,14 @@ module Ecoportal
40
40
  response.success?
41
41
  end
42
42
 
43
- def print
43
+ def pretty_print
44
44
  if success?
45
- each(&:print)
45
+ each(&:pretty_print)
46
46
  else
47
47
  puts "Request failed."
48
48
  end
49
49
  end
50
-
50
+
51
51
  end
52
52
  end
53
53
  end
@@ -13,14 +13,49 @@ module Ecoportal
13
13
  embeds_one :preferences, klass: :preferences_class
14
14
 
15
15
  # Sets the `policy_group_ids`
16
+ # @note it preserves the original order
17
+ # @param value [Array<String>] the policy group ids to be set.
16
18
  def policy_group_ids=(value)
17
19
  unless value.is_a?(Array)
18
20
  raise "policy_group_ids= needs to be passed an Array, got #{value.class}"
19
21
  end
20
22
 
23
+ value.uniq!
21
24
  ini_ids = (original_doc && original_doc["policy_group_ids"]) || []
22
25
  # preserve original order to avoid false updates
23
26
  doc["policy_group_ids"] = (ini_ids & value) + (value - ini_ids)
27
+ doc["policy_group_ids"].compact!
28
+ end
29
+
30
+ # @return [Array<String>] the policy group ids of this user.
31
+ def policy_group_ids
32
+ doc["policy_group_ids"] ||= []
33
+ end
34
+
35
+ # Sets the `login_provider_ids`
36
+ def login_provider_ids=(value)
37
+ unless value.is_a?(Array)
38
+ raise "login_provider_ids= needs to be passed an Array, got #{value.class}"
39
+ end
40
+ doc["login_provider_ids"] = value.compact!
41
+ end
42
+
43
+ # @return [Array<String>] the login provider ids of this user.
44
+ def login_provider_ids
45
+ doc["login_provider_ids"] ||= []
46
+ end
47
+
48
+ # Sets the `starred_ids`
49
+ def starred_ids=(value)
50
+ unless value.is_a?(Array)
51
+ raise "starred_ids= needs to be passed an Array, got #{value.class}"
52
+ end
53
+ doc["starred_ids"] = value.compact!
54
+ end
55
+
56
+ # @return [Array<String>] the starred page ids of this user.
57
+ def starred_ids
58
+ doc["starred_ids"] ||= []
24
59
  end
25
60
 
26
61
  # Sets the `permissions_preset`.
@@ -37,6 +72,20 @@ module Ecoportal
37
72
  self.permissions_preset.nil? ? "custom" : self.permissions_preset
38
73
  end
39
74
 
75
+ # It preserves the values of keys that are not defined in `value`.
76
+ # @param value [Hash] the abilities that you want to update.
77
+ def permissions_custom=(value)
78
+ doc["permissions_custom"] ||= {}
79
+ doc["permissions_custom"].merge!(value)
80
+ end
81
+
82
+ # It preserves the values of keys that are not defined in `value`.
83
+ # @param value [Hash] the preferences that you want to update.
84
+ def preferences=(value)
85
+ doc["preferences"] ||= {}
86
+ doc["preferences"].merge!(value)
87
+ end
88
+
40
89
  def as_json
41
90
  super.tap do |hash|
42
91
  if preset == "custom"
@@ -2,7 +2,10 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class Permissions < Common::BaseModel
5
- passthrough :files, :data, :reports, :organization, :people, :pages, :page_editor, :registers
5
+ passthrough :files, :data, :reports
6
+ passthrough :organization, :person_core, :person_core_create, :person_core_edit
7
+ passthrough :person_account, :person_details
8
+ passthrough :pages, :page_editor, :registers, :tasks
6
9
  end
7
10
  end
8
11
  end
@@ -2,21 +2,17 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class Preferences < Common::BaseModel
5
+ passthrough :kiosk_enabled, :kiosk_workflow_message, :kiosk_create_button_label,
6
+ :kiosk_create_button_help, :kiosk_return_button_label, :kiosk_return_button_help,
7
+ :kiosk_dashboard_button_label, :kiosk_dashboard_button_help
8
+
5
9
  [
6
10
  :show_sidebar,
7
11
  :show_shortcuts,
8
12
  :show_coming_soon,
9
13
  :show_recently_visited_forms,
10
14
  :show_tasks,
11
- :show_task_bubbles,
12
- :kiosk_enabled,
13
- :kiosk_workflow_message,
14
- :kiosk_create_button_label,
15
- :kiosk_create_button_help,
16
- :kiosk_return_button_label,
17
- :kiosk_return_button_help,
18
- :kiosk_dashboard_button_label,
19
- :kiosk_dashboard_button_help
15
+ :show_task_bubbles
20
16
  ].map(&:to_s).each do |field|
21
17
  define_method(field) do
22
18
  if doc.key?(field)
@@ -27,15 +27,27 @@ module Ecoportal
27
27
  # @param params [Hash]
28
28
  # @option params [String] :per_page the number of people you get per request.
29
29
  # @option params [String] :q some text to search. Omit this parameter to target all the people.
30
+ # @param silent [Boolean] `false` to show percentage of progress.
30
31
  # @yield [person] does some stuff with the person.
31
32
  # @yieldparam person [Person]
32
- def each(params: {}, &block)
33
- return to_enum(:each) unless block
34
- cursor_id = nil
33
+ def each(params: {}, silent: false, &block)
34
+ return to_enum(:each, params: params, silent: silent) unless block
35
+ cursor_id = nil; results = 0
36
+ puts "\n" unless silent
35
37
  loop do
36
38
  params.update(cursor_id: cursor_id) if cursor_id
37
39
  response = client.get("/people", params: params)
38
- raise "Request failed." unless response.success?
40
+ raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
41
+
42
+ unless silent || (total = response.body["total_results"]) == 0
43
+ results += response.body["results"].length
44
+ percent = results * 100 / total
45
+ msg = "People GET"
46
+ msg += " (search=#{params[:q]})" if params.key?(:q)
47
+ print "#{msg}: #{percent.round}% (of #{total})\r"
48
+ $stdout.flush
49
+ end
50
+
39
51
  response.body["results"].each do |person|
40
52
  yield person_class.new(person)
41
53
  end
@@ -45,13 +57,14 @@ module Ecoportal
45
57
  end
46
58
 
47
59
  # Gets all the people via api requests.
48
- # @note it ignores the key `:page` in `params:`.
60
+ # @note it ignores the key `:cursor_id` in `params:`.
49
61
  # @param params [Hash]
50
62
  # @option params [Integer] :per_page the number of people you get per request.
51
63
  # @option params [String] :q some text to search.
64
+ # @param silent [Boolean] `false` to show percentage of progress.
52
65
  # @return [Array<Person>] the array of people got via api.
53
- def get_all(params: {})
54
- each(params: params).to_a
66
+ def get_all(params: {}, silent: false)
67
+ each(params: params, silent: silent).to_a
55
68
  end
56
69
 
57
70
  # Gets a person via api.
@@ -15,6 +15,7 @@ module Ecoportal
15
15
  embeds_one :details, nullable: true, klass: :person_details_class
16
16
 
17
17
  VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
18
+ VALID_EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
18
19
 
19
20
  # Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
20
21
  #
@@ -41,8 +42,17 @@ module Ecoportal
41
42
  self.supervisor_id = person&.id || person&.external_id
42
43
  end
43
44
 
45
+ # Sets the email of a person.
46
+ # @param value [String, nil] the email of this person.
47
+ def email=(value)
48
+ unless !value || value.match(VALID_EMAIL_REGEX)
49
+ raise "Invalid email #{value.inspect}"
50
+ end
51
+ doc["email"] = value&.downcase
52
+ end
53
+
44
54
  # Validates the string tags of the array, and sets the `filter_tags` property of the account.
45
- # @note all is set in upper case.
55
+ # @note all is set in upper case and preserves the original order.
46
56
  # @raise [Exception] if there was any invalid string tag.
47
57
  # @param value [Array<String>] array of tags.
48
58
  def filter_tags=(value)
@@ -54,11 +64,17 @@ module Ecoportal
54
64
  raise "Invalid filter tag #{tag.inspect}"
55
65
  end
56
66
  tag.upcase
57
- end
67
+ end.uniq
58
68
 
59
69
  ini_tags = (original_doc && original_doc["filter_tags"]) || []
60
70
  # preserve original order to avoid false updates
61
71
  doc["filter_tags"] = (ini_tags & end_tags) + (end_tags - ini_tags)
72
+ doc["filter_tags"].compact!
73
+ end
74
+
75
+ # @return [Array<String>] the filter tags of this person.
76
+ def filter_tags
77
+ doc["filter_tags"] ||= []
62
78
  end
63
79
 
64
80
  def as_json
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.5.8"
3
+ VERSION = "0.7.3"
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.5.8
4
+ version: 0.7.3
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-06-23 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,16 +108,16 @@ dependencies:
108
108
  name: pry
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ">="
111
+ - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: '0'
113
+ version: '0.13'
114
114
  type: :development
115
115
  prerelease: false
116
116
  version_requirements: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - ">="
118
+ - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: '0'
120
+ version: '0.13'
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: http
123
123
  requirement: !ruby/object:Gem::Requirement
@@ -163,7 +163,6 @@ files:
163
163
  - ".yardopts"
164
164
  - CHANGELOG.md
165
165
  - Gemfile
166
- - Gemfile.lock
167
166
  - LICENSE
168
167
  - README.md
169
168
  - Rakefile
@@ -183,7 +182,6 @@ files:
183
182
  - lib/ecoportal/api/common/response.rb
184
183
  - lib/ecoportal/api/common/wrapped_response.rb
185
184
  - lib/ecoportal/api/internal.rb
186
- - lib/ecoportal/api/internal/.git-keep
187
185
  - lib/ecoportal/api/internal/account.rb
188
186
  - lib/ecoportal/api/internal/login_provider.rb
189
187
  - lib/ecoportal/api/internal/login_providers.rb
@@ -200,7 +198,6 @@ files:
200
198
  - lib/ecoportal/api/internal/schema_field_value.rb
201
199
  - lib/ecoportal/api/logger.rb
202
200
  - lib/ecoportal/api/v1.rb
203
- - lib/ecoportal/api/v1/.git-keep
204
201
  - lib/ecoportal/api/v1/people.rb
205
202
  - lib/ecoportal/api/v1/person.rb
206
203
  - lib/ecoportal/api/v1/person_details.rb
File without changes
File without changes