ecoportal-api-graphql 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c0e5dcda795491dd4687054d51f9b3888f707f320ed079742c54cbde74464ad
4
- data.tar.gz: ab434f8f1f410692b0ac8f4a3cd549293045e17e469b2b09a14c1fbe85123f06
3
+ metadata.gz: 2e84ebd7d21833d62b3d0723997bf8cddc8ab5bf69a53197113f25062d041580
4
+ data.tar.gz: 47e7b4ac0468a82b5548942ee8381fb07e58a60a1adbae7c219aa7259617af6f
5
5
  SHA512:
6
- metadata.gz: f3d127b631c0c567cd7831d5e1cda50f5474e1d4c262716e000aa324045b2fc228452ed2d968b620b9b58c43000b4526af5d2916e525b81af2c12999e23a00bd
7
- data.tar.gz: 5c86f610a220829e975bef5ff3e459801247a7cda07368dafc2fc2278b81aed8f2535b187b6ee8682d61bc15bfb23ea84c048dac6df48c219d6f4ccb5fff84bd
6
+ metadata.gz: a8eb13e8e3f8a6880cc1b4fd6f7e734d0b163f0eaba42fbc503e297e1e76833420b37f05dc598865aca43553109d6bc4316df1c8a504b41667f8c0fabacaa6b7
7
+ data.tar.gz: d5931f5c1c5eba0102dae8da2745ce415159a861f61259e850978bf1fe38b4f342494553701d0521bcf353a2172266ec8c77b826fccac560ccd0490fe0d35806
data/CHANGELOG.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.1.7] - 2022-09-xx
4
+ ## [0.1.8] - 2022-09-xx
5
5
 
6
6
  ### Added
7
- ### Changed
7
+ ### Changed
8
8
  ### Fixed
9
9
 
10
10
  ### ToDo
@@ -14,6 +14,17 @@ All notable changes to this project will be documented in this file.
14
14
  - Analyse how to "DSL" currentOrganization.action.activities
15
15
  - review `path` tracking
16
16
 
17
+ ## [0.1.7] - 2022-09-23
18
+
19
+ ### Added
20
+ - `currentOrganization.tagTrees` query
21
+
22
+ ### Changed
23
+ - **upgraded** `ecoportal-api-v2` gem dependency
24
+ - Restructured the `Query` inheritance chain to make things simpler
25
+
26
+ ### Fixed
27
+
17
28
  ## [0.1.6] - 2022-09-19
18
29
 
19
30
  ### Fixed
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
30
30
  spec.add_development_dependency "pry" , ">= 0.14"
31
31
 
32
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.31', '< 0.9'
32
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.33', '< 0.9'
33
33
  spec.add_dependency 'graphlient', '>= 0.6.0', '< 0.7'
34
34
  end
@@ -27,15 +27,41 @@ module Ecoportal
27
27
  def slice_params(kargs)
28
28
  kargs.slice(*accepted_params)
29
29
  end
30
+
31
+ # Used to obtain the full `path` in the GraphQL query by using `base_path`
32
+ # @note it is meant for reusability of queries from different end-points
33
+ def field_name(str = nil)
34
+ return @field_name unless str
35
+ @field_name = nil
36
+ @field_name = str.to_s if str
37
+ end
30
38
  end
31
39
 
32
40
  class_resolver :item_class, GenericItem
33
41
  attr_reader :client
34
42
 
35
- def initialize(client)
43
+ attr_reader :base_path
44
+
45
+ def initialize(client, path: nil, base_path: nil)
46
+ @path = path
47
+ @base_path = base_path
36
48
  @client = client
37
49
  end
38
50
 
51
+ # Resolves the `path` by using `path` or `base_path` + `class.field_name`.
52
+ def path(field_name = self.class.field_name)
53
+ result = @path
54
+ result ||= default_path if self.respond_to?(:default_path, true)
55
+ result ||= (base_path + [field_name]) if base_path && field_name
56
+ result
57
+ end
58
+
59
+ # Query rely that manages the different blocks.
60
+ # @return [Class] an object of `response_class` with the results hanving from `path`.
61
+ def query(path: self.path, **kargs, &block)
62
+ graphql_query(path: path, **kargs, &basic_block(&block))
63
+ end
64
+
39
65
  def response_class
