Sha256: 887ad9835e7683bd99573602727301f4dd685c302420f2f2713cee3fc1ab0f65

Contents?: true

Size: 1.59 KB

Versions: 10

Compression:

Stored size: 1.59 KB

Contents

require 'graphlient'
module Ecoportal
  module API
    module Common
      module GraphQL
        class Client < ::Graphlient::Client
          attr_accessor :org_id, :host

          READ_TIMEOUT  = 90
          WRITE_TIMEOUT = 90

          include Ecoportal::API::Common::GraphQL::AuthService

          def initialize(email: nil, pass: nil, org_id: self.org_id,
            host: server, schema_path: host, no_schema: false)
            @org_id      = org_id
            @host        = host
            @no_schema   = no_schema
            @user_email  = email
            @user_pass   = pass

            puts "Configuring GraphQL Client onto '#{url}'"
            super(url,
              headers: {
                'Authorization' => "Bearer #{session_token(host: host)}"
              },
              http_options: {
                read_timeout:  READ_TIMEOUT,
                write_timeout: WRITE_TIMEOUT
              }.tap do |options|
                options.merge!(schema_path: schema_path) unless @no_schema
              end
            )
          end

          def new(org_id: self.org_id, host: self.host, schema_path: host, no_schema: @no_schema)
            self.class.new(org_id: org_id, host: host, schema_path: schema_path, no_schema: no_schema)
          end

          def org_id
            @org_id || fetch_env_required("ORGANIZATION_ID")
          end

          private

          def url
            "#{Ecoportal::API::Common::GraphQL::HttpClient.base_url(host)}/api/#{org_id}/graphql"
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.3.16 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.15 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.14 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.13 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.12 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.11 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.10 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.9 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.8 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.7 lib/ecoportal/api/common/graphql/client.rb