ecoportal-api 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc651f2474f74b8f767c9df5b4611bd8adefdff75f8e25365135c89561229738
4
- data.tar.gz: cb7a8ff5c0c03ba7e371f987d6b277c001b33e57716ab6cf03628d28bac53b61
3
+ metadata.gz: 4364abf59cd6460788d315eb5012df5e8ad254a208e8af7314a766463eb35ed0
4
+ data.tar.gz: d71fe7e38402e827aea0f95c6a0c379e191e525d597ab8b225990f48c6879764
5
5
  SHA512:
6
- metadata.gz: f89285565edeaa9cbe4a98970bae8602a943c7c865121a89782f512353a8be74529578eecb4f48e893f546f172425dd38af0759412f53b8fc3a91989d6dbe52a
7
- data.tar.gz: 4f51e3e6d080745261c033acf511fdd341ebf9f97003f4dda5067c49c9ef51adf966c51cf268e4991e741b45c803fc6c1e821051832c090ba2c685f03c4eaa7d
6
+ metadata.gz: e055587b4aafbfabf25996cf4e67d85b0a0d9be936d4b0bdae194b431e4f2bb12b09fc99562d594cf355767aae3081a1fbea70d10a48dc204ce839284bbf0256
7
+ data.tar.gz: 5cd7284e455af271f1642775844636fd0ea11b590c0036d3b4a43868a9ffd6ece97ceebb9a3d6dfcdae7891dd65dedd0df9dac5944578cb18484b07342640c3e
data/CHANGELOG.md CHANGED
@@ -1,7 +1,24 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.8.4] - 2021-10-xx
4
+ ## [0.8.5] - 2022-02-28
5
+
6
+ ### Added
7
+ - `Ecoportal::API::V1::PersonDetails#[]` to raise a specific error type to allow handling
8
+ - `Ecoportal::API::V1::PersonDetails.key?` to allow to check if a field exists
9
+ - `Ecoportal::API::Internal::Account#force_send_invites` support for back-end new method
10
+
11
+ ### Fixed
12
+ - `Ecoportal::API::V1::People#get` fixed typo
13
+ - `Ecoportal::API::Common::BaseModel` `#original_doc` and `#initial_doc` maybe empty for the parent object
14
+
15
+ ### Changed
16
+ - `Ecoportal::API::V1::People#each` limited the `GET` retries to `5`
17
+ - `Ecoportal::API::Internal::Account#default_tag=`
18
+ - Controls input type to be `String` or `nil`
19
+ - Inherent `upcase`
20
+
21
+ ## [0.8.4] - 2021-11-05
5
22
 
6
23
  ### Added
7
24
  - `Ecoportal::API::Internal::Permissions` added abilities
@@ -68,13 +68,13 @@ module Ecoportal
68
68
  def original_doc
69
69
  raise UnlinkedModel.new(from: "#{self.class}#original_doc", key: _key) unless linked?
70
70
  return @original_doc if is_root?
71
- _parent.original_doc.dig(*[_key].flatten)
71
+ _parent.original_doc&.dig(*[_key].flatten)
72
72
  end
73
73
 
74
74
  def initial_doc
75
75
  raise UnlinkedModel.new(from: "#{self.class}#initial_doc", key: _key) unless linked?
76
76
  return @initial_doc if is_root?
77
- _parent.initial_doc.dig(*[_key].flatten)
77
+ _parent.initial_doc&.dig(*[_key].flatten)
78
78
  end
79
79
 
80
80
  def as_json
@@ -6,7 +6,7 @@ module Ecoportal
6
6
  "user_id", "policy_group_ids", "default_tag", "prefilter",
7
7
  "permissions_custom", "permissions_merged", "preferences",
8
8
  "login_provider_ids", "starred_ids", "landing_page_id",
9
- "accept_eula", "send_invites"
9
+ "accept_eula", "send_invites", "force_send_invites"
10
10
  ]
11
11
  passthrough *PROPERTIES.map(&:to_sym)
12
12
 
@@ -17,6 +17,23 @@ module Ecoportal
17
17
  embeds_one :perms_merged, key: "permissions_merged", klass: :permissions_class
18
18
  embeds_one :preferences, klass: :preferences_class
19
19
 