40
66
  item_class
41
67
  end
@@ -44,6 +70,19 @@ module Ecoportal
44
70
  path.last
45
71
  end
46
72
 
73
+ private
74
+
75
+ def graphql_query(path: self.path, **kargs, &block)
76
+ query_params = self.class.slice_params(kargs)
77
+ request(*path) do
78
+ client.query(query_params, &block)
79
+ end
80
+ rescue Faraday::ParsingError => e
81
+ puts "Internal Error with these params:"
82
+ pp kargs
83
+ raise
84
+ end
85
+
47
86
  def request(*path)
48
87
  response = yield
49
88
  wrap_response(response, path)
@@ -0,0 +1,35 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Base
5
+ class QueryArray < Ecoportal::API::GraphQL::Base::Query
6
+ include Enumerable
7
+
8
+ def each(item_block: nil, **kargs, &block)
9
+ return to_enum(:each, **kargs, item_block: connection_block) unless block
10
+ query(**kargs, &item_block).each do |item|
11
+ yield(item) if block_given?
12
+ end
13
+ end
14
+
15
+ def response_class
16
+ return array_class if respond_to?(:array_class)
17
+ @response_class ||= self.class.new_class(
18
+ item_class,
19
+ inherits: Ecoportal::API::Common::Content::CollectionModel
20
+ ) do |klass|
21
+ puts "created class #{klass}: item_class: #{item_class}"
22
+ klass.klass = item_class
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def basic_block
29
+ raise "Missuse. You have to implement 'basic_block' private method in the child class"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -6,29 +6,6 @@ module Ecoportal
6
6
  accepted_params :searchConf, :after, :before, :first, :last
7
7
  include Enumerable
8
8
 
9
- attr_reader :path
10
-
11
- def initialize(*args, path: default_base_path, **kargs)
12
- @path = path
13
- super(*args, **kargs)
14
- end
15
-
16
- def query(path: default_base_path, **kargs, &block)
17
- path ||= default_base_path
18
- kargs = self.class.slice_params(kargs)
19
- ap = access_point(path)
20
- raise "Missuse. You have to implement this method in the child class"
21
- end
22
-
23
- def graphql_query(**kargs, &block)
24
- query_params = self.class.slice_params(kargs)
25
- client.query(query_params, &block)
26
- rescue Faraday::ParsingError => e
27
- puts "Internal Error with these params:"
28
- pp kargs
29
- raise
30
- end
31
-
32
9
  def each(connection_block: nil, **kargs, &block)
33
10
  return to_enum(:each, **kargs, connection_block: connection_block) unless block
34
11
  cursor = nil; results = 0
@@ -51,13 +28,9 @@ module Ecoportal
51
28
  inherits: Ecoportal::API::GraphQL::Base::Connection,
52
29
  namespace: "Ecoportal::API::GraphQL::Connection"
53
30
  ) do |klass|
54
- klass.item_class = item_class
31
+ klass.item_class = item_class
55
32
  end
56
33
  end
57
-
58
- def default_base_path
59
- ["currentOrganization"]
60
- end
61
34
  end
62
35
  end
63
36
  end
@@ -0,0 +1,20 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Base
5
+ class TagTree < Ecoportal::API::GraphQL::Base::Model
6
+ extend Ecoportal::API::GraphQL::Helpers::TagTree
7
+
8
+ passkey :id
9
+ passthrough :name
10
+ passboolean :visitorManagementEnabled
11
+ embeds_many :nodes, klass: Ecoportal::API::GraphQL::Base::TagTreeNode, order_key: :weight
12
+
13
+ def treeify
14
+ self.class.treeify(nodes)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Base
5
+ class TagTreeNode < Ecoportal::API::GraphQL::Base::Model
6
+ passkey :id
7
+ passthrough :tag, :parent, :parentId
8
+ passboolean :enabledLocationCode
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,9 +13,12 @@ require 'ecoportal/api/graphql/base/id_diff_input'
13
13
  require 'ecoportal/api/graphql/base/page_info'
