ecoportal-api 0.10.8 → 0.10.9

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -2
  3. data/lib/ecoportal/api/common/base_class.rb +11 -12
  4. data/lib/ecoportal/api/common/base_model.rb +3 -3
  5. data/lib/ecoportal/api/common/batch_operation.rb +10 -10
  6. data/lib/ecoportal/api/common/batch_response.rb +1 -1
  7. data/lib/ecoportal/api/common/client/elastic_apm_integration.rb +9 -9
  8. data/lib/ecoportal/api/common/client/error/checks.rb +1 -1
  9. data/lib/ecoportal/api/common/client/with_retry.rb +1 -1
  10. data/lib/ecoportal/api/common/client.rb +13 -13
  11. data/lib/ecoportal/api/common/doc_helpers.rb +7 -6
  12. data/lib/ecoportal/api/common/hash_diff.rb +8 -5
  13. data/lib/ecoportal/api/common/logging.rb +1 -0
  14. data/lib/ecoportal/api/common/response.rb +1 -1
  15. data/lib/ecoportal/api/common/wrapped_response.rb +1 -1
  16. data/lib/ecoportal/api/internal/account.rb +18 -18
  17. data/lib/ecoportal/api/internal/people.rb +1 -1
  18. data/lib/ecoportal/api/internal/person.rb +24 -18
  19. data/lib/ecoportal/api/internal/person_details.rb +1 -1
  20. data/lib/ecoportal/api/internal/person_schema.rb +1 -1
  21. data/lib/ecoportal/api/internal/person_schemas.rb +1 -1
  22. data/lib/ecoportal/api/internal/policy_groups.rb +3 -2
  23. data/lib/ecoportal/api/internal/preferences.rb +13 -10
  24. data/lib/ecoportal/api/internal.rb +5 -5
  25. data/lib/ecoportal/api/logger.rb +8 -7
  26. data/lib/ecoportal/api/v1/job/awaiter/timer.rb +1 -0
  27. data/lib/ecoportal/api/v1/job/status.rb +2 -2
  28. data/lib/ecoportal/api/v1/job.rb +4 -4
  29. data/lib/ecoportal/api/v1/people.rb +12 -10
  30. data/lib/ecoportal/api/v1/person.rb +27 -15
  31. data/lib/ecoportal/api/v1/person_details.rb +7 -7
  32. data/lib/ecoportal/api/v1/person_schema.rb +5 -4
  33. data/lib/ecoportal/api/v1/person_schemas.rb +9 -6
  34. data/lib/ecoportal/api/v1/schema_field.rb +8 -8
  35. data/lib/ecoportal/api/v1/schema_field_value.rb +15 -15
  36. data/lib/ecoportal/api/v1.rb +4 -4
  37. data/lib/ecoportal/api/version.rb +1 -1
  38. data/lib/ecoportal/api.rb +9 -9
  39. metadata +2 -2
@@ -2,7 +2,7 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class PersonSchema < V1::PersonSchema
5
- class_resolver :schema_field_class, "Ecoportal::API::Internal::SchemaField"
5
+ class_resolver :schema_field_class, 'Ecoportal::API::Internal::SchemaField'
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class PersonSchemas < V1::PersonSchemas
5
- class_resolver :person_schema_class, "Ecoportal::API::Internal::PersonSchema"
5
+ class_resolver :person_schema_class, 'Ecoportal::API::Internal::PersonSchema'
6
6
  end
7
7
  end
8
8
  end
@@ -15,13 +15,14 @@ module Ecoportal
15
15
 
16
16
  # Gets all the policy groups via api request.
17
17
  # @return [Enumerable<PolicyGroup>] an `Enumerable` with all the policy groups already wrapped as `PolicyGroup` objects.
18
- def get_all
19
- response = client.get("/policy_groups")
18
+ def get_all # rubocop:disable Naming/AccessorMethodName
19
+ response = client.get('/policy_groups')
20
20
  Common::WrappedResponse.new(response, Internal::PolicyGroup)
21
21
  end
22
22
 
23
23
  def each(&block)
24
24
  return to_enum(:each) unless block
25
+
25
26
  get_all.each(&block)
