ecoportal-api-oozes 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +55 -0
  5. data/.travis.yml +5 -0
  6. data/.yardopts +10 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE +21 -0
  9. data/README.md +20 -0
  10. data/Rakefile +27 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/ecoportal-api-oozes.gemspec +31 -0
  14. data/lib/ecoportal/api-oozes.rb +10 -0
  15. data/lib/ecoportal/api/common.rb +18 -0
  16. data/lib/ecoportal/api/common/content.rb +18 -0
  17. data/lib/ecoportal/api/common/content/array_model.rb +287 -0
  18. data/lib/ecoportal/api/common/content/class_helpers.rb +111 -0
  19. data/lib/ecoportal/api/common/content/client.rb +40 -0
  20. data/lib/ecoportal/api/common/content/collection_model.rb +223 -0
  21. data/lib/ecoportal/api/common/content/doc_helpers.rb +67 -0
  22. data/lib/ecoportal/api/common/content/double_model.rb +334 -0
  23. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +162 -0
  24. data/lib/ecoportal/api/common/content/string_digest.rb +22 -0
  25. data/lib/ecoportal/api/common/content/wrapped_response.rb +42 -0
  26. data/lib/ecoportal/api/v2.rb +48 -0
  27. data/lib/ecoportal/api/v2/page.rb +30 -0
  28. data/lib/ecoportal/api/v2/page/component.rb +105 -0
  29. data/lib/ecoportal/api/v2/page/component/action.rb +17 -0
  30. data/lib/ecoportal/api/v2/page/component/action_field.rb +16 -0
  31. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +16 -0
  32. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +15 -0
  33. data/lib/ecoportal/api/v2/page/component/date_field.rb +13 -0
  34. data/lib/ecoportal/api/v2/page/component/file.rb +16 -0
  35. data/lib/ecoportal/api/v2/page/component/files_field.rb +14 -0
  36. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +13 -0
  37. data/lib/ecoportal/api/v2/page/component/geo_field.rb +13 -0
  38. data/lib/ecoportal/api/v2/page/component/image.rb +16 -0
  39. data/lib/ecoportal/api/v2/page/component/images_field.rb +14 -0
  40. data/lib/ecoportal/api/v2/page/component/law_field.rb +12 -0
  41. data/lib/ecoportal/api/v2/page/component/number_field.rb +12 -0
  42. data/lib/ecoportal/api/v2/page/component/people_field.rb +13 -0
  43. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +13 -0
  44. data/lib/ecoportal/api/v2/page/component/reference_field.rb +12 -0
  45. data/lib/ecoportal/api/v2/page/component/rich_text_field.rb +13 -0
  46. data/lib/ecoportal/api/v2/page/component/selection_field.rb +18 -0
  47. data/lib/ecoportal/api/v2/page/component/selection_option.rb +15 -0
  48. data/lib/ecoportal/api/v2/page/component/signature_field.rb +14 -0
  49. data/lib/ecoportal/api/v2/page/component/tag_field.rb +12 -0
  50. data/lib/ecoportal/api/v2/page/components.rb +20 -0
  51. data/lib/ecoportal/api/v2/page/section.rb +36 -0
  52. data/lib/ecoportal/api/v2/page/sections.rb +14 -0
  53. data/lib/ecoportal/api/v2/page/stage.rb +16 -0
  54. data/lib/ecoportal/api/v2/page/stages.rb +14 -0
  55. data/lib/ecoportal/api/v2/pages.rb +63 -0
  56. data/lib/ecoportal/api/v2/register.rb +36 -0
  57. data/lib/ecoportal/api/v2/registers.rb +35 -0
  58. data/lib/ecoportal/api/v2/template.rb +10 -0
  59. data/lib/ecoportal/api/v2/version.rb +7 -0
  60. metadata +219 -0
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChecklistField < Page::Component
7
+ class_resolver :checklist_item_class, "Ecoportal::API::V2::Page::Component::ChecklistItem"
8
+ embeds_multiple :items, klass: :checklist_item_class, order_key: :weight
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'ecoportal/api/v2/page/component/checklist_item'
@@ -0,0 +1,15 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChecklistItem < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :patch_ver, :label
9
+ passthrough :weight, :checked
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class DateField < Page::Component
7
+ passthrough :value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class File < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :patch_ver, :position
9
+ passthrough :content_type, :file_size, :file_container_id
10
+ passdate :file_update_at
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class FilesField < Page::Component
7
+ class_resolver :file_class, "Ecoportal::API::V2::Page::File"
8
+ embeds_multiple :items, klass: :file_class, order_key: :position
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class GaugeField < Page::Component
7
+ passthrough :value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class GeoField < Page::Component
7
+ passthrough :address, :coordinates
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class Image < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :patch_ver, :weight
9
+ passthrough :height, :width, :caption
10
+ passthrough :dimensions, :styles
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ImagesField < Page::Component
7
+ class_resolver :image_class, "Ecoportal::API::V2::Page::Image"
8
+ embeds_multiple :images, klass: :image_class, order_key: :weight
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class LawField < Page::Component
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class NumberField < Page::Component
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class PeopleField < Page::Component
7
+ passarray :people_ids
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class PlainTextField < Page::Component
7
+ passthrough :value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ReferenceField < Page::Component
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class RichTextField < Page::Component
7
+ passthrough :content
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class SelectionField < Page::Component
7
+ passthrough :multiple, :other, :other_desc
8
+
9
+ class_resolver :selection_option_class, "Ecoportal::API::V2::Page::Component::SelectionOption"
10
+ embeds_multiple :options, klass: :selection_option_class, order_key: :weight
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ require 'ecoportal/api/v2/page/component/selection_option'
@@ -0,0 +1,15 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class SelectionOption < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :patch_ver, :name, :value
9
+ passthrough :weight, :selected
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class SignatureField < Page::Component
7
+ passthrough :signed_by_id, :signature_url
8
+ passdate :signature_updated_at
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class TagField < Page::Component
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Components < Common::Content::CollectionModel
6
+ class_resolver :component_class, "Ecoportal::API::V2::Page::Component"
7
+
8
+ self.klass do |doc|
9
+ component_class.get_class(doc).tap do |klass|
10
+ klass.key = :id
11
+ end
12
+ end
13
+
14
+ order_matters = true
15
+
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Section < Common::Content::DoubleModel
6
+ passkey :id
7
+ passthrough :patch_ver, :weight, :type
8
+ passthrough :heading, :left_heading, :right_heading
9
+ passarray :component_ids, :left_component_ids, :right_component_ids
10
+
11
+ def split?
12
+ doc && doc["type"] == "split"
13
+ end
14
+
15
+ def all_component_ids
16
+ return component_ids.to_a unless split?
17
+ left_component_ids.to_a | right_component_ids.to_a
18
+ end
19
+
20
+ def component?(id)
21
+ all_component_ids.include?(id)
22
+ end
23
+
24
+ def components
25
+ sec_ids = all_component_ids
26
+ root.components.values_at(*sec_ids).select.with_index do |fld, i|
27
+ puts "Warning: section #{id} points to missing field #{sec_ids[i]}" if !fld
28
+ fld && (!block_given? || yield(fld))
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Sections < Common::Content::CollectionModel
6
+ class_resolver :section_class, "Ecoportal::API::V2::Page::Section"
7
+
8
+ self.klass = :section_class
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Stage < Common::Content::DoubleModel
6
+ passkey :id
7
+ passthrough :patch_ver
8
+ passthrough :name
9
+ passarray :subtags, order_matters: false
10
+ passarray :section_ids
11
+ passthrough :can
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Stages < Common::Content::CollectionModel
6
+ class_resolver :stage_class, "Ecoportal::API::V2::Page::Stage"
7
+
8
+ self.klass = :stage_class
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,63 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
5
+ class Pages
6
+ extend Common::BaseClass
7
+ include Common::Content::DocHelpers
8
+
9
+ class_resolver :page_class, "Ecoportal::API::V2::Page"
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 a page via api.
20
+ # @note if the request has `success?` the returned `object.result` gives an object with that `Page`.
21
+ # @param doc [String, Hash, Page] data containing an `id` of the target page.
22
+ # @return [Ecoportal::API::V2::Page] the target page.
23
+ def get(doc)
24
+ id = get_id(doc)
25
+ response = client.get("/pages/#{CGI.escape(id)}")
26
+ Common::Content::WrappedResponse.new(response, page_class).result
27
+ end
28
+
29
+ # Gets a `new` non-existing page via api with all the ids initialized.
30
+ # @param from [String, Hash, Page] template or `id` of the template
31
+ # @return [Ecoportal::API::V2::Page] the new page object.
32
+ def get_new(from)
33
+ id = get_id(from)
34
+ response = client.get("/pages/new", params: {template_id: id})
35
+ # TODO: make it so the obtained `doc` can be used as `doc`, yet `source_doc` to be empty {}
36
+ #Common::Content::WrappedResponse.new(response, page_class).result
37
+ end
38
+
39
+ # Requests a creation of a page via api.
40
+ # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
41
+ # @param from [String, Hash, Page] template or `id` of the template
42
+ # @return [Response] an object with the api response.
43
+ def create(doc, from:)
44
+ body = get_body(doc)
45
+ id = get_id(from)
46
+ client.post("/pages", data: body, params: {template_id: id})
47
+ end
48
+
49
+ # Requests to update an existing page via api.
50
+ # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
51
+ # @return [Response] an object with the api response.
52
+ def update(doc)
53
+ body = get_body(doc) # , level: "page"
54
+ id = get_id(doc)
55
+ client.patch("/pages/#{CGI.escape(id)}", data: body)
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ require 'ecoportal/api/v2/page'