ecoportal-api-oozes 0.7.0 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +103 -1
  3. data/README.md +2 -0
  4. data/ecoportal-api-oozes.gemspec +13 -6
  5. data/lib/ecoportal/api/common/content/class_helpers.rb +35 -0
  6. data/lib/ecoportal/api/common/content/collection_model.rb +25 -3
  7. data/lib/ecoportal/api/common/content/double_model.rb +27 -12
  8. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +8 -2
  9. data/lib/ecoportal/api/common/content/wrapped_response.rb +1 -1
  10. data/lib/ecoportal/api/v2.rb +38 -3
  11. data/lib/ecoportal/api/v2/page.rb +3 -3
  12. data/lib/ecoportal/api/v2/page/component.rb +24 -7
  13. data/lib/ecoportal/api/v2/page/component/action.rb +14 -3
  14. data/lib/ecoportal/api/v2/page/component/action_field.rb +40 -2
  15. data/lib/ecoportal/api/v2/page/component/chart_field.rb +54 -0
  16. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +29 -0
  17. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +27 -0
  18. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +26 -0
  19. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +31 -0
  20. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +27 -0
  21. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +26 -0
  22. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +23 -0
  23. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +32 -0
  24. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +35 -2
  25. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +10 -0
  26. data/lib/ecoportal/api/v2/page/component/date_field.rb +21 -0
  27. data/lib/ecoportal/api/v2/page/component/files_field.rb +1 -2
  28. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +24 -1
  29. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +88 -0
  30. data/lib/ecoportal/api/v2/page/component/images_field.rb +11 -2
  31. data/lib/ecoportal/api/v2/page/component/people_field.rb +8 -1
  32. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +2 -0
  33. data/lib/ecoportal/api/v2/page/component/reference_field.rb +4 -0
  34. data/lib/ecoportal/api/v2/page/component/selection_field.rb +4 -5
  35. data/lib/ecoportal/api/v2/page/component/selection_option.rb +1 -0
  36. data/lib/ecoportal/api/v2/page/component/signature_field.rb +12 -1
  37. data/lib/ecoportal/api/v2/page/component/tag_field.rb +2 -0
  38. data/lib/ecoportal/api/v2/page/components.rb +2 -2
  39. data/lib/ecoportal/api/v2/page/section.rb +1 -0
  40. data/lib/ecoportal/api/v2/page/sections.rb +1 -1
  41. data/lib/ecoportal/api/v2/page/stages.rb +6 -0
  42. data/lib/ecoportal/api/v2/pages.rb +17 -15
  43. data/lib/ecoportal/api/v2/pages/page_stage.rb +6 -1
  44. data/lib/ecoportal/api/v2/pages/stages.rb +4 -1
  45. data/lib/ecoportal/api/v2/people.rb +31 -0
  46. data/lib/ecoportal/api/v2/registers.rb +60 -6
  47. data/lib/ecoportal/api/v2/registers/page_result.rb +21 -0
  48. data/lib/ecoportal/api/v2/registers/register.rb +37 -0
  49. data/lib/ecoportal/api/v2/registers/stage_result.rb +14 -0
  50. data/lib/ecoportal/api/v2/registers/stages_result.rb +13 -0
  51. data/lib/ecoportal/api/v2/registers/template.rb +12 -0
  52. data/lib/ecoportal/api/v2/version.rb +1 -1
  53. metadata +70 -36
  54. data/lib/ecoportal/api/v2/register.rb +0 -36
  55. data/lib/ecoportal/api/v2/template.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cb0d1b8ffc0213cf73870b6e1947fddf97633b2156c8f77199195041fda9656
4
- data.tar.gz: 0d59146cdd6ad87b710333c165ee5c2a704db9dafdfe89d4c056388bc6ed0394
3
+ metadata.gz: 5929f4395b13bbc49387e6df11b391d868533454b9c4e7a8a82059471dcc0c3e
4
+ data.tar.gz: 3dec1899afedfa10558c61cd24e3d2e2717bcaa2173284c960b93e1317ba74c8
5
5
  SHA512:
