mooncats-graphql 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +0 -1
- data/README.md +48 -3
- data/Rakefile +1 -0
- data/lib/mooncats/graphql.rb +1 -10
- data/lib/mooncats/graphql/query.rb +13 -8
- data/lib/mooncats/graphql/version.rb +1 -1
- metadata +16 -3
- data/lib/mooncats/graphql/client.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2248752fa435f14b9b0119a7755e74a28f0eba5569c43dd696d9ab35bf50224a
|
4
|
+
data.tar.gz: 522ec4a1c519bf114ea679f6bb7383adaa083497d205a036a0b5b1f18a6c4619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19bc629d7bf8d8af8787bdca9b969b9c58f290c31432ffc07198269c95f686e3f0b57a94f383e38dcbd8783ad4eca7d6d32a6b3554c93c1b889923597666e27
|
7
|
+
data.tar.gz: d90f07f91931b65af9e252b375e8472acb46073ba0d7814a8b56f677ed547b2d34e83152260cd4d5877509592e188a5bd2811c34fe47561a333408c154c66ec7
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -24,12 +24,57 @@ require 'mooncats/graphql'
|
|
24
24
|
|
25
25
|
c = Mooncats::GraphQL::Client.new
|
26
26
|
|
27
|
-
data = c.
|
27
|
+
data = c.query( <<GRAPHQL )
|
28
|
+
{
|
29
|
+
cats(first: 12, orderBy: maxAdoptionPrice, orderDirection: desc)
|
30
|
+
{
|
31
|
+
id
|
32
|
+
rescueIndex
|
33
|
+
rescueBlock
|
34
|
+
rescueTime
|
35
|
+
name
|
36
|
+
isGenesis
|
37
|
+
maxAdoptionPrice
|
38
|
+
}
|
39
|
+
}
|
40
|
+
GRAPHQL
|
28
41
|
```
|
29
42
|
|
43
|
+
|
30
44
|
resulting in:
|
31
45
|
|
32
46
|
``` ruby
|
47
|
+
{"data"=>
|
48
|
+
{"cats"=>
|
49
|
+
[{"id"=>"0xff52000ca7",
|
50
|
+
"isGenesis"=>true,
|
51
|
+
"maxAdoptionPrice"=>"55500000000000000000",
|
52
|
+
"name"=>nil,
|
53
|
+
"rescueBlock"=>4363303,
|
54
|
+
"rescueIndex"=>2878,
|
55
|
+
"rescueTime"=>1507932258},
|
56
|
+
{"id"=>"0xff50000ca7",
|
57
|
+
"isGenesis"=>true,
|
58
|
+
"maxAdoptionPrice"=>"55500000000000000000",
|
59
|
+
"name"=>nil,
|
60
|
+
"rescueBlock"=>4363303,
|
61
|
+
"rescueIndex"=>2876,
|
62
|
+
"rescueTime"=>1507932258},
|
63
|
+
#...
|
64
|
+
]
|
65
|
+
}
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
Or use pre-configured / built-in queries. Example:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
data = c.query_bestsellers( first: 12 )
|
73
|
+
```
|
74
|
+
|
75
|
+
resulting in:
|
76
|
+
|
77
|
+
```ruby
|
33
78
|
[{"id" => "0xff52000ca7",
|
34
79
|
"isGenesis" => true,
|
35
80
|
"maxAdoptionPrice" => "55500000000000000000",
|
@@ -48,9 +93,9 @@ resulting in:
|
|
48
93
|
]
|
49
94
|
```
|
50
95
|
|
51
|
-
Note: Depending on the query either a data array (zero, one or more records)
|
96
|
+
Note: Depending on the pre-defined / built-in query either a data array (zero, one or more records)
|
52
97
|
e.g. `query_bestsellers`
|
53
|
-
or a hash table or nil
|
98
|
+
or a hash table or nil (one or no record) e.g. `query_cat_by_id`
|
54
99
|
gets returned. Use like:
|
55
100
|
|
56
101
|
|
data/Rakefile
CHANGED
data/lib/mooncats/graphql.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
require 'net/https'
|
3
|
-
require 'uri'
|
4
|
-
require 'json'
|
5
|
-
require 'yaml'
|
6
|
-
require 'date'
|
7
|
-
require 'time'
|
8
|
-
require 'fileutils'
|
9
|
-
require 'pp'
|
1
|
+
require 'webclient'
|
10
2
|
|
11
3
|
|
12
4
|
|
13
5
|
## our own code
|
14
6
|
require 'mooncats/graphql/version' # note: let version always go first
|
15
|
-
require 'mooncats/graphql/client'
|
16
7
|
require 'mooncats/graphql/query'
|
17
8
|
|
18
9
|
|
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
2
|
module Mooncats
|
3
3
|
module GraphQL
|
4
|
-
|
5
|
-
class Client < ::Mooncats::Client
|
6
|
-
def initialize
|
7
|
-
super( base_uri: 'https://api.thegraph.com/subgraphs/name/merklejerk/moon-cats-rescue' )
|
8
|
-
end
|
4
|
+
class Client
|
9
5
|
|
10
6
|
|
11
7
|
def query_bestsellers( first: 100,
|
@@ -275,6 +271,8 @@ GRAPHQL
|
|
275
271
|
|
276
272
|
#####
|
277
273
|
# generic query via HTTP POST
|
274
|
+
BASE_URL = 'https://api.thegraph.com/subgraphs/name/merklejerk/moon-cats-rescue'
|
275
|
+
|
278
276
|
def query( query, includes: [] )
|
279
277
|
if includes.size > 0
|
280
278
|
## check for end-of-line comments with @INCLUDES marker
|
@@ -282,12 +280,19 @@ GRAPHQL
|
|
282
280
|
includes.join( ' ' ) )
|
283
281
|
end
|
284
282
|
|
285
|
-
post(
|
286
|
-
|
283
|
+
res = Webclient.post( BASE_URL, json: {
|
284
|
+
query: query } )
|
287
285
|
|
286
|
+
if res.status.nok? ## e.g. != 200
|
287
|
+
puts "!! ERROR: HTTP #{res.status.code} #{res.status.message}:"
|
288
|
+
pp res.raw ## note: dump inner (raw) response (NOT the wrapped)
|
289
|
+
exit 1
|
290
|
+
end
|
291
|
+
|
292
|
+
res.json ## return body (utf-8 enconded text) parsed as json
|
293
|
+
end
|
288
294
|
|
289
295
|
end # class Client
|
290
296
|
end # module GraphQL
|
291
297
|
end # module Mooncats
|
292
298
|
|
293
|
-
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mooncats-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rdoc
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,7 +73,6 @@ files:
|
|
59
73
|
- Rakefile
|
60
74
|
- lib/mooncats-graphql.rb
|
61
75
|
- lib/mooncats/graphql.rb
|
62
|
-
- lib/mooncats/graphql/client.rb
|
63
76
|
- lib/mooncats/graphql/query.rb
|
64
77
|
- lib/mooncats/graphql/version.rb
|
65
78
|
homepage: https://github.com/cryptocopycats/mooncats
|
@@ -1,43 +0,0 @@
|
|
1
|
-
|
2
|
-
module Mooncats
|
3
|
-
class Client
|
4
|
-
|
5
|
-
|
6
|
-
def initialize( base_uri: )
|
7
|
-
@base_uri = base_uri
|
8
|
-
end
|
9
|
-
|
10
|
-
def post( **params )
|
11
|
-
|
12
|
-
uri = URI.parse( @base_uri )
|
13
|
-
res = Net::HTTP.start( uri.host, uri.port,
|
14
|
-
use_ssl: true) do |http|
|
15
|
-
req = Net::HTTP::Post.new( uri )
|
16
|
-
req['Content-Type'] = 'application/json'
|
17
|
-
|
18
|
-
# note: the body needs to be a JSON string
|
19
|
-
req.body = JSON.generate( params )
|
20
|
-
|
21
|
-
# puts
|
22
|
-
# puts "graphql post:"
|
23
|
-
# puts req.body
|
24
|
-
# puts "---"
|
25
|
-
|
26
|
-
http.request( req )
|
27
|
-
end
|
28
|
-
|
29
|
-
if res.code.to_i != 200
|
30
|
-
puts "!! ERROR: HTTP #{res.code} #{res.message}:"
|
31
|
-
pp res
|
32
|
-
exit 1
|
33
|
-
end
|
34
|
-
|
35
|
-
body = res.body.to_s
|
36
|
-
## note: assumes ascii-8bit/binary encoding (by default)
|
37
|
-
## change to utf-8 (as always required by json )
|
38
|
-
body = body.force_encoding( Encoding::UTF_8 )
|
39
|
-
|
40
|
-
data = JSON.parse( body )
|
41
|
-
end
|
42
|
-
end # class Client
|
43
|
-
end # module Mooncats
|