14
14
  require 'ecoportal/api/graphql/base/query'
15
15
  require 'ecoportal/api/graphql/base/connection'
16
+ require 'ecoportal/api/graphql/base/query_array'
16
17
  require 'ecoportal/api/graphql/base/query_connection'
17
18
  require 'ecoportal/api/graphql/base/validation_errors'
18
19
  require 'ecoportal/api/graphql/base/payload'
20
+ require 'ecoportal/api/graphql/base/tag_tree_node'
21
+ require 'ecoportal/api/graphql/base/tag_tree'
19
22
  require 'ecoportal/api/graphql/base/person_member'
20
23
  require 'ecoportal/api/graphql/base/file_attachment'
21
24
  require 'ecoportal/api/graphql/base/file_container'
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ class Fragment
5
+ fragment :TagTreeNode, <<~'GRAPHQL'
6
+ fragment on TagTreeNode {
7
+ id
8
+ parentId
9
+ tag
10
+ weight
11
+ }
12
+ GRAPHQL
13
+ end
14
+ end
15
+ end
16
+ end
@@ -47,5 +47,6 @@ module Ecoportal
47
47
  end
48
48
 
49
49
  require 'ecoportal/api/graphql/fragment/pagination'
50
+ require 'ecoportal/api/graphql/fragment/tag_tree_node'
50
51
  require 'ecoportal/api/graphql/fragment/action'
51
52
  require 'ecoportal/api/graphql/fragment/contractor_entity'
