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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da57d2e625ff09695d4678abe4b42267b31a951f538bccba41f692973b932585
4
- data.tar.gz: f829e8e7042bfa6269eb844c69f8dffc9c0da8d8c8be0b282a939f3096ae49a2
3
+ metadata.gz: 2248752fa435f14b9b0119a7755e74a28f0eba5569c43dd696d9ab35bf50224a
4
+ data.tar.gz: 522ec4a1c519bf114ea679f6bb7383adaa083497d205a036a0b5b1f18a6c4619
5
5
  SHA512:
6
- metadata.gz: ba9445031e9252911b3b16d9f28a3bf7b566deeab239602ed467b74ad2d4e798f686116a7ef0153d9d1bad5da3fe7863e412f44e62143e74a3beaaa073d5cea0
7
- data.tar.gz: 264bafe762848cdf7627735bfe44735b3b8384003da0a2aa43668e25db1163714ddd6e230c2f83dd98c351ffea1e2a39f8945f629211de34578334251f8700aa
6
+ metadata.gz: b19bc629d7bf8d8af8787bdca9b969b9c58f290c31432ffc07198269c95f686e3f0b57a94f383e38dcbd8783ad4eca7d6d32a6b3554c93c1b889923597666e27
7
+ data.tar.gz: d90f07f91931b65af9e252b375e8472acb46073ba0d7814a8b56f677ed547b2d34e83152260cd4d5877509592e188a5bd2811c34fe47561a333408c154c66ec7
data/Manifest.txt CHANGED
@@ -4,6 +4,5 @@ README.md
4
4
  Rakefile
5
5
  lib/mooncats-graphql.rb
6
6
  lib/mooncats/graphql.rb
7
- lib/mooncats/graphql/client.rb
8
7
  lib/mooncats/graphql/query.rb
9
8
  lib/mooncats/graphql/version.rb
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.query_bestsellers( first: 12 )
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 (one or no record) e.g. `query_cat_by_id`
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
@@ -18,6 +18,7 @@ Hoe.spec 'mooncats-graphql' do
18
18
  self.history_file = 'CHANGELOG.md'
19
19
 
20
20
  self.extra_deps = [
21
+ ['webclient'],
21
22
  ]
22
23
 
23
24
  self.licenses = ['Public Domain']
@@ -1,18 +1,9 @@
1
- require 'net/http'
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( query: query )
286
- end
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
-
@@ -3,7 +3,7 @@ module MooncatsClient
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- PATCH = 0
6
+ PATCH = 1
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
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.0
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-03-31 00:00:00.000000000 Z
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