Sha256: 703872df092f68d72f9cbc7abbda4df1cd1694e5f90433357c1a755f85e17f40

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

module Braintree
  class GraphQLClient < Http

    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

8 entries across 8 versions & 1 rubygems

Version Path
braintree-4.23.0 lib/braintree/graphql_client.rb
braintree-4.22.0 lib/braintree/graphql_client.rb
braintree-4.21.0 lib/braintree/graphql_client.rb
braintree-4.20.0 lib/braintree/graphql_client.rb
braintree-4.19.0 lib/braintree/graphql_client.rb
braintree-4.18.0 lib/braintree/graphql_client.rb
braintree-4.17.0 lib/braintree/graphql_client.rb
braintree-4.16.0 lib/braintree/graphql_client.rb