kittyverse-graphql 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +8 -0
- data/README.md +244 -0
- data/Rakefile +30 -0
- data/lib/kittyverse-graphql.rb +7 -0
- data/lib/kittyverse/graphql.rb +15 -0
- data/lib/kittyverse/graphql/query.rb +34 -0
- data/lib/kittyverse/graphql/version.rb +22 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1172c42ad70884aad3a464f3cb142e7b5033996f477efcca5100b707dd2fbaed
|
4
|
+
data.tar.gz: f346ce7804f251265117be4cb0fcfa800410bd50062ac07d4c259dde58a607a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d56e85fc96a07ca7aaa1fb0aedc51c7724418c312a18b5c8312c008e115215c749ed7c3120c07c6c420aca07aafa89660da69aaa0076583abafade6506fd8750
|
7
|
+
data.tar.gz: 662cd4e936a1eb80a26ead6a91ecfbbe84b8330738352c9a46cbfb598a4382fcbae0a2474228ff603c76e070d08df2b2e7ae97ca3b084d2e56e079cada1aa284
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
# Kittyverse GraphQL (incl. CryptoKitties Sales GraphQL)
|
2
|
+
|
3
|
+
|
4
|
+
kittyverse-graphql - web client (helpers) for using CryptoKitties (HTTP JSON) GraphQL APIs
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
* home :: [github.com/cryptocopycats/kittyverse](https://github.com/cryptocopycats/kittyverse)
|
9
|
+
* bugs :: [github.com/cryptocopycats/kittyverse/issues](https://github.com/cryptocopycats/kittyverse/issues)
|
10
|
+
* gem :: [rubygems.org/gems/kittyverse-graphql](https://rubygems.org/gems/kittyverse-graphql)
|
11
|
+
* rdoc :: [rubydoc.info/gems/kittyverse-graphql](http://rubydoc.info/gems/kittyverse-graphql)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
A lite web client wrapper for the CryptoKitties Sales open graph api
|
19
|
+
powered by the Graph.
|
20
|
+
See [**thegraph.com/explorer/subgraph/nieldlr/cryptokitties-sales »**](https://thegraph.com/explorer/subgraph/nieldlr/cryptokitties-sales).
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
Example - Get the latest kitties sold in auctions:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
require 'kittyverse/graphql'
|
28
|
+
|
29
|
+
c = Kittyverse::GraphQL::Client.new
|
30
|
+
|
31
|
+
data = c.query( <<GRAPHQL )
|
32
|
+
{
|
33
|
+
auctions(first: 10,
|
34
|
+
orderBy: endedAt,
|
35
|
+
orderDirection: desc,
|
36
|
+
where: {state: "sold"})
|
37
|
+
{
|
38
|
+
state
|
39
|
+
soldPrice
|
40
|
+
startedAt
|
41
|
+
endedAt
|
42
|
+
winner
|
43
|
+
cryptoKitty {
|
44
|
+
id
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
GRAPHQL
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
resulting in:
|
53
|
+
|
54
|
+
``` ruby
|
55
|
+
{"data"=>
|
56
|
+
{"auctions"=>
|
57
|
+
[{"cryptoKitty"=>{"id"=>"411361"},
|
58
|
+
"endedAt"=>"1617784066",
|
59
|
+
"soldPrice"=>"5000000000000000",
|
60
|
+
"startedAt"=>"1559543782",
|
61
|
+
"state"=>"sold",
|
62
|
+
"winner"=>"0x201e269455d823b558ba11a2873779a7ea44b599"},
|
63
|
+
{"cryptoKitty"=>{"id"=>"537620"},
|
64
|
+
"endedAt"=>"1617783764",
|
65
|
+
"soldPrice"=>"6000000000000000",
|
66
|
+
"startedAt"=>"1519347485",
|
67
|
+
"state"=>"sold",
|
68
|
+
"winner"=>"0x776d795de3b4726422fea94f0529a570e05998c2"},
|
69
|
+
#...
|
70
|
+
]
|
71
|
+
}
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
75
|
+
Let's pretty print the auction data:
|
76
|
+
|
77
|
+
``` ruby
|
78
|
+
def wei_to_eth( wei )
|
79
|
+
wei_per_eth = 1_000_000_000_000_000_000 ## wei (10^18)
|
80
|
+
Float(wei) / Float(wei_per_eth)
|
81
|
+
end
|
82
|
+
|
83
|
+
def print_sales( recs )
|
84
|
+
puts " price (in eth), price (in wei), date, kitty id, winner\n"
|
85
|
+
recs.each do |rec|
|
86
|
+
print '%f eth ' % wei_to_eth( rec['soldPrice'].to_i )
|
87
|
+
print '(%d wei) ' % rec['soldPrice'].to_i
|
88
|
+
print Time.at( rec['endedAt'].to_i ).utc
|
89
|
+
print " "
|
90
|
+
print "##{rec['cryptoKitty']['id']} "
|
91
|
+
print rec['winner']
|
92
|
+
print "\n"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
print_sales( data['data']['auctions'] )
|
97
|
+
```
|
98
|
+
|
99
|
+
resulting in:
|
100
|
+
|
101
|
+
```
|
102
|
+
price (in eth), price (in wei), date, kitty id, winner
|
103
|
+
0.005000 eth (5000000000000000 wei) 2021-04-07 08:27:46 #411361 0x201e2694...
|
104
|
+
0.006000 eth (6000000000000000 wei) 2021-04-07 08:22:44 #537620 0x776d795d...
|
105
|
+
0.005000 eth (5000000000000000 wei) 2021-04-07 07:42:39 #1641139 0x776d795d...
|
106
|
+
0.012539 eth (12538972095383055 wei) 2021-04-07 07:19:45 #799099 0x48f3d916...
|
107
|
+
0.012580 eth (12579516235413496 wei) 2021-04-07 07:17:52 #1302761 0x48f3d916...
|
108
|
+
0.005000 eth (5000000000000000 wei) 2021-04-07 06:56:57 #405308 0x131b3957...
|
109
|
+
0.009900 eth (9900000000000000 wei) 2021-04-07 03:55:36 #1244187 0xfdf8f7e6...
|
110
|
+
0.005000 eth (5000000000000000 wei) 2021-04-07 03:55:25 #1470744 0xde0515ec...
|
111
|
+
0.005000 eth (5000000000000000 wei) 2021-04-07 03:36:25 #1815178 0xde0515ec...
|
112
|
+
0.012586 eth (12586110096397768 wei) 2021-04-07 03:08:55 #1348108 0x833b59ac...
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
Or let's query for the all-time high.
|
117
|
+
Example - Get the most expensive kitties sold in auctions:
|
118
|
+
|
119
|
+
|
120
|
+
``` ruby
|
121
|
+
data = c.query( <<GRAPHQL )
|
122
|
+
{
|
123
|
+
auctions(first: 10,
|
124
|
+
orderBy: soldPrice,
|
125
|
+
orderDirection: desc,
|
126
|
+
where: {state: "sold"})
|
127
|
+
{
|
128
|
+
state
|
129
|
+
soldPrice
|
130
|
+
endedAt
|
131
|
+
winner
|
132
|
+
cryptoKitty {
|
133
|
+
id
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
GRAPHQL
|
138
|
+
```
|
139
|
+
|
140
|
+
resulting in:
|
141
|
+
|
142
|
+
``` ruby
|
143
|
+
{"data"=>
|
144
|
+
{"auctions"=>
|
145
|
+
[{"cryptoKitty"=>{"id"=>"896775"},
|
146
|
+
"endedAt"=>"1536034886",
|
147
|
+
"soldPrice"=>"600000000000000000000",
|
148
|
+
"state"=>"sold",
|
149
|
+
"winner"=>"0x0e7afeee3a623decb71cf367e86191865ede6c5f"},
|
150
|
+
{"cryptoKitty"=>{"id"=>"18"},
|
151
|
+
"endedAt"=>"1512617298",
|
152
|
+
"soldPrice"=>"253336776620370370370",
|
153
|
+
"state"=>"sold",
|
154
|
+
"winner"=>"0xa6d3fdf423bbc578dd4d41220078475371626b22"},
|
155
|
+
#...
|
156
|
+
]
|
157
|
+
}
|
158
|
+
}
|
159
|
+
```
|
160
|
+
|
161
|
+
Let's pretty print the auction data (again):
|
162
|
+
|
163
|
+
``` ruby
|
164
|
+
print_sales( data['data']['auctions'] )
|
165
|
+
```
|
166
|
+
|
167
|
+
resulting in:
|
168
|
+
|
169
|
+
```
|
170
|
+
price (in eth), price (in wei), date, kitty id, winner
|
171
|
+
600.000000 eth (600000000000000000000 wei) 2018-09-04 04:21:26 #896775 0x0e7afeee...
|
172
|
+
253.336777 eth (253336776620370370370 wei) 2017-12-07 03:28:18 #18 0xa6d3fdf4...
|
173
|
+
247.000000 eth (247000000000000000000 wei) 2017-12-06 19:41:57 #4 0x61a4575d...
|
174
|
+
246.925530 eth (246925530478395061729 wei) 2017-12-02 20:32:36 #1 0x79bd5924...
|
175
|
+
237.522840 eth (237522839506172839507 wei) 2017-12-08 09:31:03 #21 0x58323a0b...
|
176
|
+
225.000000 eth (225000000000000000000 wei) 2017-12-08 09:34:36 #22 0x58323a0b...
|
177
|
+
222.000000 eth (222000000000000000000 wei) 2017-12-05 16:45:01 #5 0x69c94767...
|
178
|
+
190.046825 eth (190046825396825396825 wei) 2017-12-04 19:45:47 #7 0x2ff1e192...
|
179
|
+
188.889654 eth (188889654097222222223 wei) 2017-12-06 07:18:02 #35 0x7ca91be7...
|
180
|
+
179.073438 eth (179073437500000000000 wei) 2017-12-06 18:11:42 #87 0xc3003be6...
|
181
|
+
```
|
182
|
+
|
183
|
+
|
184
|
+
Or let's query for the aggregated totals.
|
185
|
+
Example - Get the aggregated all-time auction totals:
|
186
|
+
|
187
|
+
``` ruby
|
188
|
+
data = c.query( <<GRAPHQL )
|
189
|
+
{
|
190
|
+
aggregation(id: "1") {
|
191
|
+
totalAuctions
|
192
|
+
totalAuctionsSold
|
193
|
+
totalAuctionsCancelled
|
194
|
+
totalUniqueCryptoKittiesAuctioned
|
195
|
+
totalUniqueCryptoKittiesSold
|
196
|
+
totalEtherRevenue
|
197
|
+
}
|
198
|
+
}
|
199
|
+
GRAPHQL
|
200
|
+
```
|
201
|
+
|
202
|
+
resulting in:
|
203
|
+
|
204
|
+
``` ruby
|
205
|
+
{"data"=>
|
206
|
+
{"aggregation"=>
|
207
|
+
{"totalAuctions"=>"1162357",
|
208
|
+
"totalAuctionsCancelled"=>"251887",
|
209
|
+
"totalAuctionsSold"=>"724983",
|
210
|
+
"totalEtherRevenue"=>"63705844622899779521107",
|
211
|
+
"totalUniqueCryptoKittiesAuctioned"=>"807028",
|
212
|
+
"totalUniqueCryptoKittiesSold"=>"595308"}}}
|
213
|
+
```
|
214
|
+
|
215
|
+
And so on and so forth.
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
## New to CryptoKitties?
|
221
|
+
|
222
|
+
See the
|
223
|
+
[**Programming CryptoKitties & Copycats Step-by-Step Booklet / Guide »**](https://github.com/cryptocopycats/programming-cryptokitties)
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
## Install
|
229
|
+
|
230
|
+
Just install the gem:
|
231
|
+
|
232
|
+
$ gem install kittyverse-graphql
|
233
|
+
|
234
|
+
|
235
|
+
## License
|
236
|
+
|
237
|
+
The scripts are dedicated to the public domain.
|
238
|
+
Use it as you please with no restrictions whatsoever.
|
239
|
+
|
240
|
+
|
241
|
+
## Questions? Comments?
|
242
|
+
|
243
|
+
|
244
|
+
Post them on the [cryptokitties reddit](https://www.reddit.com/r/cryptokitties). Thanks.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/kittyverse/graphql/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'kittyverse-graphql' do
|
5
|
+
|
6
|
+
self.version = KittyverseGraphqlClient::VERSION
|
7
|
+
|
8
|
+
self.summary = "kittyverse-graphql - (lite) web client (helpers) for using CryptoKitties (HTTP JSON) GraphQL APIs"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = { home: 'https://github.com/cryptocopycats/kittyverse' }
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'wwwmake@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['webclient'],
|
22
|
+
]
|
23
|
+
|
24
|
+
self.licenses = ['Public Domain']
|
25
|
+
|
26
|
+
self.spec_extras = {
|
27
|
+
required_ruby_version: '>= 2.3'
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module Kittyverse
|
3
|
+
module GraphQL
|
4
|
+
|
5
|
+
class Client
|
6
|
+
|
7
|
+
|
8
|
+
#####
|
9
|
+
# generic query via HTTP POST
|
10
|
+
BASE_URL = 'https://api.thegraph.com/subgraphs/name/nieldlr/cryptokitties-sales'
|
11
|
+
|
12
|
+
def query( query, includes: [] )
|
13
|
+
if includes.size > 0
|
14
|
+
## check for end-of-line comments with @INCLUDES marker
|
15
|
+
query = query.gsub( /[#]+[ ]+@INCLUDES[^\n\r]+/,
|
16
|
+
includes.join( ' ' ) )
|
17
|
+
end
|
18
|
+
|
19
|
+
res = Webclient.post( BASE_URL, json: {
|
20
|
+
query: query } )
|
21
|
+
|
22
|
+
if res.status.nok? ## e.g. != 200
|
23
|
+
puts "!! ERROR: HTTP #{res.status.code} #{res.status.message}:"
|
24
|
+
pp res.raw ## note: dump inner (raw) response (NOT the wrapped)
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
res.json ## return body (utf-8 enconded text) parsed as json
|
29
|
+
end
|
30
|
+
end # class Client
|
31
|
+
end # module GraphQL
|
32
|
+
end # module Kittyverse
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module KittyverseGraphqlClient
|
3
|
+
|
4
|
+
MAJOR = 0
|
5
|
+
MINOR = 0
|
6
|
+
PATCH = 1
|
7
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
8
|
+
|
9
|
+
def self.version
|
10
|
+
VERSION
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.banner
|
14
|
+
"kittyverse-graphql/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in #{root}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.root
|
18
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
|
19
|
+
end
|
20
|
+
|
21
|
+
end # module KittyverseGraphqlClient
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kittyverse-graphql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '7'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '4.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hoe
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.22'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.22'
|
61
|
+
description: kittyverse-graphql - (lite) web client (helpers) for using CryptoKitties
|
62
|
+
(HTTP JSON) GraphQL APIs
|
63
|
+
email: wwwmake@googlegroups.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files:
|
67
|
+
- CHANGELOG.md
|
68
|
+
- Manifest.txt
|
69
|
+
- README.md
|
70
|
+
files:
|
71
|
+
- CHANGELOG.md
|
72
|
+
- Manifest.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/kittyverse-graphql.rb
|
76
|
+
- lib/kittyverse/graphql.rb
|
77
|
+
- lib/kittyverse/graphql/query.rb
|
78
|
+
- lib/kittyverse/graphql/version.rb
|
79
|
+
homepage: https://github.com/cryptocopycats/kittyverse
|
80
|
+
licenses:
|
81
|
+
- Public Domain
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- "--main"
|
86
|
+
- README.md
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.3'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.4
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: kittyverse-graphql - (lite) web client (helpers) for using CryptoKitties
|
104
|
+
(HTTP JSON) GraphQL APIs
|
105
|
+
test_files: []
|