@@ -0,0 +1,27 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Helpers
5
+ module TagTree
6
+ def treeify(nodes)
7
+ parents = nodes.each_with_object({}) do |node, parents|
8
+ (parents[node.parentId] ||= []).push(node)
9
+ end
10
+ get_children(nil, parents)
11
+ end
12
+
13
+ private
14
+
15
+ def get_children(node_id, parents)
16
+ (parents[node_id] ||= []).each_with_object([]) do |child, results|
17
+ results << {
18
+ "tag" => child.tag,
19
+ "nodes" => get_children(child.id, parents).compact
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Helpers
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ecoportal/api/graphql/helpers/tag_tree'
@@ -3,41 +3,64 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Model
5
5
  class Organization < Ecoportal::API::GraphQL::Base::Organization
6
+ DEFAULT_PATH = ["currentOrganization"]
7
+
6
8
  class << self
7
- #userGroup, userGroups,
8
- #tagTree, tagTrees,
9
+ def path(*add)
10
+ DEFAULT_PATH.dup.push(*add)
11
+ end
12
+
13
+ #userGroup, userGroups
14
+
15
+ # @return [Collection::TagTree, Query::TagTrees]
16
+ def tagTrees(**kargs, &block)
17
+ if kargs.empty? && !block_given?
18
+ tagTreesQuery
19
+ else
20
+ tagTreesQuery.query(**kargs, &block)
21
+ end
22
+ end
23
+
24
+ #tagTree
25
+
9
26
  #register, registers
10
27
  #personMembers, attachablePersonMembers
11
28
  #contractorEntity,
12
29
 
13
30
  # @return [Connection::ContractorEntity, Query::ContractorEntities]
14
31
  def contractorEntities(**kargs, &block)
15
- if kargs.empty?
32
+ if kargs.empty? && !block_given?
16
33
  contractorEntitiesQuery
17
34
  else
18
35
  contractorEntitiesQuery.query(**kargs, &block)
19
36
  end
20
37
  end
21
38
 
22
- def contractorEntitiesQuery
23
- Ecoportal::API::GraphQL::Query::ContractorEntities.new(client)
24
- end
25
-
26
39
  # @return [Connection::Action, Query::Actions]
27
40
  def actions(**kargs, &block)
28
- if kargs.empty?
41
+ if kargs.empty? && !block_given?
29
42
  actionsQuery
30
43
  else
31
44
  actionsQuery.query(**kargs, &block)
32
45
  end
33
46
  end
34
47
 
35
- def actionsQuery
36
- Ecoportal::API::GraphQL::Query::Actions.new(client)
48
+ #action, actionsByPage, actionsCounter
49
+ #actionCategories
50
+
51
+ private
52
+
53
+ def tagTreesQuery
54
+ Ecoportal::API::GraphQL::Query::TagTrees.new(client, base_path: path)
37
55
  end
38
56
 
39
- #actionCategories
40
- #action, actionsByPage, actionsCounter
57
+ def contractorEntitiesQuery
58
+ Ecoportal::API::GraphQL::Query::ContractorEntities.new(client, base_path: path)
59
+ end
60
+
61
+ def actionsQuery
62
+ Ecoportal::API::GraphQL::Query::Actions.new(client, base_path: path)
63
+ end
41
64
  end
42
65
  end
43
66
  end
@@ -0,0 +1,11 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class TagTree < Ecoportal::API::GraphQL::Base::TagTree
6
+ embeds_many :nodes, klass: Ecoportal::API::GraphQL::Model::TagTreeNode, order_key: :weight
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class TagTreeNode < Ecoportal::API::GraphQL::Base::TagTreeNode
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,6 +7,8 @@ module Ecoportal
7
7
  end
8
8
  end
9
9
 
10
+ require 'ecoportal/api/graphql/model/tag_tree_node'
11
+ require 'ecoportal/api/graphql/model/tag_tree'
10
12
  require 'ecoportal/api/graphql/model/account'
11
13
  require 'ecoportal/api/graphql/model/user'
12
14
  require 'ecoportal/api/graphql/model/person_member'
@@ -3,20 +3,11 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Query
5
5
  class Actions < Ecoportal::API::GraphQL::Base::QueryConnection
6
+ field_name :actions
7
+
6
8
  class_resolver :item_class, Ecoportal::API::GraphQL::Model::Action
7
9
  class_resolver :connection_class, Ecoportal::API::GraphQL::Connection::Action
8
10
 
9
- def query(path: default_base_path, **kargs, &block)
10
- path ||= default_base_path
11
- request(*path, "actions") do
12
- graphql_query(**kargs, &basic_block(&block))
13
- end
14
- end
15
-
16
- def default_base_path
17
- ["currentOrganization"]
18
- end
19
-
20
11
  private
21
12
 
22
13
  def basic_block(&block)
@@ -3,21 +3,11 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Query
5
5
  class ContractorEntities < Ecoportal::API::GraphQL::Base::QueryConnection
6
+ field_name :contractorEntities
7
+
6
8
  class_resolver :item_class, Ecoportal::API::GraphQL::Model::ContractorEntity
7
9
  class_resolver :connection_class, Ecoportal::API::GraphQL::Connection::ContractorEntity
8
10
 
9
- def query(path: default_base_path, **kargs, &block)
10
- path ||= default_base_path
11
- #ap = access_point(path)
12
- request(*path, "contractorEntities") do
13
- graphql_query(**kargs, &basic_block(&block))
14
- end
15
- end
16
-
17
- def default_base_path
18
- ["currentOrganization"]
19
- end
20
-
21
11
  private
22
12
 
23
13
  def basic_block(&block)
@@ -0,0 +1,37 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Query
5
+ class TagTrees < Ecoportal::API::GraphQL::Base::QueryArray
6
+ field_name :tagTrees
7
+
8
+ class_resolver :item_class, Ecoportal::API::GraphQL::Model::TagTree
9
+
10
+ private
11
+
12
+ def basic_block(&block)
13
+ final_block = block || default_tree_block
14
+ Proc.new {
15
+ query {
16
+ currentOrganization {
17
+ tagTrees(&final_block)
18
+ }
19
+ }
20
+ }
21
+ end
22
+
23
+ def default_tree_block
24
+ Proc.new {
25
+ id
26
+ name
27
+ visitorManagementEnabled
28
+ nodes {
29
+ ___Ecoportal__API__GraphQL__Fragment__TagTreeNode
30
+ }
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -7,5 +7,6 @@ module Ecoportal
7
7
  end
8
8
  end
9
9
 
10
+ require 'ecoportal/api/graphql/query/tag_trees'
10
11
  require 'ecoportal/api/graphql/query/actions'
11
12
  require 'ecoportal/api/graphql/query/contractor_entities'
@@ -29,6 +29,7 @@ module Ecoportal
29
29
  end
30
30
  end
31
31
 
32
+ require 'ecoportal/api/graphql/helpers'
32
33
  require 'ecoportal/api/graphql/base'
33
34
  require 'ecoportal/api/graphql/model'
34
35
  require 'ecoportal/api/graphql/connection'
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GRAPQL_VERSION = "0.1.6"
3
+ GRAPQL_VERSION = "0.1.7"
4
4
  end
5
5
  end
@@ -0,0 +1,7 @@
1
+ require_relative 'local_libs'
2
+
3
+ api = Ecoportal::API::GraphQL.new
4
+ api.currentOrganization.tagTrees.each_with_index do |tree, idx|
5
+ puts "#{idx+1}. '#{tree.name}' (#{tree.id})"
6
+ pp tree.treeify
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-18 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 0.8.31
133
+ version: 0.8.33
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0.9'
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: 0.8.31
143
+ version: 0.8.33
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0.9'
@@ -214,8 +214,11 @@ files:
214
214
  - lib/ecoportal/api/graphql/base/payload.rb
215
215
  - lib/ecoportal/api/graphql/base/person_member.rb
216
216
  - lib/ecoportal/api/graphql/base/query.rb
217
+ - lib/ecoportal/api/graphql/base/query_array.rb
217
218
  - lib/ecoportal/api/graphql/base/query_connection.rb
218
219
  - lib/ecoportal/api/graphql/base/resource.rb
220
+ - lib/ecoportal/api/graphql/base/tag_tree.rb
221
+ - lib/ecoportal/api/graphql/base/tag_tree_node.rb
219
222
  - lib/ecoportal/api/graphql/base/validation_errors.rb
220
223
  - lib/ecoportal/api/graphql/connection.rb
221
224
  - lib/ecoportal/api/graphql/connection/action.rb
@@ -225,6 +228,9 @@ files:
225
228
  - lib/ecoportal/api/graphql/fragment/action.rb
226
229
  - lib/ecoportal/api/graphql/fragment/contractor_entity.rb
227
230
  - lib/ecoportal/api/graphql/fragment/pagination.rb
231
+ - lib/ecoportal/api/graphql/fragment/tag_tree_node.rb
232
+ - lib/ecoportal/api/graphql/helpers.rb
233
+ - lib/ecoportal/api/graphql/helpers/tag_tree.rb
228
234
  - lib/ecoportal/api/graphql/input.rb
229
235
  - lib/ecoportal/api/graphql/input/create_contractor_entity.rb
230
236
  - lib/ecoportal/api/graphql/input/destroy_contractor_entity.rb
@@ -243,6 +249,8 @@ files:
243
249
  - lib/ecoportal/api/graphql/model/page.rb
244
250
  - lib/ecoportal/api/graphql/model/person_member.rb
245
251
  - lib/ecoportal/api/graphql/model/resource.rb
252
+ - lib/ecoportal/api/graphql/model/tag_tree.rb
253
+ - lib/ecoportal/api/graphql/model/tag_tree_node.rb
246
254
  - lib/ecoportal/api/graphql/model/user.rb
247
255
  - lib/ecoportal/api/graphql/payload.rb
248
256
  - lib/ecoportal/api/graphql/payload/create_contractor_entity.rb
@@ -251,10 +259,12 @@ files:
251
259
  - lib/ecoportal/api/graphql/query.rb
252
260
  - lib/ecoportal/api/graphql/query/actions.rb
253
261
  - lib/ecoportal/api/graphql/query/contractor_entities.rb
262
+ - lib/ecoportal/api/graphql/query/tag_trees.rb
254
263
  - lib/ecoportal/api/graphql_version.rb
255
264
  - tests/actions_get.rb
256
265
  - tests/contractor_entities_get.rb
257
266
  - tests/local_libs.rb
267
+ - tests/tagtrees_get.rb
258
268
  homepage: https://www.ecoportal.com
259
269
  licenses:
260
270
  - MIT