6
- metadata.gz: 760f145f8caaca3e50e9ec063f7876bcec24ab0427b4ba72307e026d83cd9510c4b8a91d263d06bdd60038d92b51ef350f52c53ba02c9bb45ba7d47a793656cf
7
- data.tar.gz: c3c42a6d60e77b23c8228f1d60320947a7884abae78e89439c8cfd721e9da5a39fe111b701f3549d07d13ffc2488defc3494b79ab44708ff59a511f669c0cd68
6
+ metadata.gz: 5ddfa85f7e4a424b421ef9f4163d7d3f97dc4f25c049bb04e8971472efb3fdc9857ba4b3d0cde701b09e8bb6add6bdb0c046be7e6609b8c6985e8fff36397c04
7
+ data.tar.gz: 99459754a151c61633212238c23d77cfc0fb3999ca5bf4fd5be6ee01219399f8d32fbc9b16b66fb84678fca4623edcaa1ebcd7d2a4a52b09f643111ab897f7c9
data/CHANGELOG.md CHANGED
@@ -1,7 +1,109 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.7.0] - 2020-07-xx
4
+ ## [0.7.5] - 2021-02-xx
5
+
6
+ ### Added
7
+ - `Ecoportal::API::Common::ClassHelpers` added inheritable attribute values
8
+ - `Ecoportal::API::V2::Pages::PageStage` added missing properties
9
+ - `Ecoportal::API::V2::Page::Stages#ordered_stages` method to obtain stages in order
10
+ - `Ecoportal::API::V2::Registers#search` method search pages in the register, which includes new classes:
11
+ - `Ecoportal::API::V2::Registers::PageResult`
12
+ - `Ecoportal::API::V2::Registers::StagesResult`
13
+ - `Ecoportal::API::V2::Registers::StageResult`
14
+ - `Ecoportal::API::V2::Pages#get` added parameter `stage_id:` to be able to directly obtain the stage
15
+
16
+ ### Changed
17
+ - Moved some classes to the new namespace `Ecoportal::API::V2::Registers`
18
+ - `Ecoportal::API::V2::Registers::Register`
19
+ - `Ecoportal::API::V2::Registers::Template`
20
+
21
+ ### Fixed
22
+ - `Ecoportal::API::Common::Content::HashDiffPatch`: `deleted` operation wording and `data.patch_ver`
23
+ - `Ecoportal::API::V2::Page::Component.new_doc` should delegate to child classes that have their own implementation
24
+ - `Ecoportal::API::V2::Page::Component::ImagesField.new_doc` should include `layout`
25
+ - `Ecoportal::API::V2::Page::Component::SignatureField.new_doc` should include `color`
26
+
27
+ ## [0.7.4] - 2021-02-12
28
+
29
+ ### Added
30
+ - `Ecoportal::API::V2::Page::Component::GaugeStop#color=` enabled setting colours using a `symbol`
31
+ - `:blue`, `:blue_greyed`, `:blue_light`
32
+ - `:turquoise`, `:jade`, `:green`, `:pistachio`, `:avocado`
33
+ - `:yellow`, `:orange`, `:pumpkin`, `:red`, `:magenta`, `:fuchsia`, `:purple`, `:violet`
34
+ - `Ecoportal::API::V2::Page::Component::GaugeStop#color_sym` to get the color as `symbol` name
35
+ - added support for chart fields:
36
+ - `Ecoportal::API::V2::Page::Component::ChartField` with the different `mode` types
37
+ - `Ecoportal::API::V2::Page::Component::ChartFrField` (LTIFR)
38
+
39
+ ### Changed
40
+ - `Ecoportal::API::Page::Component::DateField` Date objects + Timezones
41
+ - `#value` should be shown in local time
42
+ - `#value=` should be set by local time
43
+ - `Ecoportal::API::Common::Content::DoubleModel.embeds_multiple` renamed to `embeds_many`
44
+ - `Ecoportal::API::Common::Content::DoubleModel.embeds_one` removed parameter `:multiple`
45
+ - Fields under `Ecoportal::API::Page::Component` that `embeds_many` should generate new elements in a standard way
46
+ - added `Ecoportal::API::Common::Content::CollectionModel#items_class` method
47
+
48
+ ### Fixed
49
+ - solved `pretty_print` name collision renaming to `Ecoportal::API::Common::Content::DoubleModel#print_pretty`
50
+
51
+ ## [0.7.3] - 2021-02-01
52
+
53
+ ### Added
54
+ - `Ecoportal::API::Common::Content::CollectionModel#delete!` finally scoped how delete should work :)
55
+ - `Ecoportal::API::V2.new` better feedback on key error.
56
+ - `Ecoportal::API::V2::Page::Component::SignatureField` added property `signed_by_name`
57
+ - `Ecoportal::API::V2::Page::Component#required` this field property is currently supported
58
+ - `Ecoportal::API::V2::Page::Component::DateField` more supported properties:
59
+ * `show_time`, `today_button`, `past_only`, `create_event`, `remind_me_in`, `renews`, `renews_every`, `renews_unit`, `renews_until`
60
+ - `Ecoportal::API::V2::Page::Component::ChecklistField`
61
+ * added more methods: `add_item`, `ordered_items`
62
+ - `Ecoportal::API::V2::Page::Component::GaugeField`
63
+ * more supported properties: `max`, `active_color` and `stops`
64
+ - for `stops` added class `Ecoportal::API::V2::Page::Component::GaugeStop`
65
+ * added more methods: `add_stop`, `ordered_stops`
66
+ - `Ecoportal::API::V2::Page::Component::ReferenceField` more supported properties:
67
+ * `register_id`, `hide_create`, `hide_attach`, `hide_metadata`, `hide_dashboards`, `display_fields`, `display_fields_in_lookup`
68
+ - `Ecoportal::API::V2::Page::Component::ActionField`
69
+ * more supported properties:`create_actions`, `required_number_of_completed_actions`, `permits_and_rules_integration`, `add_subscribed`, `add_subscribed_to_tasks`
70
+ * added more methods: `add_task`, `ordered_tasks`
71
+ - `Ecoportal::API::V2::Page::Component::Action` modified, provided that some properties are `read_only`
72
+ - `Ecoportal::API::V2::Page::Component::PeopleField` more supported properties:
73
+ * `is_me_button`, `attach_mode`, `person_schema_id`, `viewable_fields`, `singular`, `requires_number`, `cached_people`, `attached_people_permissions_enabled`, `apply_attached_people_permissions_to`, `attached_people_permissions_editable`, `attached_people_permissions_flags`
74
+ - `Ecoportal::API::V2::Page::Component::PlainTextField` more supported properties:
75
+ * `multiline`, `max_length`, `exact_index`
76
+ - `Ecoportal::API::V2::Page::Component::SelectionField` more supported properties:
77
+ * `flat`
78
+ - `Ecoportal::API::V2::Page::Component::TagField` more supported properties:
79
+ * `single_select`, `use_defaults`, `tag_tree_id`, `button_text`
80
+ - `Ecoportal::API::V2::Page::Section` more supported properties:
81
+ * `minimized`
82
+
83
+ ### Changed
84
+ - upgraded `ecoportal-api` dependency
85
+
86
+ ### Fixed
87
+ - `Ecoportal::API::Common::Content::CollectionModel#upsert!` was not actually moving the element to the new position when it already existed
88
+
89
+ ## [0.7.2] - 2020-10-07
90
+
91
+ ### Added
92
+ - automatic key builder
93
+ - helper: `Ecoportal::API::V2::v2key` method
94
+ - `user_key:` and `org_key:` as constructor methods for `Ecoportal::API::V2`
95
+ ### Changed
96
+ ### Fixed
97
+
98
+ ## [0.7.1] - 2020-10-07
99
+
100
+ ### Added
101
+ ### Changed
102
+ - updated dependencies
103
+ ### Fixed
104
+
105
+
106
+ ## [0.7.0] - 2020-09-10
5
107
 
6
108
  ### Added
7
109
  ### Changed
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ **Moved to ---> 'ecoportal-api-v2'**
2
+
1
3
  # Ecoportal::API::V2
2
4
 
3
5
  This is a basic collection of helpers that can be used to interact with the
@@ -13,6 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://www.ecoportal.com"
14
14
  spec.licenses = %w[MIT]
15
15
 
16
+ spec.required_ruby_version = '>= 2.4.4'
17
+
16
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
19
  f.match(%r{^(test|spec|features)/})
18
20
  end
@@ -20,12 +22,17 @@ Gem::Specification.new do |spec|
20
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
23
  spec.require_paths = ["lib"]
22
24
 
23
- spec.add_development_dependency "bundler", "~> 2.1"
24
- spec.add_development_dependency "rake", "~> 12.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
27
- spec.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
25
+ spec.add_development_dependency "bundler", ">= 2.1.3", "< 2.2"
26
+ spec.add_development_dependency "rspec", ">= 3.9", "< 4"
27
+ spec.add_development_dependency "rake", ">= 12.3.0", "< 13"
28
+ spec.add_development_dependency "yard", ">= 0.9.18", "< 0.10"
29
+ spec.add_development_dependency "redcarpet", ">= 3.5.0", "< 3.6"
28
30
  spec.add_development_dependency "pry"
29
31
 
30
- spec.add_dependency 'ecoportal-api', '~> 0.7', '>= 0.6.0'
32
+ spec.add_dependency 'ecoportal-api', '>= 0.7.4', '< 0.8'
33
+
34
+ spec.post_install_message = %{
35
+ The 'ecoportal-api-oozes' gem has been deprecated and has been replaced by 'ecoportal-api-v2'.
36
+ See: https://rubygems.org/gems/ecoportal-api-v2
37
+ }
31
38
  end
@@ -104,6 +104,41 @@ module Ecoportal
104
104
  val != NOT_USED
105
105
  end
106
106
 
107
+ # Keeps track on class instance variables that should be inherited by child classes.
108
+ # @note
109
+ # - subclasses will inherit the value as is at that moment
110
+ # - any change afterwards will be only on the specific class (in line with class instance variables)
111
+ # - adapted from https://stackoverflow.com/a/10729812/4352306
112
+ # TODO: this separates the logic of the method to the instance var. Think if would be possible to join them somehow.
113
+ def inheritable_class_vars(*vars)
114
+ @inheritable_class_vars ||= [:inheritable_class_vars]
115
+ @inheritable_class_vars += vars
116
+ end
117
+
118
+ # Builds the attr_reader and attr_writer of `attrs` and registers the associated instance variable as inheritable.
119
+ def inheritable_attrs(*attrs)
120
+ attrs.each do |attr|
121
+ class_eval %(
122
+ class << self; attr_accessor :#{attr} end
123
+ )
124
+ end
125
+ inheritable_class_vars(*attrs)
126
+ end
127
+
128
+ # This callback method is called whenever a subclass of the current class is created.
129
+ # @note
130
+ # - values of the instance variables are copied as they are (no dups or clones)
131
+ # - the above means: avoid methods that change the state of the mutable object on it
132
+ # - mutating methods would reflect the changes on other classes as well
133
+ # - therefore, `freeze` will be called on the values that are inherited.
134
+ def inherited(subclass)
135
+ inheritable_class_vars.each do |var|
136
+ instance_var = instance_variable_name(var)
137
+ value = instance_variable_get(instance_var)
138
+ subclass.instance_variable_set(instance_var, value.freeze)
139
+ end
140
+ end
141
+
107
142
  end
108
143
  end
109
144
  end
@@ -101,6 +101,11 @@ module Ecoportal
101
101
  super(ini_doc, parent: parent, key: key)
102
102
  end
103
103
 
104
+ # @return [Class] the class of the elements of the Collection
105
+ def items_class
106
+ self.class.klass
107
+ end
108
+
104
109
  # Transforms `value` into the actual `key` to access the object in the doc `Array`
105
110
  def _doc_key(value)
106
111
  #print "*(#{value.class})"
@@ -134,6 +139,7 @@ module Ecoportal
134
139
  end
135
140
  end
136
141
 
142
+ # Get an element usign the `key`.
137
143
  def [](value)
138
144
  items_by_key[get_key(value)]
139
145
  end
@@ -161,6 +167,15 @@ module Ecoportal
161
167
  end
162
168
  end
163
169
 
170
+ def delete!(value)
171
+ unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel)
172
+ raise "'Content::DoubleModel' or 'Hash' doc required"
173
+ end
174
+ if item = self[value]
175
+ _doc_delete(item.doc)
176
+ end
177
+ end
178
+
164
179
  protected