26
27
  end
27
28
  end
@@ -2,17 +2,19 @@ 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
5
+ passthrough(
6
+ :kiosk_enabled, :kiosk_workflow_message, :kiosk_create_button_label,
7
+ :kiosk_create_button_help, :kiosk_return_button_label, :kiosk_return_button_help,
8
+ :kiosk_dashboard_button_label, :kiosk_dashboard_button_help
9
+ )
8
10
 
9
- [
10
- :show_sidebar,
11
- :show_shortcuts,
12
- :show_coming_soon,
13
- :show_recently_visited_forms,
14
- :show_tasks,
15
- :show_task_bubbles
11
+ %i[
12
+ show_sidebar
13
+ show_shortcuts
14
+ show_coming_soon
15
+ show_recently_visited_forms
16
+ show_tasks
17
+ show_task_bubbles
16
18
  ].map(&:to_s).each do |field|
17
19
  define_method(field) do
18
20
  if doc.key?(field)
@@ -21,6 +23,7 @@ module Ecoportal
21
23
  true
22
24
  end
23
25
  end
26
+
24
27
  define_method("#{field}=") do |value|
25
28
  doc[field] = !!value
26
29
  end
@@ -3,12 +3,12 @@ module Ecoportal
3
3
  class Internal < V1
4
4
  include Common::Logging
5
5
 
6
- VERSION = "v0".freeze
7
- class_resolver :people_class, "Ecoportal::API::Internal::People"
8
- class_resolver :person_schemas_class, "Ecoportal::API::Internal::PersonSchemas"
6
+ VERSION = 'v0'.freeze
7
+ class_resolver :people_class, 'Ecoportal::API::Internal::People'
8
+ class_resolver :person_schemas_class, 'Ecoportal::API::Internal::PersonSchemas'
9
9
 
10
- class_resolver :policy_groups_class, "Ecoportal::API::Internal::PolicyGroups"
11
- class_resolver :login_providers_class, "Ecoportal::API::Internal::LoginProviders"
10
+ class_resolver :policy_groups_class, 'Ecoportal::API::Internal::PolicyGroups'
11
+ class_resolver :login_providers_class, 'Ecoportal::API::Internal::LoginProviders'
12
12
 
13
13
  # Obtain specific object for policy groups api requests.
14
14
  # @return [PolicyGroups] an instance object ready to make policy groups api requests.
@@ -1,26 +1,27 @@
1
1
  module Ecoportal
2
2
  module API
3
3
  class Logger
4
- TIMESTAMP_PATTERN = "%Y-%m-%dT%H:%M:%S".freeze
4
+ TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze
5
5
 
6
6
  STDOUT_FORMAT_PROC = proc do |severity, _datetime, _progname, msg|
7
7
  prefix = "%5s > " % severity # rubocop:disable Style/FormatString
8
- msg.lines.map.with_index do |line, idx|
8
+ msg.lines.map.with_index do |line, idx| # rubocop:disable Style/StringConcatenation
9
9
  if idx.zero?
10
10
  prefix + line.chomp
11
11
  else
12
- (" " * prefix.length) + line.chomp
12
+ (' ' * prefix.length) + line.chomp
13
13
  end
14
14
  end.join("\n")+"\n"
15
15
  end
16
16
 
17
17
  FILE_FORMAT_PROC = proc do |severity, datetime, _progname, msg|
18
18
  prefix = "%5s(%s) > " % [severity, datetime.strftime(TIMESTAMP_PATTERN)] # rubocop:disable Style/FormatString, Style/FormatStringToken
19
- msg.lines.map.with_index do |line, idx|
19
+
20
+ msg.lines.map.with_index do |line, idx| # rubocop:disable Style/StringConcatenation
20
21
  if idx.zero?
21
22
  prefix + line.chomp
22
23
  else
23
- (" " * prefix.length) + line.chomp
24
+ (' ' * prefix.length) + line.chomp
24
25
  end
25
26
  end.join("\n")+"\n"
26
27
  end
@@ -30,7 +31,7 @@ module Ecoportal
30
31
  def initialize(
31
32
  console_level: ::Logger::INFO,
32
33
  file_level: ::Logger::DEBUG,
33
- output_file: File.join(Dir.getwd, "API_Log-#{Time.now.strftime("%Y-%m-%dT%H%M")}.txt")
34
+ output_file: File.join(Dir.getwd, "API_Log-#{Time.now.strftime('%Y-%m-%dT%H%M')}.txt")
34
35
  )
35
36
  @console = make_stdout_logger(console_level)
36
37
  @file = make_file_logger(file_level, output_file)
@@ -54,7 +55,7 @@ module Ecoportal
54
55
 
55
56
  def make_file_logger(level, output_file)
56
57
  return unless output_file
57
- ::Logger.new(File.open(output_file, "a")).tap do |logger|
58
+ ::Logger.new(File.open(output_file, 'a')).tap do |logger|
58
59
  logger.formatter = FILE_FORMAT_PROC
59
60
  logger.level = level
60
61
  end
@@ -9,6 +9,7 @@ module Ecoportal
9
9
  status lstatus
10
10
  ].freeze
