ecoportal-api-graphql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8b2c0cedbda4c84748b943f0abb5b6bca595385f79692189aa7bcf6fb5d1f46b
4
+ data.tar.gz: 7e0582c067c29772bc89257fbd83aab19d6268c5500b054cb62a69285c86e992
5
+ SHA512:
6
+ metadata.gz: f26eb9930114eac84351856978256e470a8c5a89fef4e54ae7c2424829fbc0970d906865a4a1e3b6e205e72e3e915960c97169bff83af5d6cc286c6cd6703e5d
7
+ data.tar.gz: 68de94a4e01bb6d7eb97946adff3456920971453665d9a2069511c76def7771a7bb8998b9cf66ee0ff43493ea4e9ba11a6b3883474f19747893a4a11af6f0379
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ # it's a gem, ignore the lockfile
2
+ Gemfile.lock
3
+
4
+ .env
5
+ # build artifacts
6
+ *.gem
7
+ /.bundle/
8
+ /vendor/bundle
9
+ /spec/reports/
10
+ /tmp/
11
+ /pkg/
12
+
13
+ # docs
14
+ /.yardoc
15
+ /_yardoc/
16
+ /coverage/
17
+ /doc/
18
+
19
+ # rspec failure tracking
20
+ .rspec_status
21
+ scratch.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,55 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5.1
3
+ Exclude:
4
+ - 'config/routes.rb'
5
+
6
+ Metrics/LineLength:
7
+ Enabled: false
8
+ Metrics/BlockLength:
9
+ ExcludedMethods: [context, describe]
10
+ Max: 50
11
+ Metrics/MethodLength:
12
+ Max: 50
13
+ Metrics/ClassLength:
14
+ Max: 200
15
+ Metrics/AbcSize:
16
+ Max: 30
17
+
18
+ ParameterLists:
19
+ Max: 5
20
+ CountKeywordArgs: false
21
+
22
+ Style/StringLiterals:
23
+ Enabled: false
24
+ Style/FrozenStringLiteralComment:
25
+ Enabled: false
26
+ Style/CommentedKeyword:
27
+ Enabled: false
28
+ Style/MultilineBlockChain:
29
+ Enabled: false
30
+ Style/Documentation:
31
+ Enabled: false
32
+ Style/StringLiteralsInInterpolation:
33
+ Enabled: false
34
+ Style/AndOr:
35
+ Enabled: false
36
+
37
+ Layout/SpaceInsideHashLiteralBraces:
38
+ Enabled: false
39
+ Layout/SpaceInsideBlockBraces:
40
+ Enabled: false
41
+ Layout/SpaceAroundOperators:
42
+ Enabled: false
43
+ Layout/ExtraSpacing:
44
+ AllowForAlignment: true
45
+ Layout/AccessModifierIndentation:
46
+ EnforcedStyle: indent
47
+ Layout/DotPosition:
48
+ EnforcedStyle: trailing
49
+ Layout/MultilineMethodCallIndentation:
50
+ EnforcedStyle: indented
51
+ Layout/IndentHash:
52
+ Enabled: false
53
+
54
+ Naming/VariableNumber:
55
+ EnforcedStyle: snake_case
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/.yardopts ADDED
@@ -0,0 +1,10 @@
1
+ --readme README.md
2
+ --charset utf-8
3
+ --markup-provider=redcarpet
4
+ --markup=markdown
5
+ --no-private
6
+ --output-dir ./doc
7
+ 'lib/**/*.rb'
8
+ -
9
+ CHANGELOG.md
10
+ LICENSE
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [0.0.2] - 2022-09-xx
5
+
6
+ ### Added
7
+
8
+ ### Changed
9
+
10
+ ### Fixed
11
+
12
+ ### ToDo
13
+ - Make `GraphQL` default fragments work
14
+ - Add update/create operations for `ContractorEntity`
15
+ - Add currentOrganization.action
16
+ - Analyse how to "DSL" currentOrganization.action.activities
17
+ - review `path` tracking
18
+
19
+ ## [0.0.1] - 2022-09-15
20
+
21
+ ### Added
22
+ - First commit with some basic structure
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ecoportal-api.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 ecoPortal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Ecoportal::API::GraphQL
2
+
3
+ This is a basic collection of helpers that can be used to interact with the
4
+ [ecoPortal](https://www.ecoportal.com) `GraphQL` API
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ecoportal-api-graphql', require: %w[ecoportal/api-graphql]
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ecoportal-api-graphql
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "yard"
4
+ require "redcarpet"
5
+
6
+ desc "run the specs"
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ desc "run rspec showing backtrace"
10
+ RSpec::Core::RakeTask.new(:spec_trace) do |task|
11
+ task.rspec_opts = ['--backtrace']
12
+ end
13
+
14
+ desc "run rspec stopping on first fail, and show backtrace"
15
+ RSpec::Core::RakeTask.new(:spec_fast) do |task|
16
+ task.rspec_opts = ['--fail-fast', '--backtrace']
17
+ end
18
+
19
+ # default task name is yard
20
+ desc "Yard: generate all the documentation"
21
+ YARD::Rake::YardocTask.new(:doc) do |t|
22
+ #t.files = ['lib/**/*.rb']
23
+ end
24
+
25
+ task :default => [:spec]
26
+ task :rspec_trace => :spec_trace
27
+ task :rspec_fast => :spec_fast
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ecoportal/api-graphql"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ Pry.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/setup.ps1 ADDED
@@ -0,0 +1,6 @@
1
+
2
+ <# For mor information on Strict-Mode, visit:
3
+ https://devblogs.microsoft.com/scripting/enforce-better-script-practices-by-using-set-strictmode/ #>
4
+ Set-StrictMode -Version 1.0
5
+
6
+ bundle install
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ecoportal/api/graphql_version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ecoportal-api-graphql"
8
+ spec.version = Ecoportal::API::GRAPQL_VERSION
9
+ spec.authors = ["Oscar Segura"]
10
+ spec.email = ["oscar@ecoportal.co.nz"]
11
+
12
+ spec.summary = %q{A collection of helpers for interacting with the ecoPortal GraphQL API}
13
+ spec.homepage = "https://www.ecoportal.com"
14
+ spec.licenses = %w[MIT]
15
+
16
+ spec.required_ruby_version = '>= 2.6.0'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", ">= 2.2.17", "< 2.3"
26
+ spec.add_development_dependency "rspec", ">= 3.10.0", "< 3.11"
27
+ spec.add_development_dependency "rake", ">= 13.0.3", "< 13.1"
28
+ spec.add_development_dependency "yard", ">= 0.9.26", "< 0.10"
29
+ spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
30
+ spec.add_development_dependency "pry" , ">= 0.14"
31
+
32
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.31', '< 0.9'
33
+ spec.add_dependency 'graphlient', '>= 0.6.0', '< 0.7'
34
+ end
@@ -0,0 +1,66 @@
1
+ require 'graphlient'
2
+ module Ecoportal
3
+ module API
4
+ module Common
5
+ module GraphQL
6
+ module AuthService
7
+ DEFAULT_SERVER = "live.ecoportal.com"
8
+
9
+ module InstanceMethods
10
+ def session_token(host: server, version: nil)
11
+ http_client(host: host, version: version).post("/oauth/token", data: {
12
+ "grant_type" => "password",
13
+ "email" => user_email,
14
+ "password" => user_pass
15
+ }).yield_self do |response|
16
+ if response.success?
17
+ response.body["access_token"]
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def http_client(host: server, version: nil)
25
+ @http_client ||= Ecoportal::API::Common::GraphQL::HttpClient.new(host: host, version: version)
26
+ end
27
+
28
+ def user_email
29
+ fetch_env_required("USER_EMAIL")
30
+ end
31
+
32
+ def user_pass
33
+ fetch_env_required("USER_PASS")
34
+ end
35
+
36
+ def server(default = DEFAULT_SERVER)
37
+ ENV['SERVER'] || default
38
+ end
39
+
40
+ def fetch_env_required(name)
41
+ abort("Missing ENV '#{name}'") unless ENV.key?(name)
42
+ ENV[name]
43
+ end
44
+
45
+ def abort(msg)
46
+ puts msg
47
+ exit(1)
48
+ end
49
+ end
50
+
51
+ module ClassMethods
52
+ end
53
+
54
+ class << self
55
+ include InstanceMethods
56
+
57
+ def included(base)
58
+ base.send(:include, InstanceMethods)
59
+ base.extend(ClassMethods)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,34 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module GraphQL
5
+ module ClassHelpers
6
+ module InstanceMethods
7
+ def becomes(klass)
8
+ klass.new.tap do |becoming|
9
+ instance_variables.each do |var|
10
+ becoming.instance_variable_set(var, instance_variable_get(var))
11
+ end
12
+ end
13
+ end
14
+
15
+ def becomes_parent_class
16
+ becomes(self.class.superclass)
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ include Ecoportal::API::Common::Content::ClassHelpers
22
+ end
23
+
24
+ class << self
25
+ def included(base)
26
+ base.send(:include, InstanceMethods)
27
+ base.extend(ClassMethods)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'graphlient'
2
+ module Ecoportal
3
+ module API
4
+ module Common
5
+ module GraphQL
6
+ class Client < ::Graphlient::Client
7
+ attr_accessor :org_id, :host
8
+
9
+ include Ecoportal::API::Common::GraphQL::AuthService
10
+
11
+ def initialize(org_id:, host: server, schema_path: host, no_schema: false)
12
+ @org_id = org_id
13
+ @host = host
14
+ @no_schema = no_schema
15
+
16
+ puts "Configuring GraphQL Client onto '#{url}'"
17
+ super(url,
18
+ headers: {
19
+ 'Authorization' => "Bearer #{session_token}"
20
+ },
21
+ http_options: {
22
+ read_timeout: 20,
23
+ write_timeout: 30
24
+ }.tap do |options|
25
+ options.merge!(schema_path: schema_path) unless @no_schema
26
+ end
27
+ )
28
+ end
29
+
30
+ def new(org_id: self.org_id, host: self.host, schema_path: self.schema_path, no_schema: @no_schema)
31
+ self.class.new(org_id: org_id, host: host, schema_path: schema_path, no_schema: no_schema)
32
+ end
33
+
34
+ private
35
+
36
+ def url
37
+ "#{Ecoportal::API::Common::GraphQL::HttpClient.base_url(host)}/api/#{org_id}/graphql"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module GraphQL
5
+ module DocHelpers
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,79 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module GraphQL
5
+ module HashHelpers
6
+ module InstanceMethods
7
+ def transform_keys_deep(value, &block)
8
+ case value
9
+ when Hash
10
+ value.dup.each_with_object({}) do |(k, v), out|
11
+ k_val = block_given?? yield(k) : k
12
+ out[k_val] = keys_to_sym_deep(v)
13
+ end
14
+ when Enumerable
15
+ value.map {|v| keys_to_sym_deep(v)}
16
+ else
17
+ value
18
+ end
19
+ end
20
+
21
+ def keys_to_sym_deep(value)
22
+ transform_keys_deep(value) {|k| k.to_sym}
23
+ end
24
+
25
+ def keys_to_s_deep(value)
26
+ transform_keys_deep(value) {|k| k.to_s}
27
+ end
28
+
29
+ def remove_nil_keys_deep(value, target: [])
30
+ target = [target].flatten.compact unless target.is_a?(Array)
31
+ return value if target.empty?
32
+ case value
33
+ when Hash
34
+ value.dup.each_with_object({}) do |(k, v), out|
35
+ next unless v || !target.include?(k)
36
+ out[k] = remove_nil_keys_deep(v, target: target)
37
+ end
38
+ when Enumerable
39
+ value.map {|v| remove_nil_keys_deep(v, target: target)}
40
+ else
41
+ value
42
+ end
43
+ end
44
+
45
+ def deep_dup(data)
46
+ case data
47
+ when Hash
48
+ data.each_with_object({}) do |(k,v), copy|
49
+ if k.is_a?(::String) || k.is_a?(::Symbol)
50
+ copy[k] = deep_dup(v)
51
+ else
52
+ copy.delete(k)
53
+ copy[deep_dup(k)] = deep_dup(v)
54
+ end
55
+ end
56
+ when Enumerable
57
+ data.map {|d| deep_dup(d)}
58
+ else
59
+ data.dup
60
+ end
61
+ end
62
+ end
63
+
64
+ module ClassMethods
65
+ end
66
+
67
+ class << self
68
+ include InstanceMethods
69
+
70
+ def included(base)
71
+ base.send(:include, InstanceMethods)
72
+ base.extend(ClassMethods)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,84 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module GraphQL
5
+ class HttpClient < Common::Client
6
+ class << self
7
+ def base_url(host)
8
+ "#{protocol(host)}://#{host}"
9
+ end
10
+
11
+ def protocol(host)
12
+ host.match(/^localhost|^127\.0\.0\.1/)? "http" : "https"
13
+ end
14
+ end
15
+
16
+ attr_reader :host, :version
17
+
18
+ def initialize(api_key: nil, version: "v1", host: "live.ecoportal.com", logger: ::Logger.new(IO::NULL), response_logging: false)
19
+ super(api_key: api_key, version: version, host: host, logger: logger, response_logging: false)
20
+ end
21
+
22
+ def refresh_key(value)
23
+ @api_key = value
24
+ end
25
+
26
+ # Creates a HTTP object adding the `X-ApiKey` or `X-ECOPORTAL-API-KEY` param to the header, depending on the API version.
27
+ # @note It configures HTTP so it only allows body data in json format.
28
+ # @return [HTTP] HTTP object.
29
+ def base_request
30
+ @base_request ||= begin
31
+ case @version
32
+ when NilClass
33
+ HTTP.accept(:json)
34
+ when "v2"
35
+ HTTP.headers("X-ECOPORTAL-API-KEY" => key_token).accept(:json)
36
+ when "graphql"
37
+ HTTP.headers("Authorization" => "Bearer #{key_token}").accept(:json)
38
+ else
39
+ HTTP.headers("X-ApiKey" => key_token).accept(:json)
40
+ end
41
+ end
42
+ end
43
+
44
+ # Full URl builder of the request
45
+ # @param path [String] the tail that completes the url of the request.
46
+ # @return [String] the final url.
47
+ def url_for(path)
48
+ version? ? "#{base_url_api}#{path}" : "#{base_url}#{path}"
49
+ end
50
+
51
+ private
52
+
53
+ def version?
54
+ !!@version
55
+ end
56
+
57
+ def protocol
58
+ @protocol ||= self.class.protocol(host)
59
+ end
60
+
61
+ def base_url
62
+ @base_url ||= self.class.base_url(host)
63
+ end
64
+
65
+ def base_url_api
66
+ @base_uri_api ||= "#{base_url}/api/#{version}"
67
+ end
68
+
69
+ def key_token
70
+ if @api_key.nil? || @api_key.match(/\A\W*\z/)
71
+ if (version == "v0") && key = ENV['ORG_INT_KEY']
72
+ key
73
+ else
74
+ puts "Api-key missing!"
75
+ end
76
+ else
77
+ @api_key
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,15 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module GraphQL
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ecoportal/api/common/graphql/http_client'
11
+ require 'ecoportal/api/common/graphql/auth_service'
12
+ require 'ecoportal/api/common/graphql/client'
13
+ require 'ecoportal/api/common/graphql/class_helpers'
14
+ require 'ecoportal/api/common/graphql/doc_helpers'
15
+ require 'ecoportal/api/common/graphql/hash_helpers'
@@ -0,0 +1,8 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ end
5
+ end
6
+ end
7
+
8
+ require 'ecoportal/api/common/graphql'
@@ -0,0 +1,36 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Base
5
+ class Action < Ecoportal::API::GraphQL::Base::Model
6
+ passkey :id
7
+ passthrough :altId
8
+ passthrough :name, :description
9
+ passthrough :age
10
+
11
+ passarray :tags, :location
12
+
13
+ passthrough :status, :relativeStatus
14
+ passboolean :archived, :attached, :standaloneAction
15
+ passthrough :actionCategoryId
16
+
17
+ passarray :fileContainerIds
18
+
19
+ passarray :assignedPersonMemberIds
20
+ passthrough :creatorId, :creatorUserId
21
+ passthrough :updaterId, :updaterUserId
22
+ passthrough :completerId
23
+
24
+ passthrough :timeZone
25
+ embeds_one :dueDate, klass: GraphQL::Base::DateTime
26
+ embeds_one :reminderDate, klass: GraphQL::Base::DateTime
27
+ embeds_one :createdAt, klass: GraphQL::Base::DateTime
28
+ embeds_one :updatedAt, klass: GraphQL::Base::DateTime
29
+ embeds_one :completedAt, klass: GraphQL::Base::DateTime
30
+ embeds_one :openededAt, klass: GraphQL::Base::DateTime
31
+ embeds_one :closedAt, klass: GraphQL::Base::DateTime
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Base
5
+ class ActionCategory < Ecoportal::API::GraphQL::Base::Model
6
+ passkey :id
7
+ passthrough :name, :value
8
+ passboolean :archived
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end