ecoportal-api 0.4.3 → 0.5.0

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: 5441ef892224dc43af0a9060cf90725d93640cc98a66642565962ace69eefa00
4
- data.tar.gz: 5c53d8665f94cae4e06f86b72cc4807ed8862908f0999156fd792d38c8a46ed5
3
+ metadata.gz: af4b4d055b75875f58319c3299a216403457a9fbdf10cbaa3a731943e5a8bf82
4
+ data.tar.gz: c8ff8f7b9a60fd8b272dfb79d571d3c4d30ee70d59e389bbc538f1f839b7297f
5
5
  SHA512:
6
- metadata.gz: 0102b941ada369991d37a24676fedf97055633b3df0b4b0198f5dfef7007ddc289b53c1e36cdf4a0aae4afa995a26b05c26a3d2df5aecdcfeabe6e53bf108650
7
- data.tar.gz: e3d0401ba1d6d91508812f549677e23fc60667cb794d22cafe82fc5bda8c344b529cf248856c36f1d13dad9d4e0bc8a00d66844f628686b6b3442035521f1a12
6
+ metadata.gz: 806e76c2333dc8d415b3937894d508741a7b5d2c9badcab2cfb6da61938516a8eb2b812ba804c23f5e9ef83f86ff56cfcdbf4028cb57490f842d538701fbfd42
7
+ data.tar.gz: d4d1ffea2980774fd9d5b42d91aa00c2d757de97e99d1e1d086591e544e9d5612d6a2b7b629e713313d7e142e7502f7a282e4cefe6d8dd2c9ad2fc7705369c55
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "ecoportal-api"
8
8
  spec.version = Ecoportal::API::VERSION
9
9
  spec.authors = ["Tapio Saarinen"]
10
- spec.email = ["tapio@ecoportal.co.nz"]
10
+ spec.email = ["tapio@ecoportal.co.nz", "rien@ecoportal.co.nz", "oscar@ecoportal.co.nz"]
11
11
 
12
12
  spec.summary = %q{A collection of helpers for interacting with the ecoPortal MS's various APIs}
13
13
  spec.homepage = "https://www.ecoportal.com"
@@ -3,17 +3,15 @@ module Ecoportal
3
3
  class Internal
4
4
  class Account < Common::BaseModel
5
5
  passthrough :policy_group_ids, :landing_page_id, :permissions_preset, :permissions_custom,
6
- :preferences, :prefilter, :filter_tags, :login_provider_ids, :starred_ids, :accept_eula,
6
+ :preferences, :prefilter, :login_provider_ids, :starred_ids, :accept_eula,
7
7
  :send_invites, :default_tag
8
8
 
9
9
  class_resolver :preferences_class, "Ecoportal::API::Internal::Preferences"
10
10
  class_resolver :permissions_class, "Ecoportal::API::Internal::Permissions"
11
-
11
+
12
12
  embeds_one :permissions, key: "permissions_custom", klass: :permissions_class
13
13
  embeds_one :preferences, klass: :preferences_class
14
14
 
15
- VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
16
-
17
15
  # Sets the `permissions_preset`.
18
16
  # @note basically the same as `permissions_preset=` but when `"custom"`, it's changed to `nil`
19
17
  # @param value [nil, String] preset name.
@@ -28,22 +26,6 @@ module Ecoportal
28
26
  self.permissions_preset.nil? ? "custom" : self.permissions_preset
29
27
  end
30
28
 
31
- # Validates the string tags of the array, and sets the `filter_tags` property of the account.
32
- # @note all is set in upper case.
33
- # @raise [Exception] if there was any invalid string tag.
34
- # @param value [Array<String>] array of tags.
35
- def filter_tags=(value)
36
- unless value.is_a?(Array)
37
- raise "filter_tags= needs to be passed an Array, got #{value.class}"
38
- end
39
- doc["filter_tags"] = value.map do |tag|
40
- unless tag.match(VALID_TAG_REGEX)
41
- raise "Invalid filter tag #{tag.inspect}"
42
- end
43
- tag.upcase
44
- end
45
- end
46
-
47
29
  def as_json
48
30
  super.tap do |hash|
49
31
  if preset == "custom"
@@ -25,10 +25,7 @@ module Ecoportal
25
25
  when Internal::Account
26
26
  doc["account"] = JSON.parse(value.to_json)
27
27
  when Hash
28
- # TODO:
29
- # => missing send_invites
30
- # => better use an Internal::Account::PROPERTIES const for this kind of stuff
31
- doc["account"] = value.slice(%w[policy_group_ids landing_page_id permissions_preset permissions_custom preferences prefilter filter_tags login_provider_ids starred_ids])
28
+ doc["account"] = value.slice(*%w[policy_group_ids landing_page_id permissions_preset permissions_custom preferences prefilter login_provider_ids starred_ids])
32
29
  else
33
30
  # TODO
34
31
  raise "Invalid set on account: Need nil, Account or Hash; got #{value.class}"
@@ -8,12 +8,14 @@ module Ecoportal
8
8
  # @attr_reader subordinates [Integer] the number of people this person is supervisor of.
9
9
  # @attr details [PersonDetails, nil] the details of the person or `nil` if missing.
10
10
  class Person < Common::BaseModel
11
- passthrough :id, :external_id, :name, :email, :supervisor_id, :subordinates
11
+ passthrough :id, :external_id, :name, :email, :supervisor_id, :subordinates, :filter_tags
12
12
 
13
13
  class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
14
14
  class_resolver :person_details_class, "Ecoportal::API::V1::PersonDetails"
15
15
  embeds_one :details, nullable: true, klass: :person_details_class
16
16
 
17
+ VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
18
+
17
19
  # Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
18
20
  #
19
21
  # **Example Usage**:
@@ -39,6 +41,22 @@ module Ecoportal
39
41
  self.supervisor_id = person&.id || person&.external_id
40
42
  end
41
43
 
44
+ # Validates the string tags of the array, and sets the `filter_tags` property of the account.
45
+ # @note all is set in upper case.
46
+ # @raise [Exception] if there was any invalid string tag.
47
+ # @param value [Array<String>] array of tags.
48
+ def filter_tags=(value)
49
+ unless value.is_a?(Array)
50
+ raise "filter_tags= needs to be passed an Array, got #{value.class}"
51
+ end
52
+ doc["filter_tags"] = value.map do |tag|
53
+ unless tag.match(VALID_TAG_REGEX)
54
+ raise "Invalid filter tag #{tag.inspect}"
55
+ end
56
+ tag.upcase
57
+ end
58
+ end
59
+
42
60
  def as_json
43
61
  super.merge "details" => details&.as_json
44
62
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.4.3"
3
+ VERSION = "0.5.0"
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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-12 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -123,6 +123,8 @@ dependencies:
123
123
  description:
124
124
  email:
125
125
  - tapio@ecoportal.co.nz
126
+ - rien@ecoportal.co.nz
127
+ - oscar@ecoportal.co.nz
126
128
  executables: []
127
129
  extensions: []
128
130
  extra_rdoc_files: []