11
11
 
12
+ # The class
12
13
  Timer = Struct.new(*TIMER_ARGS) do
13
14
  self::MAX_START_DELAY = 60
14
15
 
@@ -44,8 +44,8 @@ module Ecoportal
44
44
  end
45
45
 
46
46
  def to_s
47
- msg = complete? ? "Completed" : "In progress"
48
- msg = "Errored" if errored?
47
+ msg = complete? ? 'Completed' : 'In progress'
48
+ msg = 'Errored' if errored?
49
49
  msg << " with #{progress} done."
50
50
  msg
51
51
  end
@@ -31,7 +31,7 @@ module Ecoportal
31
31
  raise_if_already_launched! unless recover
32
32
 
33
33
  @operation ||= Common::BatchOperation.new(
34
- "/people",
34
+ '/people',
35
35
  person_class,
36
36
  logger: client.logger
37
37
  )
@@ -84,7 +84,7 @@ module Ecoportal
84
84
  def raise_if_already_launched!
85
85
  return unless created?
86
86
 
87
- msg = "Missusage: job was already created."
87
+ msg = 'Missusage: job was already created.'
88
88
  msg << " Can't call batch more than once"
89
89
  raise msg
90
90
  end
@@ -102,8 +102,8 @@ module Ecoportal
102
102
 
103
103
  job_id = nil
104
104
 
105
- client.post("/people/job", data: operation.as_json).tap do |response|
106
- job_id = body_data(response.body)["id"] if response.success?
105
+ client.post('/people/job', data: operation.as_json).tap do |response|
106
+ job_id = body_data(response.body)['id'] if response.success?
107
107
 
108
108
  next if job_id
109
109
 
@@ -8,7 +8,7 @@ module Ecoportal
8
8
  include Common::DocHelpers
9
9
  include Enumerable
10
10
 
11
- class_resolver :person_class, "Ecoportal::API::V1::Person"
11
+ class_resolver :person_class, 'Ecoportal::API::V1::Person'
12
12
 
13
13
  attr_reader :client
14
14
 
@@ -44,7 +44,7 @@ module Ecoportal
44
44
  count = 5
45
45
 
46
46
  loop do
47
- response = client.get("/people", params: params)
47
+ response = client.get('/people', params: params)
48
48
  body = response && body_data(response.body)
49
49
  break if response.success? || count <= 0
50
50
 
@@ -56,22 +56,22 @@ module Ecoportal
56
56
 
57
57
  raise "Request failed - Status #{response.status}: #{body}" unless response.success?
58
58
 
59
- unless silent || (total = body["total_results"])&.zero?
60
- results += body["results"].length
59
+ unless silent || (total = body['total_results'])&.zero?
60
+ results += body['results'].length
61
61
  percent = results * 100 / total
62
62
 
63
- msg = "People GET"
63
+ msg = 'People GET'
64
64
  msg << " (search=#{params[:q]})" if params.key?(:q)
65
65
 
66
66
  print "#{msg}: #{percent.round}% (of #{total}): #{results}\r"
67
67
  $stdout.flush
68
68
  end
69
69
 
