Class: GHX::GraphqlClient
- Inherits:
-
Object
- Object
- GHX::GraphqlClient
- Defined in:
- lib/ghx/graphql_client.rb
Overview
Internal class to interact with the GitHub GraphQL API
Instance Method Summary collapse
-
#initialize(api_key) ⇒ GraphqlClient
constructor
A new instance of GraphqlClient.
-
#query(query) ⇒ Net::HTTPResponse
Perform a GraphQL Query and return the result.
Constructor Details
#initialize(api_key) ⇒ GraphqlClient
Returns a new instance of GraphqlClient.
5 6 7 |
# File 'lib/ghx/graphql_client.rb', line 5 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#query(query) ⇒ Net::HTTPResponse
Perform a GraphQL Query and return the result
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ghx/graphql_client.rb', line 12 def query(query) uri = URI("https://api.github.com/graphql") req = Net::HTTP::Post.new(uri) req["Authorization"] = "Bearer #{@api_key}" req["Content-Type"] = "application/json" req.body = {query: query}.to_json Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end end |