ecoportal-api 0.8.5 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +20 -20
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +55 -55
  5. data/.travis.yml +5 -5
  6. data/.yardopts +10 -10
  7. data/CHANGELOG.md +257 -236
  8. data/Gemfile +6 -6
  9. data/LICENSE +21 -21
  10. data/README.md +34 -34
  11. data/Rakefile +27 -27
  12. data/bin/console +14 -14
  13. data/bin/setup +8 -8
  14. data/ecoportal-api.gemspec +36 -36
  15. data/lib/ecoportal/api/common/base_class.rb +33 -29
  16. data/lib/ecoportal/api/common/base_model.rb +195 -177
  17. data/lib/ecoportal/api/common/batch_operation.rb +119 -119
  18. data/lib/ecoportal/api/common/batch_response.rb +34 -34
  19. data/lib/ecoportal/api/common/client.rb +198 -196
  20. data/lib/ecoportal/api/common/doc_helpers.rb +29 -29
  21. data/lib/ecoportal/api/common/elastic_apm_integration.rb +112 -112
  22. data/lib/ecoportal/api/common/hash_diff.rb +41 -41
  23. data/lib/ecoportal/api/common/logging.rb +12 -12
  24. data/lib/ecoportal/api/common/response.rb +31 -31
  25. data/lib/ecoportal/api/common/wrapped_response.rb +54 -54
  26. data/lib/ecoportal/api/common.rb +18 -18
  27. data/lib/ecoportal/api/errors/base.rb +8 -8
  28. data/lib/ecoportal/api/errors/time_out.rb +8 -8
  29. data/lib/ecoportal/api/errors.rb +9 -9
  30. data/lib/ecoportal/api/internal/account.rb +99 -100
  31. data/lib/ecoportal/api/internal/login_provider.rb +9 -9
  32. data/lib/ecoportal/api/internal/login_providers.rb +33 -33
  33. data/lib/ecoportal/api/internal/people.rb +14 -14
  34. data/lib/ecoportal/api/internal/permissions.rb +14 -13
  35. data/lib/ecoportal/api/internal/person.rb +101 -53
  36. data/lib/ecoportal/api/internal/person_details.rb +9 -9
  37. data/lib/ecoportal/api/internal/person_schema.rb +10 -10
  38. data/lib/ecoportal/api/internal/person_schemas.rb +11 -11
  39. data/lib/ecoportal/api/internal/policy_group.rb +9 -9
  40. data/lib/ecoportal/api/internal/policy_groups.rb +32 -32
  41. data/lib/ecoportal/api/internal/preferences.rb +31 -31
  42. data/lib/ecoportal/api/internal/schema_field.rb +8 -8
  43. data/lib/ecoportal/api/internal/schema_field_value.rb +8 -8
  44. data/lib/ecoportal/api/internal.rb +31 -31
  45. data/lib/ecoportal/api/logger.rb +62 -62
  46. data/lib/ecoportal/api/v1/people.rb +218 -218
  47. data/lib/ecoportal/api/v1/person.rb +138 -135
  48. data/lib/ecoportal/api/v1/person_details.rb +94 -82
  49. data/lib/ecoportal/api/v1/person_schema.rb +53 -53
  50. data/lib/ecoportal/api/v1/person_schemas.rb +48 -48
  51. data/lib/ecoportal/api/v1/schema_field.rb +34 -34
  52. data/lib/ecoportal/api/v1/schema_field_value.rb +65 -65
  53. data/lib/ecoportal/api/v1.rb +49 -49
  54. data/lib/ecoportal/api/version.rb +5 -5
  55. data/lib/ecoportal/api.rb +16 -16
  56. metadata +3 -3