70
- body["results"].each do |person|
70
+ body['results'].each do |person|
71
71
  yield person_class.new(person)
72
72
  end
73
73
 
74
- break unless (cursor_id = body["cursor_id"])
74
+ break unless (cursor_id = body['cursor_id'])
75
75
  end
76
76
  self
77
77
  end
@@ -106,6 +106,7 @@ module Ecoportal
106
106
  def update(doc)
107
107
  body = get_body(doc)
108
108
  id = get_id(doc)
109
+
109
110
  client.patch("/people/#{CGI.escape(id)}", data: body)
110
111
  end
111
112
 
@@ -114,7 +115,8 @@ module Ecoportal
114
115
  # @return [Response] an object with the api response.
115
116
  def create(doc)
116
117
  body = get_body(doc)
117
- client.post("/people", data: body)
118
+
119
+ client.post('/people', data: body)
118
120
  end
119
121
 
120
122
  # Requests to update an existing person or if it does not exist, to create it, via api.
@@ -143,7 +145,7 @@ module Ecoportal
143
145
  return job.batch(&block) if job_mode
144
146
 
145
147
  operation = Common::BatchOperation.new(
146
- "/people",
148
+ '/people',
147
149
  person_class,
148
150
  logger: client.logger
149
151
  )
@@ -151,7 +153,7 @@ module Ecoportal
151
153
  yield operation
152
154
 
153
155
  # The batch operation is responsible for logging the output
154
- client.post("/people/batch", data: operation.as_json).tap do |response|
156
+ client.post('/people/batch', data: operation.as_json).tap do |response|
155
157
  operation.process_response(response)
156
158
  end
157
159
  end
@@ -10,25 +10,35 @@ module Ecoportal
10
10
  class Person < Common::BaseModel
11
11
  passthrough :id, :external_id, :name, :email, :filter_tags
12
12
  passthrough :archived
13
+ alias_method :archived?, :archived
14
+
13
15
  passthrough :supervisor_id, :contractor_organization_id
14
16
  passthrough :brand_id
15
17
  passthrough :freemium
16
18
 
17
- class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
18
- class_resolver :person_details_class, "Ecoportal::API::V1::PersonDetails"
19
+ class_resolver :person_schema_class, 'Ecoportal::API::V1::PersonSchema'
20
+ class_resolver :person_details_class, 'Ecoportal::API::V1::PersonDetails'
19
21
  embeds_one :details, nullable: true, klass: :person_details_class
20
22
 
21
23
  VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/.-]+$/
22
24
  VALID_EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
23
25
 
26
+ def unarchive!
27
+ self.archived = false
28
+ end
29
+
30
+ def archive!
31
+ self.archived = true
32
+ end
33
+
24
34
  # Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
25
35
  #
26
36
  # **Example Usage**:
27
37
  # ```ruby
28
38
  # API_KEY = 'some-private-api-key-version'
29
- # HOST = "live.ecoportal.com"
39
+ # HOST = 'live.ecoportal.com'
30
40
  # api = Ecoportal::API::Internal.new(API_KEY, host: HOST)
31
- # person = api.people.get({"id": "my-dummy-user"})
41
+ # person = api.people.get({'id': 'my-dummy-user'})
32
42
  # super = person.supervisor(api.client)
33
43
  # pp "#{person.name}'s supervisor is #{super.name}."
34
44
  # ```
@@ -37,6 +47,7 @@ module Ecoportal
37
47
  def supervisor(client)
38
48
  return @supervisor if defined?(@supervisor)
39
49
  return @supervisor = nil if supervisor_id.nil?
50
+
40
51
  @supervisor = client.people.get(supervisor_id).result
41
52
  end
42
53
 
@@ -51,7 +62,7 @@ module Ecoportal
51
62
  def email=(value)
52
63
  raise "Invalid email #{value.inspect}" if value && !value.match(VALID_EMAIL_REGEX)
53
64
 
54
- doc["email"] = value&.downcase
65
+ doc['email'] = value&.downcase
55
66
  end
56
67
 
57
68
  # Validates the string tags of the array, and sets the `filter_tags` property of the account.
@@ -69,20 +80,20 @@ module Ecoportal
69
80
  tag.upcase
