ecoportal-api 0.7.1 → 0.7.2

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: 8071a9704b5accb61bd9db43b0bd6c8c6d6f88aee00ef80d16fd4b5522aedf3c
4
- data.tar.gz: fc42e6ea6570565a22cb52d9941ace6bcb081b42553321d552c1d1794ec0f8f9
3
+ metadata.gz: e1976e2e6000be3719f3cd7d9d0524ecdd4d005691f4c214e9ad77bbe9b33d09
4
+ data.tar.gz: 577313f39edd82846a9050ae8acbadf9f3b79ca2f1ebbedec9ee598973ff1fed
5
5
  SHA512:
6
- metadata.gz: 52a24b2a8f5326e92b42af2781c6a498580dfda7a16458c288b77e7ac5dea01cfa0ed619f27ea7a86d4ce27e4b004c156205a14076ac51cc06203c6abbc28820
7
- data.tar.gz: 7146daf930693399e4935f0b00645768b64e0c44a7772f0c128042ab151bf29f0598e2e357e0462af77dd423561646c98cdd350e59830bd733e9c51bc120684a
6
+ metadata.gz: 6706dcf4968d94c9e1daedff8e2325699b4da5403d758c79474a7dff618e9dd36d31d566003be66bb685fc633e0100a2c08a80ba5edd9c4d8433b2e5c56ac00f
7
+ data.tar.gz: 20004f26d098f579cc5b7269bb06eb8bf41284506b291882ff81ff7794db2612162df8f010e24a41240a82d30f6b48a48ae8e54c60375c3d5f79228f95ef76b8
@@ -1,6 +1,28 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.7.2] - 2020-10-30
5
+
6
+ ### Added
7
+ - `Ecoportal::API::V1::Person#email=`:
8
+ - do a minimum validation (no blanks in the email)
9
+ - set in lower case (as this is how it's in the server)
10
+ ### Fixed
11
+ - `Ecoportal::API::V1::People#each`: when `silent` it shouldn't print a blank line
12
+ - fixed so they return empty array `[]` when `nil`:
13
+ - `Ecoportal::API::V1::Person#filter_tags`
14
+ - `Ecoportal::API::Internal::Account#policy_group_ids`
15
+ - `Ecoportal::API::Internal::Account#login_provider_ids`
16
+ - `Ecoportal::API::Internal::Account#starred_ids`
17
+ ### Changed
18
+ - made it so some methods the `Array` with `uniq` values:
19
+ - `Ecoportal::API::V1::Person#filter_tags=`
20
+ - `Ecoportal::API::Internal::Account#policy_group_ids=`
21
+ - made it so it only updates the keys defined in the `Hash` passed to the setter:
22
+ - `Ecoportal::API::Internal::Account#permissions_custom=`
23
+ - `Ecoportal::API::Internal::Account#preferences=`
24
+
25
+
4
26
  ## [0.7.1] - 2020-09-30
5
27
 
6
28
  ### Added
@@ -13,16 +13,34 @@ 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)
24
27
  end
25
28
 
29
+ # @return [Array<String>] the policy group ids of this user.
30
+ def policy_group_ids
31
+ doc["policy_group_ids"] ||= []
32
+ end
33
+
34
+ # @return [Array<String>] the login provider ids of this user.
35
+ def login_provider_ids
36
+ doc["login_provider_ids"] ||= []
37
+ end
38
+
39
+ # @return [Array<String>] the starred page ids of this user.
40
+ def starred_ids
41
+ doc["starred_ids"] ||= []
42
+ end
43
+
26
44
  # Sets the `permissions_preset`.
27
45
  # @note basically the same as `permissions_preset=` but when `"custom"`, it's changed to `nil`
28
46
  # @param value [nil, String] preset name.
@@ -37,6 +55,20 @@ module Ecoportal
37
55
  self.permissions_preset.nil? ? "custom" : self.permissions_preset
38
56
  end
39
57
 
58
+ # It preserves the values of keys that are not defined in `value`.
59
+ # @param value [Hash] the abilities that you want to update.
60
+ def permissions_custom=(value)
61
+ doc["permissions_custom"] ||= {}
62
+ doc["permissions_custom"].merge!(value)
63
+ end
64
+
65
+ # It preserves the values of keys that are not defined in `value`.
66
+ # @param value [Hash] the preferences that you want to update.
67
+ def preferences=(value)
68
+ doc["preferences"] ||= {}
69
+ doc["preferences"].merge!(value)
70
+ end
71
+
40
72
  def as_json
41
73
  super.tap do |hash|
42
74
  if preset == "custom"
@@ -33,7 +33,7 @@ module Ecoportal
33
33
  def each(params: {}, silent: false, &block)
34
34
  return to_enum(:each, params: params, silent: silent) unless block
35
35
  cursor_id = nil; results = 0
36
- puts "\n"
36
+ puts "\n" unless silent
37
37
  loop do
38
38
  params.update(cursor_id: cursor_id) if cursor_id
39
39
  response = client.get("/people", params: params)
@@ -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 email [String, nil] the email of this person.
47
+ def email=(value)
48
+ unless !value || value.match(VALID_EMAIL_REGEX)
49
+ raise "Invalid email #{email.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,13 +64,18 @@ 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)
62
72
  end
63
73
 
74
+ # @return [Array<String>] the filter tags of this person.
75
+ def filter_tags
76
+ doc["filter_tags"] ||= []
77
+ end
78
+
64
79
  def as_json
65
80
  super.merge "details" => details&.as_json
66
81
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.7.1"
3
+ VERSION = "0.7.2"
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.1
4
+ version: 0.7.2
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-09-30 00:00:00.000000000 Z
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler