ecoportal-api-oozes 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ecoportal-api-oozes.gemspec +1 -1
- data/lib/ecoportal/api-oozes.rb +2 -2
- data/lib/ecoportal/api/common/content/array_model.rb +7 -0
- data/lib/ecoportal/api/common/content/collection_model.rb +7 -0
- data/lib/ecoportal/api/common/content/double_model.rb +18 -10
- data/lib/ecoportal/api/common/content/hash_diff_patch.rb +15 -5
- data/lib/ecoportal/api/v2.rb +0 -1
- data/lib/ecoportal/api/v2/page.rb +12 -0
- data/lib/ecoportal/api/v2/page/component/action_field.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/checklist_field.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/files_field.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/images_field.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/people_field.rb +5 -0
- data/lib/ecoportal/api/v2/page/component/selection_field.rb +27 -2
- data/lib/ecoportal/api/v2/page/components.rb +14 -0
- data/lib/ecoportal/api/v2/page/stages.rb +12 -0
- data/lib/ecoportal/api/v2/pages.rb +35 -7
- data/lib/ecoportal/api/v2/pages/page_stage.rb +11 -0
- data/lib/ecoportal/api/v2/pages/stages.rb +52 -0
- data/lib/ecoportal/api/v2/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b995a0d1c80408bc83f797ffe14f0bf8457d1e1be99eac780f3924c19d6efbe
|
4
|
+
data.tar.gz: f06fae1cf1aaf5fbcc7fdc102a3f78f55da137d3ab9c5f12a5852c6d74d99af3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2cf8d4e48892f6f31e6b852f8aeff840af65729d5d811596561f4841d77a2063a23d2dd0b111a67a1e8feafee12cf892c02fa4acab46e1b3a55af39554ab54e
|
7
|
+
data.tar.gz: 3fe6beb0b48d961544e227328eeb43676470feab25a0713987cab4d4a44d0ec52a52f8f512a27be183efdbd1de4ac8cdddccd929ddbe859f8e1169ee3107bb95
|
data/ecoportal-api-oozes.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "ecoportal/api/v2/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ecoportal-api-oozes"
|
8
|
-
spec.version = Ecoportal::API::V2::
|
8
|
+
spec.version = Ecoportal::API::V2::GEM_VERSION
|
9
9
|
spec.authors = ["Oscar Segura"]
|
10
10
|
spec.email = ["rien@ecoportal.co.nz", "oscar@ecoportal.co.nz", "bozydar@ecoportal.co.nz"]
|
11
11
|
|
data/lib/ecoportal/api-oozes.rb
CHANGED
@@ -30,6 +30,13 @@ module Ecoportal
|
|
30
30
|
(a.order_matters? == b.order_matters?) && (a.uniq? == b.uniq?)
|
31
31
|
end
|
32
32
|
|
33
|
+
# Creates a new object with `doc` where `original_doc` is `[]`
|
34
|
+
def create(doc)
|
35
|
+
self.new([]).tap do |page|
|
36
|
+
page.replace_doc(doc)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
33
40
|
end
|
34
41
|
|
35
42
|
def initialize(doc = {}, parent: self, key: nil)
|
@@ -153,6 +153,14 @@ module Ecoportal
|
|
153
153
|
|
154
154
|
embeds_one(method, key: key, multiple: true, klass: dim_class)
|
155
155
|
end
|
156
|
+
|
157
|
+
# Creates a new object with `doc` where `original_doc` is `{}`
|
158
|
+
def create(doc)
|
159
|
+
self.new({}).tap do |page|
|
160
|
+
page.replace_doc(doc)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
156
164
|
end
|
157
165
|
|
158
166
|
attr_reader :_parent, :_key
|
@@ -250,16 +258,6 @@ module Ecoportal
|
|
250
258
|
# self
|
251
259
|
#end
|
252
260
|
|
253
|
-
protected
|
254
|
-
|
255
|
-
def is_root?
|
256
|
-
_parent == self && !!defined?(@doc)
|
257
|
-
end
|
258
|
-
|
259
|
-
def linked?
|
260
|
-
is_root? || !!_parent.doc
|
261
|
-
end
|
262
|
-
|
263
261
|
def replace_doc(new_doc)
|
264
262
|
raise UnlinkedModel.new(from: "#{self.class}#replace_doc", key: _key) unless linked?
|
265
263
|
if is_root?
|
@@ -271,6 +269,16 @@ module Ecoportal
|
|
271
269
|
end
|
272
270
|
end
|
273
271
|
|
272
|
+
protected
|
273
|
+
|
274
|
+
def is_root?
|
275
|
+
_parent == self && !!defined?(@doc)
|
276
|
+
end
|
277
|
+
|
278
|
+
def linked?
|
279
|
+
is_root? || !!_parent.doc
|
280
|
+
end
|
281
|
+
|
274
282
|
def replace_original_doc(new_doc)
|
275
283
|
raise UnlinkedModel.new(from: "#{self.class}#replace_original_doc", key: _key) unless linked?
|
276
284
|
if is_root?
|
@@ -31,6 +31,8 @@ module Ecoportal
|
|
31
31
|
# 3. the `data` property holds the specific changes of the object
|
32
32
|
# - the `patch_ver` (compulsory) is **incremental** (for data integrity)
|
33
33
|
# - the properties that have changed
|
34
|
+
# @note
|
35
|
+
# * there should not be difference between `null` and `""` (empty string)
|
34
36
|
# @param a [Hash] current hash model
|
35
37
|
# @param b [Hash] previous hash model
|
36
38
|
# @return [Hash] a `patch data`
|
@@ -51,12 +53,19 @@ module Ecoportal
|
|
51
53
|
|
52
54
|
private
|
53
55
|
|
56
|
+
def equal_values(a, b)
|
57
|
+
if a.is_a?(String) || b.is_a?(String)
|
58
|
+
return true if a.to_s.strip.empty? && b.to_s.strip.empty?
|
59
|
+
end
|
60
|
+
a == b
|
61
|
+
end
|
62
|
+
|
54
63
|
def patch_data(a, b = nil)
|
55
64
|
{}.tap do |data_hash|
|
56
65
|
a.each do |key, a_value|
|
57
66
|
b_value = b[key] if b_has_key = b && b.key?(key)
|
58
67
|
is_meta_key = META_KEYS.include?(key)
|
59
|
-
skip_equals = b_has_key && a_value
|
68
|
+
skip_equals = b_has_key && equal_values(a_value, b_value)
|
60
69
|
next if is_meta_key || skip_equals
|
61
70
|
data_hash[key] = patch_diff(a_value, b_value)
|
62
71
|
data_hash.delete(key) if data_hash[key] == NO_CHANGES
|
@@ -106,7 +115,7 @@ module Ecoportal
|
|
106
115
|
else
|
107
116
|
a
|
108
117
|
end
|
109
|
-
else
|
118
|
+
else # array with nested elements
|
110
119
|
a_ids = array_ids(a)
|
111
120
|
b_ids = array_ids(b)
|
112
121
|
|
@@ -116,19 +125,20 @@ module Ecoportal
|
|
116
125
|
|
117
126
|
arr_delete = del_ids.map do |id|
|
118
127
|
patch_delete(array_id_item(b, id))
|
119
|
-
end
|
128
|
+
end.compact
|
120
129
|
|
121
130
|
arr_update = oth_ids.map do |id|
|
122
131
|
patch_update(array_id_item(a, id), array_id_item(b, id))
|
123
|
-
end
|
132
|
+
end.compact
|
124
133
|
|
125
134
|
arr_new = new_ids.map do |id|
|
126
135
|
patch_new(array_id_item(a, id))
|
127
|
-
end
|
136
|
+
end.compact
|
128
137
|
|
129
138
|
(arr_delete.concat(arr_update).concat(arr_new)).tap do |patch_array|
|
130
139
|
# remove data with no `id`
|
131
140
|
patch_array.reject! {|item| !item.is_a?(Hash)}
|
141
|
+
return NO_CHANGES if patch_array.empty?
|
132
142
|
end
|
133
143
|
end
|
134
144
|
end
|
data/lib/ecoportal/api/v2.rb
CHANGED
@@ -2,6 +2,7 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class V2
|
4
4
|
class Page < Common::Content::DoubleModel
|
5
|
+
ALLOWED_KEYS = %w[id patch_ver name template_id base_tags tags time_zone created_at updated_at can components sections stages]
|
5
6
|
passkey :id
|
6
7
|
passthrough :patch_ver
|
7
8
|
passthrough :name, :template_id
|
@@ -17,6 +18,17 @@ module Ecoportal
|
|
17
18
|
embeds_one :components, multiple: true, klass: :components_class
|
18
19
|
embeds_one :sections, multiple: true, klass: :sections_class
|
19
20
|
embeds_one :stages, multiple: true, klass: :stages_class
|
21
|
+
|
22
|
+
def as_update
|
23
|
+
super.tap do |hash|
|
24
|
+
unless !hash
|
25
|
+
hash["data"].select! do |key, value|
|
26
|
+
ALLOWED_KEYS.include?(key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
@@ -4,8 +4,8 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Component
|
6
6
|
class ActionField < Page::Component
|
7
|
-
class_resolver :action_class, "Ecoportal::API::V2::Page::Component::Action"
|
8
|
-
embeds_multiple :actions, klass:
|
7
|
+
#class_resolver :action_class, "Ecoportal::API::V2::Page::Component::Action"
|
8
|
+
embeds_multiple :actions, klass: "Ecoportal::API::V2::Page::Component::Action", order_key: :weight
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Component
|
6
6
|
class ChecklistField < Page::Component
|
7
|
-
class_resolver :checklist_item_class, "Ecoportal::API::V2::Page::Component::ChecklistItem"
|
8
|
-
embeds_multiple :items, klass:
|
7
|
+
#class_resolver :checklist_item_class, "Ecoportal::API::V2::Page::Component::ChecklistItem"
|
8
|
+
embeds_multiple :items, klass: "Ecoportal::API::V2::Page::Component::ChecklistItem", order_key: :weight
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Component
|
6
6
|
class FilesField < Page::Component
|
7
|
-
class_resolver :file_class, "Ecoportal::API::V2::Page::File"
|
8
|
-
embeds_multiple :items, klass:
|
7
|
+
#class_resolver :file_class, "Ecoportal::API::V2::Page::File"
|
8
|
+
embeds_multiple :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Component
|
6
6
|
class ImagesField < Page::Component
|
7
|
-
class_resolver :image_class, "Ecoportal::API::V2::Page::Image"
|
8
|
-
embeds_multiple :images, klass:
|
7
|
+
#class_resolver :image_class, "Ecoportal::API::V2::Page::Image"
|
8
|
+
embeds_multiple :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -6,8 +6,33 @@ module Ecoportal
|
|
6
6
|
class SelectionField < Page::Component
|
7
7
|
passthrough :multiple, :other, :other_desc
|
8
8
|
|
9
|
-
class_resolver :selection_option_class, "Ecoportal::API::V2::Page::Component::SelectionOption"
|
10
|
-
embeds_multiple :options, klass:
|
9
|
+
#class_resolver :selection_option_class, "Ecoportal::API::V2::Page::Component::SelectionOption"
|
10
|
+
embeds_multiple :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
|
11
|
+
|
12
|
+
def select(value)
|
13
|
+
opt = options.find {|opt| opt.value == value}
|
14
|
+
sel = selected
|
15
|
+
return true if !multiple && opt == sel
|
16
|
+
sel.selected = false if !multiple && sel
|
17
|
+
opt.selected = true unless !opt
|
18
|
+
end
|
19
|
+
|
20
|
+
def selected
|
21
|
+
if multiple
|
22
|
+
options.select {|opt| opt.selected}
|
23
|
+
else
|
24
|
+
options.find {|opt| opt.selected}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def value
|
29
|
+
if multiple
|
30
|
+
selected.map {|opt| opt.value}
|
31
|
+
else
|
32
|
+
selected&.value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
11
36
|
end
|
12
37
|
end
|
13
38
|
end
|
@@ -13,6 +13,20 @@ module Ecoportal
|
|
13
13
|
|
14
14
|
order_matters = true
|
15
15
|
|
16
|
+
def get_by_type(type)
|
17
|
+
self.select do |comp|
|
18
|
+
comp.type.downcase == type.to_s.strip.downcase
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_by_name(name, type: nil)
|
23
|
+
pool = type ? get_by_type(type) : self
|
24
|
+
|
25
|
+
pool.select do |comp|
|
26
|
+
comp.label.to_s.strip.downcase == name.to_s.strip.downcase
|
27
|
+
end.first
|
28
|
+
end
|
29
|
+
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
@@ -7,6 +7,18 @@ module Ecoportal
|
|
7
7
|
|
8
8
|
self.klass = :stage_class
|
9
9
|
|
10
|
+
def get_by_name(name)
|
11
|
+
find do |stage|
|
12
|
+
stage.name.strip.downcase == name.to_s.strip.downcase
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def sections
|
17
|
+
section_ids.map do |id|
|
18
|
+
root.sections.find {|sec| sec.id == id}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
end
|
11
23
|
end
|
12
24
|
end
|
@@ -3,9 +3,11 @@ module Ecoportal
|
|
3
3
|
class V2
|
4
4
|
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
5
5
|
class Pages
|
6
|
+
STAGE_REX = /stages\/(?<sid>.*)/
|
6
7
|
extend Common::BaseClass
|
7
8
|
include Common::Content::DocHelpers
|
8
9
|
|
10
|
+
class_resolver :stages_class, "Ecoportal::API::V2::Pages::Stages"
|
9
11
|
class_resolver :page_class, "Ecoportal::API::V2::Page"
|
10
12
|
|
11
13
|
attr_reader :client
|
@@ -16,14 +18,30 @@ module Ecoportal
|
|
16
18
|
@client = client
|
17
19
|
end
|
18
20
|
|
21
|
+
# Obtain specific object for pages api requests.
|
22
|
+
# @return [V2::Pages::Stages] an instance object ready to make pages api requests.
|
23
|
+
def stages
|
24
|
+
stages_class.new(client)
|
25
|
+
end
|
26
|
+
|
19
27
|
# Gets a page via api.
|
20
|
-
# @note
|
28
|
+
# @note
|
29
|
+
# - if the request has `success?` the returned `object.result` gives an object with that `Page`.
|
30
|
+
# - if it failed to obtain the full page, it returns a `PageStage` with the active stage data.
|
21
31
|
# @param doc [String, Hash, Page] data containing an `id` of the target page.
|
22
|
-
# @return [Ecoportal::API::V2::Page] the target page.
|
32
|
+
# @return [Ecoportal::API::V2::Page, Ecoportal::API::V2::Pages::PageStage] the target page.
|
23
33
|
def get(doc)
|
24
|
-
|
25
|
-
response = client.get("/pages/#{CGI.escape(
|
26
|
-
Common::Content::WrappedResponse.new(response, page_class)
|
34
|
+
pid = get_id(doc)
|
35
|
+
response = client.get("/pages/#{CGI.escape(pid)}")
|
36
|
+
wrapped = Common::Content::WrappedResponse.new(response, page_class)
|
37
|
+
|
38
|
+
return wrapped.result if wrapped.success?
|
39
|
+
if (response.status == 302) && (url = response.body["data"])
|
40
|
+
if sid = url_to_stage_id(url)
|
41
|
+
return stages.get(pid: pid, sid: sid)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
raise "Could not get page #{id} - Error #{response.status}: #{response.body}"
|
27
45
|
end
|
28
46
|
|
29
47
|
# Gets a `new` non-existing page via api with all the ids initialized.
|
@@ -32,8 +50,11 @@ module Ecoportal
|
|
32
50
|
def get_new(from)
|
33
51
|
id = get_id(from)
|
34
52
|
response = client.get("/pages/new", params: {template_id: id})
|
35
|
-
|
36
|
-
|
53
|
+
wrapped = Common::Content::WrappedResponse.new(response, page_class)
|
54
|
+
|
55
|
+
return wrapped.result if wrapped.success?
|
56
|
+
#return page_class.create(response.body["data"]) if response.success?
|
57
|
+
raise "Could not get new page from template #{id} - Error #{response.status}: #{response.body}"
|
37
58
|
end
|
38
59
|
|
39
60
|
# Requests a creation of a page via api.
|
@@ -55,9 +76,16 @@ module Ecoportal
|
|
55
76
|
client.patch("/pages/#{CGI.escape(id)}", data: body)
|
56
77
|
end
|
57
78
|
|
79
|
+
private
|
80
|
+
|
81
|
+
def url_to_stage_id(url)
|
82
|
+
(matches = url.match(STAGE_REX)) && matches[:sid]
|
83
|
+
end
|
84
|
+
|
58
85
|
end
|
59
86
|
end
|
60
87
|
end
|
61
88
|
end
|
62
89
|
|
63
90
|
require 'ecoportal/api/v2/page'
|
91
|
+
require 'ecoportal/api/v2/pages/stages'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
class Pages
|
5
|
+
# This API Integration level has been added due to relative permissions
|
6
|
+
# - a **user** with api access may have access to a specific `stage` but not to the full `page`
|
7
|
+
#
|
8
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
9
|
+
class Stages
|
10
|
+
extend Common::BaseClass
|
11
|
+
include Common::Content::DocHelpers
|
12
|
+
|
13
|
+
class_resolver :page_stage_class, "Ecoportal::API::V2::Pages::PageStage"
|
14
|
+
|
15
|
+
attr_reader :client
|
16
|
+
|
17
|
+
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
18
|
+
# @return [Schemas] an instance object ready to make schema api requests.
|
19
|
+
def initialize(client)
|
20
|
+
@client = client
|
21
|
+
end
|
22
|
+
|
23
|
+
# Gets a stage via api.
|
24
|
+
# @note if the request has `success?` the returned `object.result` gives an object with that `Stage`.
|
25
|
+
# @param doc [String, Hash, Stage] data containing an `id` of the target page.
|
26
|
+
# @return [Ecoportal::API::V2::Stage, Ecoportal::API::V2::Pages::PageStage] the target stage.
|
27
|
+
def get(pid:, sid:)
|
28
|
+
pid = get_id(pid)
|
29
|
+
response = client.get("/pages/#{CGI.escape(pid)}/stages/#{CGI.escape(sid)}/")
|
30
|
+
wrapped = Common::Content::WrappedResponse.new(response, page_stage_class)
|
31
|
+
|
32
|
+
return wrapped.result if wrapped.success?
|
33
|
+
raise "Could not get stage {#{sid}} of page #{pid} - Error #{response.status}: #{response.body}"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Requests to update an existing stage via api.
|
37
|
+
# @param doc [Hash, Stage] data that at least contains an `id` (internal or external) of the target stage.
|
38
|
+
# @return [Response] an object with the api response.
|
39
|
+
def update(doc, pid: nil, sid:)
|
40
|
+
body = get_body(doc)
|
41
|
+
pid = pid || get_id(doc)
|
42
|
+
path = "/pages/#{CGI.escape(pid)}/stages/#{CGI.escape(sid)}/"
|
43
|
+
client.patch(path, data: body)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'ecoportal/api/v2/pages/page_stage'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api-oozes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -189,6 +189,8 @@ files:
|
|
189
189
|
- lib/ecoportal/api/v2/page/stage.rb
|
190
190
|
- lib/ecoportal/api/v2/page/stages.rb
|
191
191
|
- lib/ecoportal/api/v2/pages.rb
|
192
|
+
- lib/ecoportal/api/v2/pages/page_stage.rb
|
193
|
+
- lib/ecoportal/api/v2/pages/stages.rb
|
192
194
|
- lib/ecoportal/api/v2/register.rb
|
193
195
|
- lib/ecoportal/api/v2/registers.rb
|
194
196
|
- lib/ecoportal/api/v2/template.rb
|