Sha256: ce88be7a008490cd913be3cfe664bb6217bab2502fbab0c29d90723fd0eb4e67

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

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

          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: 20,
                write_timeout: 30
              }.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

2 entries across 2 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.3.6 lib/ecoportal/api/common/graphql/client.rb
ecoportal-api-graphql-0.3.5 lib/ecoportal/api/common/graphql/client.rb