Class: Cryptopunks::GraphQL::Client
- Inherits:
-
Object
- Object
- Cryptopunks::GraphQL::Client
- Defined in:
- lib/cryptopunks/graphql/query.rb
Constant Summary collapse
- BASE_URL =
generic query via HTTP POST
'https://api.thegraph.com/subgraphs/name/itsjerryokolo/cryptopunks'
Instance Method Summary collapse
- #query(query, includes: []) ⇒ Object
- #query_transaction_details(block:, id:, date:) ⇒ Object (also: #query_txn_details)
- #query_transactions(first: 1000, last_date: '1498017600') ⇒ Object (also: #query_txns)
Instance Method Details
#query(query, includes: []) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cryptopunks/graphql/query.rb', line 117 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.message}:" 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 |
#query_transaction_details(block:, id:, date:) ⇒ Object Also known as: query_txn_details
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cryptopunks/graphql/query.rb', line 32 def query_transaction_details( block:, id:, date: ) query = " {\n transactions( block: { number: $block},\n orderBy: date,\n where: { id: $id,\n date: $date,\n punk_not: \"\"})\n {\n id\n owner{\n id\n punk\n }\n ctoken\n punkTransfers\n punk {\n id\n owner{\n id\n }\n transferedTo\n assignedTo{\n id\n }\n purchasedBy{\n id\n }\n bid{\n bid\n transaction{\n block\n }\n }\n offer{\n id\n amountOffered\n }\n purchase{\n amount\n seller\n id\n }\n punkTransfer\n }\n assigned\n offer\n {\n id\n offeredBy\n amountOffered\n }\n\n bid #done\n {\n id\n owner\n punk\n bidder\n bid\n transaction{\n block\n }\n }\n date # done\n block # done\n }\n }\n" query = query.gsub( '$block', block.to_s ) query = query.gsub( '$id', %Q<"#{id}"> ) ## note: id is defined as BigInt in GraphQL schema (returned in json as string) query = query.gsub( '$date', %Q<"#{date}"> ) ## note: date is defined as BigInt in GraphQL schema (returned in json as string) data = query( query ) data['data']['transactions'] end |
#query_transactions(first: 1000, last_date: '1498017600') ⇒ Object Also known as: query_txns
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cryptopunks/graphql/query.rb', line 7 def query_transactions( first: 1000, last_date: '1498017600' # approximate time of the first cryptopunk transaction ) query = " {\n transactions( first: $first,\n orderBy: date,\n where: { date_gte: $last_date,\n punk_not: \"\" } )\n {\n id\n date\n block # done\n }\n }\n" query = query.gsub( '$first', first.to_s ) query = query.gsub( '$last_date', %Q<"#{last_date}"> ) ## note: date is defined as BigInt in GraphQL schema (returned in json as string) data = query( query ) data['data']['transactions'] end |