Module: Tibber::Request::GraphQL

Included in:
API
Defined in:
lib/tibber/request.rb

Overview

JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments. It uses JSON (RFC 4627) as data format.

www.jsonrpc.org/specification

Instance Method Summary collapse

Instance Method Details

#graphql_call(query, params = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tibber/request.rb', line 15

def graphql_call(query, params = nil)
  query = (query % params) if params && params.size > 0
  options = {
    "query": query
  }
  result = post( '', options )
  raise GraphQLError.new(result.body['errors']) if result.body['errors']
  data = result.body['data']
  WrAPI::Request::Entity.create(data['viewer'] ? data['viewer'] : data)

rescue Faraday::BadRequestError => e
  body = e.response[:body]
  if body && body['errors']
    error = body['errors']
  else
    error = e.to_s
  end
  raise GraphQLError.new(error)
end