70
81
  end
71
82
 
72
- set_uniq_array_keep_order("filter_tags", end_tags)
83
+ set_uniq_array_keep_order('filter_tags', end_tags)
73
84
  end
74
85
 
75
86
  # @return [Array<String>] the filter tags of this person.
76
87
  def filter_tags
77
- doc["filter_tags"] ||= []
88
+ doc['filter_tags'] ||= []
78
89
  end
79
90
 
80
91
  def as_json
81
- super.merge "details" => details&.as_json
92
+ super.merge 'details' => details&.as_json
82
93
  end
83
94
 
84
95
  def as_update(ref = :last, ignore: [])
85
- super(ref, ignore: ignore)
96
+ super
86
97
  end
87
98
 
88
99
  # Sets the PersonDetails to the person, depending on the paramter received:
@@ -95,15 +106,15 @@ module Ecoportal
95
106
  def details=(value)
96
107
  case value
97
108
  when NilClass
98
- doc["details"] = nil
109
+ doc['details'] = nil
99
110
  when person_details_class
100
- doc["details"] = value.as_json
111
+ doc['details'] = value.as_json
101
112
  when Hash
102
- doc["details"] = value.slice("schema_id", "fields")
113
+ doc['details'] = value.slice('schema_id', 'fields')
103
114
  else
104
115
  raise "Invalid type set on details. Required nil, PersonDetails or Hash; got #{value.class}"
105
116
  end
106
- remove_instance_variable("@details") if defined?(@details)
117
+ remove_instance_variable('@details') if defined?(@details)
107
118
  end
108
119
 
109
120
  # Sets the PersonDetails to the person, depending on the parameter received:
@@ -127,10 +138,11 @@ module Ecoportal
127
138
  else
128
139
  raise "Invalid set on details: Requierd PersonSchema or String; got #{schema_or_id.class}"
129
140
  end
141
+
130
142
  self.details = new_details
131
143
  # Patch out static data from as_update
