Class: Github::GraphQL
- Inherits:
-
Object
- Object
- Github::GraphQL
- Defined in:
- lib/github/graphql.rb
Overview
Used to Query the Github GraphQL API
Instance Method Summary collapse
-
#initialize(token, query, vars) ⇒ GraphQL
constructor
A new instance of GraphQL.
- #payload(query, vars) ⇒ Object
- #query ⇒ Object
- #token(token) ⇒ Object
Constructor Details
#initialize(token, query, vars) ⇒ GraphQL
Returns a new instance of GraphQL.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/github/graphql.rb', line 9 def initialize(token, query, vars) @payload = {} uri = URI.parse('https://api.github.com/graphql') @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true @request = Net::HTTP::Post.new(uri) @request['Content-type'] = 'application/json' token(token) payload(query, vars) end |
Instance Method Details
#payload(query, vars) ⇒ Object
27 28 29 30 31 |
# File 'lib/github/graphql.rb', line 27 def payload(query, vars) @payload['query'] = query @payload['variables'] = vars @request.body = @payload.to_json end |
#query ⇒ Object
33 34 35 36 |
# File 'lib/github/graphql.rb', line 33 def query response = @http.request(@request) JSON.parse(response.body) end |
#token(token) ⇒ Object
23 24 25 |
# File 'lib/github/graphql.rb', line 23 def token(token) @request['Authorization'] = "bearer #{token}" end |