@@ -1,48 +1,48 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
5
- class PersonSchemas
6
- extend Common::BaseClass
7
- include Enumerable
8
-
9
- class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
10
-
11
- attr_reader :client
12
-
13
- # @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
14
- # @return [Schemas] an instance object ready to make schema api requests.
15
- def initialize(client)
16
- @client = client
17
- end
18
-
19
- # Gets all the schemas via api request.
20
- # @return [Enumerable<PersonSchema>] an `Enumerable` with all schemas already wrapped as `PersonSchema` objects.
21
- def get_all
22
- response = client.get("/person_schemas")
23
- Common::WrappedResponse.new(response, person_schema_class)
24
- end
25
-
26
- # If a `block` is **not** given it calls [Object#to_enum](https://ruby-doc.org/core-2.6.2/Object.html#method-i-to_enum)
27
- # Otherwise it calls `get_all`.
28
- # @note
29
- # - `:params` doesn't really do anything.
30
- # - same as #get_all but with block :)
31
- # - `to_a` will call `each` (see this [detailed explanation](https://stackoverflow.com/a/45201663/4352306))
32
- # - however, as far as you have an iterator, such as `each`, `to_a` should be last resource (see [this explanation](https://stackoverflow.com/a/44186921/4352306))
33
- # @yield [schema] does some stuff with the schema.
34
- # @yieldparam schema [PersonSchema]
35
- # @yieldreturn [PersonSchema]
36
- # @return [Enumerable<PersonSchema>] an `Enumerable` with all the person schema objects.
37
- def each(params: {}, &block)
38
- return to_enum(:each) unless block
39
- get_all.each(&block)
40
- end
41
-
42
-
43
- end
44
- end
45
- end
46
- end
47
-
48
- require 'ecoportal/api/v1/person_schema'
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
5
+ class PersonSchemas
6
+ extend Common::BaseClass
7
+ include Enumerable
8
+
9
+ class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
10
+
11
+ attr_reader :client
12
+
13
+ # @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
14
+ # @return [Schemas] an instance object ready to make schema api requests.
15
+ def initialize(client)
16
+ @client = client
17
+ end
18
+
19
+ # Gets all the schemas via api request.
20
+ # @return [Enumerable<PersonSchema>] an `Enumerable` with all schemas already wrapped as `PersonSchema` objects.
21
+ def get_all
22
+ response = client.get("/person_schemas")
23
+ Common::WrappedResponse.new(response, person_schema_class)
24
+ end
25
+
26
+ # If a `block` is **not** given it calls [Object#to_enum](https://ruby-doc.org/core-2.6.2/Object.html#method-i-to_enum)
27
+ # Otherwise it calls `get_all`.
28
+ # @note
29
+ # - `:params` doesn't really do anything.
30
+ # - same as #get_all but with block :)
31
+ # - `to_a` will call `each` (see this [detailed explanation](https://stackoverflow.com/a/45201663/4352306))
32
+ # - however, as far as you have an iterator, such as `each`, `to_a` should be last resource (see [this explanation](https://stackoverflow.com/a/44186921/4352306))
33
+ # @yield [schema] does some stuff with the schema.
34
+ # @yieldparam schema [PersonSchema]
35
+ # @yieldreturn [PersonSchema]
36
+ # @return [Enumerable<PersonSchema>] an `Enumerable` with all the person schema objects.
37
+ def each(params: {}, &block)
38
+ return to_enum(:each) unless block
39
+ get_all.each(&block)
40
+ end
41
+
42
+
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ require 'ecoportal/api/v1/person_schema'
@@ -1,34 +1,34 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- class SchemaField < Common::BaseModel
5
- passthrough :id, :alt_id, :name, :optional, :shared, :multiple, :type, :options
6
-
7
- def parse_text(value)
8
- values = [*value.to_s.lines].map do |line|
9
- line = line.chomp
10
- next if line == ""
11
- case type
12
- when "text", "phone_number"
13
- line
14
- when "number"
15
- Float(line) rescue return nil, false
16
- when "boolean"
17
- %w[true TRUE True Y y YES X x].include?(line)
18
- when "select"
19
- return nil, false unless options.include?(line)
20
- line
21
- when "date"
22
- Date.parse(line) rescue return nil, false
23
- end
24
- end.compact
25
- if multiple
26
- return values, true
27
- else
28
- return values.first, true
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ class SchemaField < Common::BaseModel
5
+ passthrough :id, :alt_id, :name, :optional, :shared, :multiple, :type, :options
6
+
7
+ def parse_text(value)
8
+ values = [*value.to_s.lines].map do |line|
9
+ line = line.chomp
10
+ next if line == ""
11
+ case type
12
+ when "text", "phone_number"
13
+ line
14
+ when "number"
15
+ Float(line) rescue return nil, false
16
+ when "boolean"
17
+ %w[true TRUE True Y y YES X x].include?(line)
18
+ when "select"
19
+ return nil, false unless options.include?(line)
20
+ line
21
+ when "date"
22
+ Date.parse(line) rescue return nil, false
23
+ end
24
+ end.compact
25
+ if multiple
26
+ return values, true
27
+ else
28
+ return values.first, true
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,65 +1,65 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- # @todo Rename to PersonDetailsField
5
- class SchemaFieldValue < Common::BaseModel
6
- passthrough :id, :alt_id, :type, :name, :shared, :multiple
7
-
8
- def value
9
- case type
10
- when "text", "phone_number", "number", "boolean", "select"
11
- doc["value"]
12
- when "date"
13
- if doc["value"]
14
- maybe_multiple(doc["value"]) do |v|
15
- Date.iso8601(v)
16
- end
17
- end
18
- else
19
- raise "Unknown type #{type}"
20
- end
21
- end
22
-
23
- def value=(value)
24
- case type
25
- when "text", "phone_number", "select"
26
- doc["value"] = maybe_multiple(value) do |v|
27
- v&.to_s
28
- end
29
- when "number"
30
- maybe_multiple(value) do |v|
31
- unless v.nil? || v.is_a?(Numeric)
32
- raise "Invalid number type #{v.class}"
33
- end
34
- end
35
- doc["value"] = value
36
- when "boolean"
37
- doc["value"] = !!value
38
- when "date"
39
- maybe_multiple(value) do |v|
40
- unless v.nil? || v.respond_to?(:to_date)
41
- raise "Invalid date type #{v.class}"
42
- end
43
- end
44
- doc["value"] = maybe_multiple(value) do |v|
45
- v&.to_date&.to_s
46
- end
47
- else
48
- raise "Unknown type #{type}"
49
- end
50
- end
51
-
52
- def maybe_multiple(value)
53
- if multiple
54
- unless value.is_a?(Array)
55
- raise "Expected Array, got #{value.class}"
56
- end
57
- value.map {|v| yield v }
58
- else
59
- yield value
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ # @todo Rename to PersonDetailsField
5
+ class SchemaFieldValue < Common::BaseModel
6
+ passthrough :id, :alt_id, :type, :name, :shared, :multiple
7
+
8
+ def value
9
+ case type
10
+ when "text", "phone_number", "number", "boolean", "select"
11
+ doc["value"]
12
+ when "date"
13
+ if doc["value"]
14
+ maybe_multiple(doc["value"]) do |v|
15
+ Date.iso8601(v)
16
+ end
17
+ end
18
+ else
19
+ raise "Unknown type #{type}"
20
+ end
21
+ end
22
+
23
+ def value=(value)
24
+ case type
25
+ when "text", "phone_number", "select"
26
+ doc["value"] = maybe_multiple(value) do |v|
27
+ v&.to_s
28
+ end
29
+ when "number"
30
+ maybe_multiple(value) do |v|
31
+ unless v.nil? || v.is_a?(Numeric)
32
+ raise "Invalid number type #{v.class}"
33
+ end
34
+ end
35
+ doc["value"] = value
36
+ when "boolean"
37
+ doc["value"] = !!value
38
+ when "date"
39
+ maybe_multiple(value) do |v|
40
+ unless v.nil? || v.respond_to?(:to_date)
41
+ raise "Invalid date type #{v.class}"
42
+ end
43
+ end
44
+ doc["value"] = maybe_multiple(value) do |v|
45
+ v&.to_date&.to_s
46
+ end
47
+ else
48
+ raise "Unknown type #{type}"
49
+ end
50
+ end
51
+
52
+ def maybe_multiple(value)
53
+ if multiple
54
+ unless value.is_a?(Array)
55
+ raise "Expected Array, got #{value.class}"
56
+ end
57
+ value.map {|v| yield v }
58
+ else
59
+ yield value
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,49 +1,49 @@
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 V1
6
- extend Common::BaseClass
7
- include Common::Logging
8
-
9
- VERSION = "v1"
10
- class_resolver :people_class, "Ecoportal::API::V1::People"
11
- class_resolver :person_schemas_class, "Ecoportal::API::V1::PersonSchemas"
12
-
13
- attr_reader :client, :logger
14
-
15
- # Creates an `V1` 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 sublcass of `V1` 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 [V1] an object with the api version suit.
23
- def initialize(api_key, 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 people api requests.
34
- # @return [People] an instance object ready to make people api requests.
35
- def people
36
- people_class.new(client)
37
- end
38
-
39
- # Obtain specific object for schema api requests.
40
- # @return [PersonSchemas] an instance object ready to make schema api requests.
41
- def person_schemas
42
- person_schemas_class.new(client)
43
- end
44
- end
45
- end
46
- end
47
-
48
- require 'ecoportal/api/v1/person_schemas'
49
- require 'ecoportal/api/v1/people'
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 V1
6
+ extend Common::BaseClass
7
+ include Common::Logging
8
+
9
+ VERSION = "v1"
10
+ class_resolver :people_class, "Ecoportal::API::V1::People"
11
+ class_resolver :person_schemas_class, "Ecoportal::API::V1::PersonSchemas"
12
+
13
+ attr_reader :client, :logger
14
+
15
+ # Creates an `V1` 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 sublcass of `V1` 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 [V1] an object with the api version suit.
23
+ def initialize(api_key, 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 people api requests.
34
+ # @return [People] an instance object ready to make people api requests.
35
+ def people
36
+ people_class.new(client)
37
+ end
38
+
39
+ # Obtain specific object for schema api requests.
40
+ # @return [PersonSchemas] an instance object ready to make schema api requests.
41
+ def person_schemas
42
+ person_schemas_class.new(client)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ require 'ecoportal/api/v1/person_schemas'
49
+ require 'ecoportal/api/v1/people'
@@ -1,5 +1,5 @@
1
- module Ecoportal
2
- module API
3
- VERSION = "0.8.5"
4
- end
5
- end
1
+ module Ecoportal
2
+ module API
3
+ VERSION = "0.9.2"
4
+ end
5
+ end
data/lib/ecoportal/api.rb CHANGED
@@ -1,16 +1,16 @@
1
- require "cgi"
2
- require "logger"
3
- require "hash-polyfill"
4
- require "ecoportal/api/version"
5
- require "dotenv/load"
6
-
7
- module Ecoportal
8
- module API
9
- end
10
- end
11
-
12
- require "ecoportal/api/logger"
13
- require "ecoportal/api/common"
14
- require "ecoportal/api/errors"
15
- require "ecoportal/api/v1"
16
- require "ecoportal/api/internal"
1
+ require "cgi"
2
+ require "logger"
3
+ require "hash-polyfill"
4
+ require "ecoportal/api/version"
5
+ require "dotenv/load"
6
+
7
+ module Ecoportal
8
+ module API
9
+ end
10
+ end
11
+
12
+ require "ecoportal/api/logger"
13
+ require "ecoportal/api/common"
14
+ require "ecoportal/api/errors"
15
+ require "ecoportal/api/v1"
16
+ require "ecoportal/api/internal"
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.5
4
+ version: 0.9.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: 2022-03-31 00:00:00.000000000 Z
11
+ date: 2023-03-10 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.3.5
284
+ rubygems_version: 3.0.3
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