20
+ # Sets the `default_tag` of the user
21
+ # @note it upcases the value
22
+ # @param value [String, nil] the tag
23
+ # @return [String, nil] the value set in `default_tag`
24
+ def default_tag=(value)
25
+ unless !value || value.is_a?(String)
26
+ raise ArgumentError.new("default_tag= needs to be passed a String or nil, got #{value.class}")
27
+ end
28
+ if value
29
+ unless value.match(Ecoportal::API::V1::Person::VALID_TAG_REGEX)
30
+ raise ArgumentError.new("Invalid default tag #{value.inspect}")
31
+ end
32
+ value = value.upcase
33
+ end
34
+ doc["default_tag"] = value
35
+ end
36
+
20
37
  # Sets the `policy_group_ids`
21
38
  # @note it preserves the original order
22
39
  # @param value [Array<String>] the policy group ids to be set.
@@ -36,16 +36,16 @@ module Ecoportal
36
36
  puts "\n" unless silent
37
37
  loop do
38
38
  params.update(cursor_id: cursor_id) if cursor_id
39
- body = nil; response = nil
39
+ body = nil; response = nil; count = 5
40
40
  loop do
41
41
  response = client.get("/people", params: params)
42
42
  body = response && body_data(response.body)
43
- break if response.success?
43
+ break if response.success? || count <= 0
44
44
  puts "Request failed - Status #{response.status}: #{body}"
45
+ count -= 1
46
+ sleep(0.5)
45
47
  end
46
- response = client.get("/people", params: params)
47
- #body = response && body_data(response.body)
48
- #raise "Request failed - Status #{response.status}: #{body}" unless response.success?
48
+ raise "Request failed - Status #{response.status}: #{body}" unless response.success?
49
49
 
50
50
  unless silent || (total = body["total_results"]) == 0
51
51
  results += body["results"].length
@@ -84,7 +84,7 @@ module Ecoportal
84
84
  response = client.get("/people/"+CGI.escape(id))
85
85
  body = body_data(response.body)
86
86
  return person_class.new(body) if response.success?
87
- raise "Could not get person #{id} - Error #{reponse.status}: #{body}"
87
+ raise "Could not get person #{id} - Error #{response.status}: #{body}"
88
88
  end
89
89
 
90
90
  # Requests an update of a person via api.
@@ -2,6 +2,9 @@ module Ecoportal
2
2
  module API
3
3
  class V1
4
4
  class PersonDetails < Common::BaseModel
5
+ class MissingId < StandardError
6
+ end
7
+
5
8
  passthrough :schema_id
6
9
 
7
10
  class_resolver :schema_field_value_class, "Ecoportal::API::V1::SchemaFieldValue"
@@ -43,16 +46,24 @@ module Ecoportal
43
46
  end
44
47
 
45
48
  # Sets the value to one specific field of the PersonDetails.
49
+ # @raise MisssingId if the `id` or `alt_id` is missing.
46
50
  # @param id [String] the `id` or the `alt_id` of the target field.
47
51
  # @return [void]
48
52
  def []=(id, value)
49
53
  if field = get_field(id)
50
54
  field.value = value
51
55
  else
52
- raise "details[#{id.inspect}] is missing. Did you forget to load the schema?"
56
+ raise MissingId.new("details[#{id.inspect}] is missing. Did you forget to load the schema?")
53
57
  end
54
58
  end
55
59
 
60
+ # Checks if an `id` or `alt_id` exists
61
+ # @param id [String] the `id` or the `alt_id` of the target field.
62
+ # @return [Boolean] `true` if it exists, `false` otherwise
63
+ def key?(id)
64
+ @fields_by_id.key?(id) || @fields_by_alt_id.key?(id)
65
+ end
66
+
56
67
  protected
57
68
 
58
69
  # Rebuilds the internal `id` and `alt_id` references to the fields.
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.8.4"
3
+ VERSION = "0.8.5"
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.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-05 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
281
281
  - !ruby/object:Gem::Version
282
282
  version: '0'
283
283
  requirements: []
284
- rubygems_version: 3.0.3
284
+ rubygems_version: 3.3.5
285
285
  signing_key:
286
286
  specification_version: 4
287
287
  summary: A collection of helpers for interacting with the ecoPortal MS's various APIs