165
180
 
166
181
  def order_matters?; self.class.order_matters; end
@@ -220,6 +235,13 @@ module Ecoportal
220
235
  super
221
236
  end
222
237
 
238
+ def _doc_delete(value)
239
+ if current_pos = _doc_key(value)
240
+ _doc_items.delete_at(current_pos)
241
+ on_change
242
+ end
243
+ end
244
+
223
245
  def _doc_upsert(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
224
246
  current_pos = _doc_key(value)
225
247
  pos = case
@@ -228,7 +250,7 @@ module Ecoportal
228
250
  when used_param?(before)
229
251
  _doc_key(before)
230
252
  when used_param?(after)
231
- puts "to add after #{after.id}"
253
+ #puts "to add after #{after.id}"
232
254
  if i = _doc_key(after)
233
255
  i + 1
234
256
  end
@@ -237,10 +259,10 @@ module Ecoportal
237
259
  pos ||= current_pos
238
260
 
239
261
  if current_pos && pos
240
- _doc_items.delete(current_pos)
262
+ _doc_items.delete_at(current_pos)
241
263
  pos = (pos <= current_pos)? pos : pos - 1
242
264
  end
243
-
265
+
244
266
  pos = (pos && pos < _doc_items.length)? pos : _doc_items.length
245
267
 
246
268
  pos.tap do |i|
@@ -131,7 +131,32 @@ module Ecoportal
131
131
  end
132
132
 
133
133
  # Helper to embed one nested object under one property
134
- def embeds_one(method, key: method, nullable: false, multiple: false, klass:)
134
+ def embeds_one(method, key: method, nullable: false, klass:)
135
+ embed(method, key: key, nullable: nullable, multiple: false, klass: klass)
136
+ end
137
+
138
+ # @note
139
+ # - if you have a dedicated `Enumerable` class to manage `many`, you should use `:enum_class`
140
+ # - otherwise, just indicate the child class in `:klass` and it will auto generate the class
141
+ # @param
142
+ def embeds_many(method, key: method, order_matters: false, order_key: nil, klass: nil, enum_class: nil)
143
+ if enum_class
144
+ eclass = enum_class
145
+ elsif klass
146
+ eclass = new_class(method, inherits: Common::Content::CollectionModel) do |dim_class|
147
+ dim_class.klass = klass
148
+ dim_class.order_matters = order_matters
149
+ dim_class.order_key = order_key
150
+ end
151
+ else
152
+ raise "You should either specify the 'klass' of the elements or the 'enum_class'"
153
+ end
154
+ embed(method, key: key, multiple: true, klass: eclass)
155
+ end
156
+
157
+ private
158
+
159
+ def embed(method, key: method, nullable: false, multiple: false, klass:)
135
160
  method = method.to_s.freeze
136
161
  var = instance_variable_name(method).freeze
137
162
  k = key.to_s.freeze
@@ -150,16 +175,6 @@ module Ecoportal
150
175
  end
151
176
  end
152
177
 
153
- def embeds_multiple(method, key: method, order_matters: false, order_key: nil, klass:)
154
- dim_class = new_class(method, inherits: Common::Content::CollectionModel) do |dklass|
155
- dklass.klass = klass
156
- dklass.order_matters = order_matters
157
- dklass.order_key = order_key
158
- end
159
-
160
- embeds_one(method, key: key, multiple: true, klass: dim_class)
161
- end
162
-
163
178
  end
164
179
 
165
180
  attr_reader :_parent, :_key
@@ -252,7 +267,7 @@ module Ecoportal
252
267
  end
253
268
  end
254
269
 
255
- def pretty_print
270
+ def print_pretty
256
271
  puts JSON.pretty_generate(as_json)
257
272
  self
258
273
  end
@@ -60,8 +60,13 @@ module Ecoportal
60
60
  a == b
61
61
  end
62
62
 
63
- def patch_data(a, b = nil)
63
+ def patch_data(a, b = nil, delete: false)
64
64
  {}.tap do |data_hash|
65
+ if delete
66
+ patch_ver = (a && a["patch_ver"]) || 1
67
+ data_hash["patch_ver"] = patch_ver
68
+ next
69
+ end
65
70
  a.each do |key, a_value|
66
71
  b_value = b[key] if b_has_key = b && b.key?(key)
67
72
  is_meta_key = META_KEYS.include?(key)
@@ -83,7 +88,8 @@ module Ecoportal
83
88
  return NO_CHANGES unless b.is_a?(Hash) && id = get_id(b, exception: false)
84
89
  {
85
90
  "id" => id,
86
- "operation" => "delete"
91
+ "operation" => "deleted",
92
+ "data" => patch_data(b, delete: true)
87
93
  }
88
94
  end
89
95
 
@@ -27,7 +27,7 @@ module Ecoportal
27
27
  def data
28
28
  return @data if instance_variable_defined?(:@data)
29
29
  @data = (response.body || {})["data"]
30
- @data = @data[key] if @key && @data
30
+ @data = @data[@key] if @key && @data
31
31
  @data
32
32
  end
33
33
 
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+
1
3
  module Ecoportal
2
4
  module API
3
5
  # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
@@ -8,25 +10,48 @@ module Ecoportal
8
10
 
9
11
  VERSION = "v2"
10
12
 
13
+ class << self
14
+ def v2key (ukey, gkey)
15
+ Base64.urlsafe_encode64({
16
+ organization: gkey,
17
+ user: ukey
18
+ }.to_json)
19
+ end
20
+ end
21
+
22
+ class_resolver :people_class, "Ecoportal::API::V2::People"
11
23
  class_resolver :registers_class, "Ecoportal::API::V2::Registers"
12
24
  class_resolver :pages_class, "Ecoportal::API::V2::Pages"
13
25
 
14
26
  attr_reader :client, :logger
15
27
 
16
28
  # Creates an `V2` object to scope version specific api requests.
29
+ # @note
30
+ # - You should use either `api_key` or `user_key` and `org_key`
31
+ # - The const `VERSION` determineds the api version that client will query against.
32
+ # - This means that each subclass of `V2` should define their own `VERSION` constant.
17
33
  # @param api_key [String] the key version to stablish the api connection.
34
+ # @param user_key [String] the user key used for the api connection (requires `org_key`).
35
+ # @param org_key [String] the org key used for the api connection (requires `user_key`).
18
36
  # @param host [String] api server domain.
19
37
  # @param logger [Logger] an object with `Logger` interface to generate logs.
20
- def initialize(api_key, host: "live.ecoportal.com", logger: default_logger)
38
+ def initialize(api_key = nil, user_key: nil, org_key: nil, host: "live.ecoportal.com", logger: default_logger)
39
+ v2key = get_key(api_key: api_key, user_key: user_key, org_key: org_key)
21
40
  @logger = logger
22
41
  @client = Common::Content::Client.new(
23
- api_key: api_key,
42
+ api_key: v2key,
24
43
  host: host,
25
44
  version: self.class::VERSION,
26
45
  logger: @logger
27
46
  )
28
47
  end
29
48
 
49
+ # Obtain specific object for people api requests.
50
+ # @return [People] an instance object ready to make people api requests.
51
+ def people
52
+ people_class.new(client)
53
+ end
54
+
30
55
  # Obtain specific object for schema api requests.
31
56
  # @return [Registers] an instance object ready to make registers api requests.
32
57
  def registers
@@ -39,9 +64,19 @@ module Ecoportal
39
64
  pages_class.new(client)
40
65
  end
41
66
 
67
+ private
68
+
69
+ def get_key(api_key: nil, user_key: nil, org_key: nil)
70
+ return self.class.v2key(user_key, org_key) if user_key && org_key
71
+ return api_key if api_key #|| ENV['X_ECOPORTAL_API_KEY']
72
+ raise "You need to provide either an api_key or user_key" unless user_key
73
+ raise "You need to provide an org_key as well (not just a user_key)" unless org_key
74
+ end
75
+
42
76
  end
43
77
  end
44
78
  end
45
79
 
46
- require 'ecoportal/api/v2/registers'
80
+ require 'ecoportal/api/v2/people'
47
81
  require 'ecoportal/api/v2/pages'
82
+ require 'ecoportal/api/v2/registers'