Class: Kittyverse::GraphQL::Client
- Inherits:
-
Object
- Object
- Kittyverse::GraphQL::Client
- Defined in:
- lib/kittyverse/graphql/query.rb
Constant Summary collapse
- BASE_URL =
generic query via HTTP POST
'https://api.thegraph.com/subgraphs/name/nieldlr/cryptokitties-sales'
Instance Method Summary collapse
Instance Method Details
#query(query, includes: []) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kittyverse/graphql/query.rb', line 12 def query( query, includes: [] ) if includes.size > 0 ## check for end-of-line comments with @INCLUDES marker query = query.gsub( /[#]+[ ]+@INCLUDES[^\n\r]+/, includes.join( ' ' ) ) end res = Webclient.post( BASE_URL, json: { query: query } ) if res.status.nok? ## e.g. != 200 puts "!! ERROR: HTTP #{res.status.code} #{res.status.}:" pp res.raw ## note: dump inner (raw) response (NOT the wrapped) exit 1 end res.json ## return body (utf-8 enconded text) parsed as json end |