ecoportal-api-graphql 0.1.0

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 (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -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/CHANGELOG.md +22 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +20 -0
  11. data/Rakefile +27 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/bin/setup.ps1 +6 -0
  15. data/ecoportal-api-graphql.gemspec +34 -0
  16. data/lib/ecoportal/api/common/graphql/auth_service.rb +66 -0
  17. data/lib/ecoportal/api/common/graphql/class_helpers.rb +34 -0
  18. data/lib/ecoportal/api/common/graphql/client.rb +43 -0
  19. data/lib/ecoportal/api/common/graphql/doc_helpers.rb +10 -0
  20. data/lib/ecoportal/api/common/graphql/hash_helpers.rb +79 -0
  21. data/lib/ecoportal/api/common/graphql/http_client.rb +84 -0
  22. data/lib/ecoportal/api/common/graphql.rb +15 -0
  23. data/lib/ecoportal/api/common.graphql.rb +8 -0
  24. data/lib/ecoportal/api/graphql/base/action.rb +36 -0
  25. data/lib/ecoportal/api/graphql/base/action_category.rb +13 -0
  26. data/lib/ecoportal/api/graphql/base/connection.rb +33 -0
  27. data/lib/ecoportal/api/graphql/base/contractor_entity.rb +17 -0
  28. data/lib/ecoportal/api/graphql/base/date_time.rb +12 -0
  29. data/lib/ecoportal/api/graphql/base/field.rb +12 -0
  30. data/lib/ecoportal/api/graphql/base/file_attachment.rb +15 -0
  31. data/lib/ecoportal/api/graphql/base/file_container.rb +14 -0
  32. data/lib/ecoportal/api/graphql/base/id_diff_input.rb +11 -0
  33. data/lib/ecoportal/api/graphql/base/model.rb +33 -0
  34. data/lib/ecoportal/api/graphql/base/organization.rb +13 -0
  35. data/lib/ecoportal/api/graphql/base/page.rb +12 -0
  36. data/lib/ecoportal/api/graphql/base/page_info.rb +12 -0
  37. data/lib/ecoportal/api/graphql/base/payload.rb +25 -0
  38. data/lib/ecoportal/api/graphql/base/person_member.rb +20 -0
  39. data/lib/ecoportal/api/graphql/base/query.rb +61 -0
  40. data/lib/ecoportal/api/graphql/base/query_connection.rb +56 -0
  41. data/lib/ecoportal/api/graphql/base/resource.rb +13 -0
  42. data/lib/ecoportal/api/graphql/base/validation_errors.rb +23 -0
  43. data/lib/ecoportal/api/graphql/base.rb +28 -0
  44. data/lib/ecoportal/api/graphql/connection/action.rb +11 -0
  45. data/lib/ecoportal/api/graphql/connection/contractor_entity.rb +11 -0
  46. data/lib/ecoportal/api/graphql/connection/person_member.rb +11 -0
  47. data/lib/ecoportal/api/graphql/connection.rb +12 -0
  48. data/lib/ecoportal/api/graphql/fragment/contractor_entity.rb +19 -0
  49. data/lib/ecoportal/api/graphql/fragment/pagination.rb +17 -0
  50. data/lib/ecoportal/api/graphql/fragment.rb +50 -0
  51. data/lib/ecoportal/api/graphql/input/create_contractor_entity.rb +14 -0
  52. data/lib/ecoportal/api/graphql/input/destroy_contractor_entity.rb +11 -0
  53. data/lib/ecoportal/api/graphql/input/search.rb +13 -0
  54. data/lib/ecoportal/api/graphql/input/search_filter.rb +12 -0
  55. data/lib/ecoportal/api/graphql/input/search_sorter.rb +11 -0
  56. data/lib/ecoportal/api/graphql/input/update_contractor_entity.rb +10 -0
  57. data/lib/ecoportal/api/graphql/input.rb +15 -0
  58. data/lib/ecoportal/api/graphql/model/account.rb +13 -0
  59. data/lib/ecoportal/api/graphql/model/action.rb +21 -0
  60. data/lib/ecoportal/api/graphql/model/contractor_entity.rb +12 -0
  61. data/lib/ecoportal/api/graphql/model/field.rb +10 -0
  62. data/lib/ecoportal/api/graphql/model/file_attachment.rb +10 -0
  63. data/lib/ecoportal/api/graphql/model/file_container.rb +11 -0
  64. data/lib/ecoportal/api/graphql/model/organization.rb +46 -0
  65. data/lib/ecoportal/api/graphql/model/page.rb +10 -0
  66. data/lib/ecoportal/api/graphql/model/person_member.rb +15 -0
  67. data/lib/ecoportal/api/graphql/model/resource.rb +12 -0
  68. data/lib/ecoportal/api/graphql/model/user.rb +12 -0
  69. data/lib/ecoportal/api/graphql/model.rb +20 -0
  70. data/lib/ecoportal/api/graphql/payload/create_contractor_entity.rb +11 -0
  71. data/lib/ecoportal/api/graphql/payload/destroy_contractor_entity.rb +10 -0
  72. data/lib/ecoportal/api/graphql/payload/update_contractor_entity.rb +10 -0
  73. data/lib/ecoportal/api/graphql/payload.rb +12 -0
  74. data/lib/ecoportal/api/graphql/query/actions.rb +94 -0
  75. data/lib/ecoportal/api/graphql/query/contractor_entities.rb +64 -0
  76. data/lib/ecoportal/api/graphql/query.rb +11 -0
  77. data/lib/ecoportal/api/graphql.rb +38 -0
  78. data/lib/ecoportal/api/graphql_version.rb +5 -0
  79. data/lib/ecoportal/api-graphql.rb +10 -0
  80. data/tests/actions_get.rb +8 -0
  81. data/tests/contractor_entities_get.rb +20 -0
  82. data/tests/local_libs.rb +14 -0
  83. metadata +278 -0
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class Account < Ecoportal::API::GraphQL::Base::Model
6
+ passkey :id
7
+ passthrough :default_tag
8
+ passboolean :active
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class Action < Ecoportal::API::GraphQL::Base::Action
6
+ embeds_one :actionCategory, klass: GraphQL::Base::ActionCategory
7
+ embeds_one :dueOrClosedDate, klass: GraphQL::Base::DateTime
8
+ embeds_many :assignedTo, klass: GraphQL::Model::PersonMember
9
+ embeds_one :creator, klass: GraphQL::Model::PersonMember
10
+ embeds_one :creatorUser, klass: GraphQL::Model::User
11
+ embeds_one :updater, klass: GraphQL::Model::PersonMember
12
+ embeds_one :updaterUser, klass: GraphQL::Model::User
13
+ embeds_one :completer, klass: GraphQL::Model::PersonMember
14
+ embeds_many :fileContainers, klass: GraphQL::Model::FileContainer
15
+ embeds_many :linkedResources, klass: GraphQL::Model::Resource
16
+ #embeds_many :activities, klass: GraphQL::Activity::Action
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class ContractorEntity < Ecoportal::API::GraphQL::Base::ContractorEntity
6
+ embeds_one :associatedPeople, klass: "Ecoportal::API::GraphQL::Connections::PersonMemberConnection"
7
+ embeds_many :leadContractors, enum_class: "Ecoportal::API::GraphQL::Model::PersonMember"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class Field < Ecoportal::API::GraphQL::Base::Field
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class FileAttachment < Ecoportal::API::GraphQL::Base::FileAttachment
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class FileContainer < Ecoportal::API::GraphQL::Base::FileContainer
6
+ embeds_many :fileAttachments, klass: Ecoportal::API::GraphQL::Model::FileAttachment
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class Organization < Ecoportal::API::GraphQL::Base::Organization
6
+ class << self
7
+ #userGroup, userGroups,
8
+ #tagTree, tagTrees,
9
+ #register, registers
10
+ #personMembers, attachablePersonMembers
11
+ #contractorEntity,
12
+
13
+ # @return [Connection::ContractorEntity, Query::ContractorEntities]
14
+ def contractorEntities(**kargs, &block)
15
+ if kargs.empty?
16
+ contractorEntitiesQuery
17
+ else
18
+ contractorEntitiesQuery.query(**kargs, &block)
19
+ end
20
+ end
21
+
22
+ def contractorEntitiesQuery
23
+ Ecoportal::API::GraphQL::Query::ContractorEntities.new(client)
24
+ end
25
+
26
+ # @return [Connection::Action, Query::Actions]
27
+ def actions(**kargs, &block)
28
+ if kargs.empty?
29
+ actionsQuery
30
+ else
31
+ actionsQuery.query(**kargs, &block)
32
+ end
33
+ end
34
+
35
+ def actionsQuery
36
+ Ecoportal::API::GraphQL::Query::Actions.new(client)
37
+ end
38
+
39
+ #actionCategories
40
+ #action, actionsByPage, actionsCounter
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class Page < Ecoportal::API::GraphQL::Base::Page
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class PersonMember < Ecoportal::API::GraphQL::Base::PersonMember
6
+ embeds_one :contractorOrganization, klass: "Ecoportal::API::GraphQL::Model::ContractorEntity"
7
+ embeds_one :account, klass: Ecoportal::API::GraphQL::Model::Account
8
+
9
+ # embeds_many :privateFields, enum_class: Ecoportal::API::GraphQL::Model::MemberSchemaFields
10
+ # embeds_many :publicFields, enum_class: Ecoportal::API::GraphQL::Model::MemberSchemaFields
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class Resource < Ecoportal::API::GraphQL::Base::Resource
6
+ embeds_one :page, klass: "Ecoportal::API::GraphQL::Model::Page"
7
+ embeds_one :field, klass: "Ecoportal::API::GraphQL::Model::Field"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ class User < Ecoportal::API::GraphQL::Base::Model
6
+ passkey :id
7
+ passthrough :email, :name
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Model
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ecoportal/api/graphql/model/account'
11
+ require 'ecoportal/api/graphql/model/user'
12
+ require 'ecoportal/api/graphql/model/person_member'
13
+ require 'ecoportal/api/graphql/model/file_attachment'
14
+ require 'ecoportal/api/graphql/model/file_container'
15
+ require 'ecoportal/api/graphql/model/field'
16
+ require 'ecoportal/api/graphql/model/page'
17
+ require 'ecoportal/api/graphql/model/resource'
18
+ require 'ecoportal/api/graphql/model/action'
19
+ require 'ecoportal/api/graphql/model/contractor_entity'
20
+ require 'ecoportal/api/graphql/model/organization'
@@ -0,0 +1,11 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Payload
5
+ class CreateContractorEntity < Ecoportal::API::GraphQL::Base::Payload
6
+ class_resolver :item_class, "Ecoportal::API::GraphQL::Model::ContractorEntity"
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 Payload
5
+ class DestroyContractorEntity < Ecoportal::API::GraphQL::Payload::CreateContractorEntity
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Payload
5
+ class UpdateContractorEntity < Ecoportal::API::GraphQL::Payload::CreateContractorEntity
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Payload
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ecoportal/api/graphql/payload/create_contractor_entity'
11
+ require 'ecoportal/api/graphql/payload/update_contractor_entity'
12
+ require 'ecoportal/api/graphql/payload/destroy_contractor_entity'
@@ -0,0 +1,94 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Query
5
+ class Actions < Ecoportal::API::GraphQL::Base::QueryConnection
6
+ class_resolver :item_class, Ecoportal::API::GraphQL::Model::Action
7
+ class_resolver :connection_class, Ecoportal::API::GraphQL::Connection::Action
8
+
9
+ def query(path: default_base_path, **kargs, &block)
10
+ path ||= default_base_path
11
+ kargs = self.class.slice_params(kargs)
12
+ request(*path, "actions") do
13
+ next client.query(kargs, &basic_block(&block)) if block_given?
14
+ client.query(kargs, &basic_block)
15
+ end
16
+ end
17
+
18
+ def default_base_path
19
+ ["currentOrganization"]
20
+ end
21
+
22
+ private
23
+
24
+ def basic_block(&block)
25
+ connection_block = block || default_connection_block
26
+ Proc.new {
27
+ query(searchConf: :Search, after: :string, before: :string, first: :int, last: :int) {
28
+ currentOrganization {
29
+ actions(
30
+ searchConf: :searchConf,
31
+ after: :after,
32
+ before: :before,
33
+ first: :first,
34
+ last: :last,
35
+ &connection_block
36
+ )
37
+ }
38
+ }
39
+ }
40
+ end
41
+
42
+ def default_connection_block
43
+ Proc.new {
44
+ totalCount
45
+ pageInfo {
46
+ endCursor
47
+ }
48
+ nodes {
49
+ id
50
+ altId
51
+ actionCategory {
52
+ name
53
+ value
54
+ }
55
+ standaloneAction
56
+ status
57
+ relativeStatus
58
+ archived
59
+ tags
60
+ name
61
+ description
62
+ assignedTo {
63
+ name
64
+ email
65
+ }
66
+ dueDate {
67
+ dateTime
68
+ timeZone
69
+ }
70
+ completedAt {
71
+ dateTime
72
+ timeZone
73
+ }
74
+ completer {
75
+ name
76
+ email
77
+ }
78
+ linkedResources {
79
+ page {
80
+ name
81
+ mouldCounter
82
+ }
83
+ field {
84
+ label
85
+ }
86
+ }
87
+ }
88
+ }
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,64 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Query
5
+ class ContractorEntities < Ecoportal::API::GraphQL::Base::QueryConnection
6
+ class_resolver :item_class, Ecoportal::API::GraphQL::Model::ContractorEntity
7
+ class_resolver :connection_class, Ecoportal::API::GraphQL::Connection::ContractorEntity
8
+
9
+ def query(path: default_base_path, **kargs, &block)
10
+ path ||= default_base_path
11
+ kargs = self.class.slice_params(kargs)
12
+ ap = access_point(path)
13
+ request(*path, "contractorEntities") do
14
+ next client.query(kargs, &basic_block(&block)) if block_given?
15
+ client.query(kargs, &basic_block)
16
+ end
17
+ end
18
+
19
+ def default_base_path
20
+ ["currentOrganization"]
21
+ end
22
+
23
+ private
24
+
25
+ def basic_block(&block)
26
+ connection_block = block || default_connection_block
27
+ Proc.new {
28
+ query(searchConf: :Search, after: :string, before: :string, first: :int, last: :int) {
29
+ currentOrganization {
30
+ contractorEntities(
31
+ searchConf: :searchConf,
32
+ after: :after,
33
+ before: :before,
34
+ first: :first,
35
+ last: :last,
36
+ &connection_block
37
+ )
38
+ }
39
+ }
40
+ }
41
+ end
42
+
43
+ def default_connection_block
44
+ Proc.new {
45
+ totalCount
46
+ pageInfo {
47
+ endCursor
48
+ }
49
+ nodes {
50
+ id
51
+ name
52
+ schemaId
53
+ active
54
+ approved
55
+ associatedPeopleIds
56
+ leadContractorIds
57
+ }
58
+ }
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Query
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ecoportal/api/graphql/query/actions'
11
+ require 'ecoportal/api/graphql/query/contractor_entities'
@@ -0,0 +1,38 @@
1
+ module Ecoportal
2
+ module API
3
+ # @attr_reader client [Common::GraphQL::Client] a client object that holds the configuration of the api connection.
4
+ # @attr_reader logger [Logger] the logger.
5
+ class GraphQL
6
+ include Ecoportal::API::Common::GraphQL::ClassHelpers
7
+
8
+ attr_reader :client
9
+
10
+ # Creates a `GraphQL` object to interact with the ecoPortal `GraphQL API`.
11
+ # @param org_id [String] the id of the target organization.
12
+ # It defaults to the environmental variable `ORGANIZATION_ID`, if defined
13
+ # @param logger [Logger] an object with `Logger` interface to generate logs.
14
+ def initialize(org_id: ENV['ORGANIZATION_ID'])
15
+ @client = Ecoportal::API::Common::GraphQL::Client.new(org_id: org_id, no_schema: true)
16
+ @fragments = Ecoportal::API::GraphQL::Fragment.new(client)
17
+ end
18
+
19
+ def currentOrganizationClass
20
+ API::GraphQL::Model::Organization.tap do |org_class|
21
+ org_class.client = client
22
+ end
23
+ end
24
+
25
+ def currentOrganization
26
+ currentOrganizationClass
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ require 'ecoportal/api/graphql/base'
33
+ require 'ecoportal/api/graphql/model'
34
+ require 'ecoportal/api/graphql/connection'
35
+ require 'ecoportal/api/graphql/payload'
36
+ require 'ecoportal/api/graphql/input'
37
+ require 'ecoportal/api/graphql/fragment'
38
+ require 'ecoportal/api/graphql/query'
@@ -0,0 +1,5 @@
1
+ module Ecoportal
2
+ module API
3
+ GRAPQL_VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "ecoportal/api-v2"
2
+ require "ecoportal/api/graphql_version"
3
+
4
+ module Ecoportal
5
+ module API
6
+ end
7
+ end
8
+
9
+ require_relative "api/common.graphql"
10
+ require_relative "api/graphql"
@@ -0,0 +1,8 @@
1
+ require_relative 'local_libs'
2
+ require 'ecoportal/api-graphql'
3
+
4
+ api = Ecoportal::API::GraphQL.new
5
+ api.currentOrganization.actions.each_with_index do |action, idx|
6
+ break if idx >= 14
7
+ puts "#{idx+1}. '#{action.name}' (#{action.altId}): #{action.status} (#{action.relativeStatus})"
8
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'local_libs'
2
+ require 'ecoportal/api-graphql'
3
+
4
+ api = Ecoportal::API::GraphQL.new
5
+ api.currentOrganization.contractorEntities.each_with_index do |entity, idx|
6
+ break if idx >= 14
7
+ puts "#{idx+1}. #{entity.name}"
8
+ end
9
+
10
+ result = api.currentOrganization.contractorEntities(first: 10)
11
+ result.nodes.each {|entity| puts "• #{entity.name}"}
12
+
13
+ result = api.currentOrganization.contractorEntities(first: 5) {
14
+ nodes {
15
+ id
16
+ name
17
+ approved
18
+ }
19
+ }
20
+ result.nodes.each {|entity| puts "#{entity.name} => approved? #{entity.approved}"}
@@ -0,0 +1,14 @@
1
+ base_dir = 'C:/ruby_scripts/git'
2
+
3
+ api_path = File.join(base_dir,'/ecoportal-api/lib')
4
+ $LOAD_PATH.unshift File.expand_path(api_path)
5
+ #require 'ecoportal/api'
6
+ api_req = File.join(base_dir,'/ecoportal-api/lib/ecoportal/api')
7
+ require api_req
8
+
9
+ api_v2_path = File.join(base_dir,'/ecoportal-api-v2/lib')
10
+ $LOAD_PATH.unshift File.expand_path(api_v2_path)
11
+ #require 'ecoportal/api-v2'
12
+ require File.join(base_dir,'/ecoportal-api-v2/lib/ecoportal/api-v2')
13
+ api_path = '../lib'
14
+ $LOAD_PATH.unshift File.expand_path(api_path)