Class: GraphQL::Hive::Client
- Inherits:
-
Object
- Object
- GraphQL::Hive::Client
- Defined in:
- lib/graphql-hive/client.rb
Overview
API client
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #send(path, body, _log_type) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/graphql-hive/client.rb', line 10 def initialize() @options = end |
Instance Method Details
#send(path, body, _log_type) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/graphql-hive/client.rb', line 14 def send(path, body, _log_type) uri = URI::HTTP.build( scheme: @options[:port].to_s == '443' ? 'https' : 'http', host: @options[:endpoint] || 'app.graphql-hive.com', port: @options[:port] || '443', path: path ) http = ::Net::HTTP.new(uri.host, uri.port) http.use_ssl = @options[:port].to_s == '443' http.read_timeout = 2 request = Net::HTTP::Post.new(uri.request_uri) request['content-type'] = 'application/json' request['x-api-token'] = @options[:token] request['User-Agent'] = "Hive@#{Graphql::Hive::VERSION}" request['graphql-client-name'] = 'Hive Ruby Client' request['graphql-client-version'] = Graphql::Hive::VERSION request.body = JSON.generate(body) response = http.request(request) @options[:logger].debug(response.inspect) @options[:logger].debug(response.body.inspect) rescue StandardError => e @options[:logger].fatal("Failed to send data: #{e}") end |