132
- original_doc["details"] = {
133
- "fields" => JSON.parse(doc["details"]["fields"].to_json)
144
+ original_doc['details'] = {
145
+ 'fields' => JSON.parse(doc['details']['fields'].to_json)
134
146
  }
135
147
  end
136
148
  end
@@ -7,10 +7,10 @@ module Ecoportal
7
7
 
8
8
  passthrough :schema_id
9
9
 
10
- class_resolver :schema_field_value_class, "Ecoportal::API::V1::SchemaFieldValue"
10
+ class_resolver :schema_field_value_class, 'Ecoportal::API::V1::SchemaFieldValue'
11
11
 
12
12
  def as_json
13
- super.merge "fields" => fields.map(&:as_json)
13
+ super.merge 'fields' => fields.map(&:as_json)
14
14
  end
15
15
 
16
16
  # Sets the `id` of the PersonDetails.
@@ -18,15 +18,15 @@ module Ecoportal
18
18
  # @param value [nil, String] the id of the schema.
19
19
  def schema_id=(value)
20
20
  @fields = [] if value.nil?
21
- doc["schema_id"] = value
21
+ doc['schema_id'] = value
22
22
  end
23
23
 
24
24
  # Gets all the fields of the PersonDetails.
25
25
  # @return [Array<SchemaFieldValue>] the array of fields of the schema.
26
26
  def fields
27
27
  return @fields if defined?(@fields)
28
- @fields = (doc["fields"] || []).each_with_index.map do |field, i|
29
- schema_field_value_class.new(field, parent: self, key: ["fields", i])
28
+ @fields = (doc['fields'] || []).each_with_index.map do |field, i|
29
+ schema_field_value_class.new(field, parent: self, key: ['fields', i])
30
30
  end
31
31
  end
32
32
 
@@ -69,13 +69,13 @@ module Ecoportal
69
69
  def changed?(id, doc = :original)
70
70
  return false unless (field = get_field(id))
71
71
 
72
- field.as_update.key?("value")
72
+ field.as_update.key?('value')
73
73
  end
74
74
 
75
75
  def original_value(id)
76
76
  return nil unless (field = get_field(id))
77
77
 
78
- field.original_doc["value"]
78
+ field.original_doc['value']
79
79
  end
80
80
 
81
81
  protected
@@ -5,7 +5,7 @@ module Ecoportal
5
5
  passthrough :id, :name
6
6
  passthrough :enable_tags, :tags
7
7
 
8
- class_resolver :schema_field_class, "Ecoportal::API::V1::SchemaField"
8
+ class_resolver :schema_field_class, 'Ecoportal::API::V1::SchemaField'
9
9
 
10
10
  def fields
11
11
  @fields_by_id or index_fields
@@ -31,7 +31,7 @@ module Ecoportal
31
31
  @fields_by_id = {}
32
32
  @fields_by_alt_id = {}
33
33
 
34
- doc["fields"].each do |field|
34
+ doc['fields'].each do |field|
35
35
  wrapped = schema_field_class.new(field)
36
36
  @fields_by_id[wrapped.id] = wrapped
37
37
  @fields_by_alt_id[wrapped.alt_id] = wrapped
@@ -40,9 +40,9 @@ module Ecoportal
40
40
 
41
41
  def initialize_details(details)
42
42
  details.schema_id = id
43
- details.doc["fields"] = fields.map do |field|
43
+ details.doc['fields'] = fields.map do |field|
44
44
  field.doc.slice(*%w[id alt_id name multiple type shared]).merge(
45
- "value" => field.multiple ? [] : nil
45
+ 'value' => field.multiple ? [] : nil
46
46
  )
47
47
  end
48
48
  end
@@ -50,4 +50,5 @@ module Ecoportal
50
50
  end
51
51
  end
52
52
  end
53
+
53
54
  require 'ecoportal/api/v1/schema_field'
@@ -1,12 +1,13 @@
1
1
  module Ecoportal
2
2
  module API
3
3
  class V1
4
- # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
4
+ # @attr_reader client [Common::Client] a `Common::Client` object that holds
5
+ # the configuration of the api connection.
5
6
  class PersonSchemas
6
7
  extend Common::BaseClass
7
8
  include Enumerable
8
9
 
9
- class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
10
+ class_resolver :person_schema_class, 'Ecoportal::API::V1::PersonSchema'
10
11
 
11
12
  attr_reader :client
12
13
 
@@ -18,8 +19,8 @@ module Ecoportal
18
19
 
19
20
  # Gets all the schemas via api request.
20
21
  # @return [Enumerable<PersonSchema>] an `Enumerable` with all schemas already wrapped as `PersonSchema` objects.
21
- def get_all
22
- response = client.get("/person_schemas")
22
+ def get_all # rubocop:disable Naming/AccessorMethodName
23
+ response = client.get('/person_schemas')
23
24
  Common::WrappedResponse.new(response, person_schema_class)
24
25
  end
25
26
 
@@ -29,13 +30,15 @@ module Ecoportal
29
30
  # - `:params` doesn't really do anything.
30
31
  # - same as #get_all but with block :)
31
32
  # - `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
+ # - however, as far as you have an iterator, such as `each`,
34
+ # `to_a` should be last resource (see [this explanation](https://stackoverflow.com/a/44186921/4352306))
33
35
  # @yield [schema] does some stuff with the schema.
34
36
  # @yieldparam schema [PersonSchema]
35
37
  # @yieldreturn [PersonSchema]
36
38
  # @return [Enumerable<PersonSchema>] an `Enumerable` with all the person schema objects.
37
39
  def each(params: {}, &block)
38
- return to_enum(:each) unless block
40
+ return to_enum(:each, params: params) unless block
41
+
39
42
  get_all.each(&block)
40
43
  end
41
44
  end
@@ -7,19 +7,19 @@ module Ecoportal
7
7
  def parse_text(value)
8
8
  values = [*value.to_s.lines].map do |line|
9
9
  line = line.chomp
10
- next if line == ""
10
+ next if line == ''
11
11
  case type
12
- when "text", "phone_number"
12
+ when 'text', 'phone_number'
13
13
  line
14
- when "number"
15
- Float(line) rescue return nil, false
16
- when "boolean"
14
+ when 'number'
15
+ Float(line) rescue return nil, false # rubocop:disable Style/RescueModifier
16
+ when 'boolean'
17
17
  %w[true TRUE True Y y YES X x].include?(line)
18
- when "select"
18
+ when 'select'
19
19
  return nil, false unless options.include?(line)
20
20
  line
21
- when "date"
22
- Date.parse(line) rescue return nil, false
21
+ when 'date'
22
+ Date.parse(line) rescue return nil, false # rubocop:disable Style/RescueModifier
23
23
  end
24
24
  end.compact
25
25
 
@@ -6,18 +6,18 @@ module Ecoportal
6
6
  passthrough :id, :alt_id, :type, :name, :shared, :multiple
7
7
 
8
8
  def clear
9
- return doc["value"] = [] if multiple
9
+ return doc['value'] = [] if multiple
10
10
 
11
- doc["value"] = nil
11
+ doc['value'] = nil
12
12
  end
13
13
 
14
14
  def value
15
15
  case type
16
- when "text", "phone_number", "number", "boolean", "select"
17
- doc["value"]
18
- when "date"
19
- if doc["value"]
20
- maybe_multiple(doc["value"]) do |v|
16
+ when 'text', 'phone_number', 'number', 'boolean', 'select'
17
+ doc['value']
18
+ when 'date'
19
+ if doc['value']
20
+ maybe_multiple(doc['value']) do |v|
21
21
  Date.iso8601(v)
22
22
  end
23
23
  end
@@ -28,28 +28,28 @@ module Ecoportal
28
28
 
29
29
  def value=(value) # rubocop:disable Metrics/AbcSize
30
30
  case type
31
- when "text", "phone_number", "select"
32
- doc["value"] = maybe_multiple(value) do |v|
31
+ when 'text', 'phone_number', 'select'
32
+ doc['value'] = maybe_multiple(value) do |v|
33
33
  v&.to_s
34
34
  end
35
- when "number"
35
+ when 'number'
36
36
  maybe_multiple(value) do |v|
37
37
  next if v.nil? || v.is_a?(Numeric)
38
38
 
39
39
  raise "Invalid number type #{v.class}"
40
40
  end
41
41
 
42
- doc["value"] = value
43
- when "boolean"
44
- doc["value"] = !!value
45
- when "date"
42
+ doc['value'] = value
43
+ when 'boolean'
44
+ doc['value'] = !!value
45
+ when 'date'
46
46
  maybe_multiple(value) do |v|
47
47
  next if v.nil? || v.respond_to?(:to_date)
48
48
 
49
49
  raise "Invalid date type #{v.class}"
50
50
  end
51
51
 
52
- doc["value"] = maybe_multiple(value) do |v|
52
+ doc['value'] = maybe_multiple(value) do |v|
53
53
  v&.to_date&.to_s
54
54
  end
55
55
  else
@@ -6,10 +6,10 @@ module Ecoportal
6
6
  extend Common::BaseClass
7
7
  include Common::Logging
8
8
 
9
- VERSION = "v1".freeze
9
+ VERSION = 'v1'.freeze
10
10
 
11
- class_resolver :people_class, "Ecoportal::API::V1::People"
12
- class_resolver :person_schemas_class, "Ecoportal::API::V1::PersonSchemas"
11
+ class_resolver :people_class, 'Ecoportal::API::V1::People'
12
+ class_resolver :person_schemas_class, 'Ecoportal::API::V1::PersonSchemas'
13
13
 
14
14
  attr_reader :client, :logger
15
15
 
@@ -21,7 +21,7 @@ module Ecoportal
21
21
  # @param host [String] api server domain.
22
22
  # @param logger [Logger] an object with `Logger` interface to generate logs.
23
23
  # @return [V1] an object with the api version suit.
24
- def initialize(api_key, host: "live.ecoportal.com", logger: default_logger)
24
+ def initialize(api_key, host: 'live.ecoportal.com', logger: default_logger)
25
25
  @logger = logger
26
26
  @client = Common::Client.new(
27
27
  api_key: api_key,
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = '0.10.8'.freeze
3
+ VERSION = '0.10.9'.freeze
4
4
  end
5
5
  end