Sha256: f98f73489bd830581908a8e207432d7f7075f86adcfdb6cabc2346876804a887

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module Braintree
  class GraphQLClient < Http # :nodoc:

    def initialize(config)
      @config = config
      @graphql_headers = {
        'Accept' => 'application/json',
        'Braintree-Version' => @config.graphql_api_version,
        'Content-Type' => 'application/json'
      }
    end

    def query(definition, variables = {}, operationName = nil)
      graphql_connection = _setup_connection(@config.graphql_server, @config.graphql_port)

      request = {}
      request['query'] = definition
      request['operationName'] = operationName if operationName
      request['variables'] = variables

      response = _http_do Net::HTTP::Post, @config.graphql_base_url, request.to_json, nil, graphql_connection, @graphql_headers
      data = _parse_response(response)
      Util.raise_exception_for_graphql_error(data)

      data
    end

    def _parse_response(response)
      body = response.body
      body = Zlib::GzipReader.new(StringIO.new(body)).read if response.header['Content-Encoding'] == "gzip"
      JSON.parse(body, :symbolize_names => true)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
braintree-3.3.0 lib/braintree/graphql_client.rb
braintree-3.2.0 lib/braintree/graphql_client.rb
braintree-3.1.0 lib/braintree/graphql_client.rb
braintree-3.0.1 lib/braintree/graphql_client.rb
braintree-2.104.1 lib/braintree/graphql_client.rb
braintree-2.104.0 lib/braintree/graphql_client.rb
braintree-2.103.0 lib/braintree/graphql_client.rb
braintree-2.102.0 lib/braintree/graphql_client.rb
braintree-2.101.0 lib/braintree/graphql_client.rb