cryptopunks-graphql 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 791e8ee6cf7734f5f4080c4886dfec62bcb0c8eb260be868b5a9957429a5a99b
4
- data.tar.gz: 2502826afbd6e3c2bf5db221fb0dd604e0442e409fc55b4163336cbbee029302
3
+ metadata.gz: bab41469a74296532a03010415aae831dec7cc767b6479a8c2d8351cb7eb3484
4
+ data.tar.gz: bea7f25896596d5584817b50338c79e8aaf7a9e5e9b6087929dafd365e562816
5
5
  SHA512:
6
- metadata.gz: c54a379c06ca46f1db1d1faa80899e5ec430d4a3d45f802be16083fb65463db69883b3c821c535de463d2ad760dfc938d536628602d3b9a9335bea05841c8678
7
- data.tar.gz: 0ec231917f9c9299084b68170d5b50ee374306ffb6b326a41c9b15b8422400c74392d38966a09b8f6d365882a98250f572f4d29468800768044343284ceb746d
6
+ metadata.gz: 4fcba9660bb897a7dc8cda07ce731ed99ac9b2af87af86b25eafa400671062fd5cc75bc44214f5e06b4a8e79c974074078b64170050ce1cef0003ca4f6e956f1
7
+ data.tar.gz: 3902266fc8559285741b587423eb1ca5ea5f5e75244c7ef6be684b19c9619d6b6c67e69909806a6407cffb35cfe706c045c5a85b897b62acc6c8afc1c18ffabd
data/Manifest.txt CHANGED
@@ -4,6 +4,5 @@ README.md
4
4
  Rakefile
5
5
  lib/cryptopunks-graphql.rb
6
6
  lib/cryptopunks/graphql.rb
7
- lib/cryptopunks/graphql/client.rb
8
7
  lib/cryptopunks/graphql/query.rb
9
8
  lib/cryptopunks/graphql/version.rb
data/Rakefile CHANGED
@@ -18,6 +18,7 @@ Hoe.spec 'cryptopunks-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 'cryptopunks/graphql/version' # note: let version always go first
15
- require 'cryptopunks/graphql/client'
16
7
  require 'cryptopunks/graphql/query'
17
8
 
18
9
 
@@ -2,14 +2,118 @@
2
2
  module Cryptopunks
3
3
  module GraphQL
4
4
 
5
- class Client < ::Cryptopunks::Client
6
- def initialize
7
- super( base_uri: 'https://api.thegraph.com/subgraphs/name/itsjerryokolo/cryptopunks' )
8
- end
5
+ class Client
6
+
7
+ def query_transactions( first: 1000,
8
+ last_date: '1498017600' # approximate time of the first cryptopunk transaction
9
+ )
10
+ query = <<GRAPHQL
11
+ {
12
+ transactions( first: $first,
13
+ orderBy: date,
14
+ where: { date_gte: $last_date,
15
+ punk_not: "" } )
16
+ {
17
+ id
18
+ date
19
+ block # done
20
+ }
21
+ }
22
+ GRAPHQL
23
+ query = query.gsub( '$first', first.to_s )
24
+ query = query.gsub( '$last_date', %Q<"#{last_date}"> ) ## note: date is defined as BigInt in GraphQL schema (returned in json as string)
25
+
26
+ data = query( query )
27
+ data['data']['transactions']
28
+ end
29
+ alias_method :query_txns, :query_transactions
30
+
31
+
32
+ def query_transaction_details( block:, id:, date: )
33
+ query = <<GRAPHQL
34
+ {
35
+ transactions( block: { number: $block},
36
+ orderBy: date,
37
+ where: { id: $id,
38
+ date: $date,
39
+ punk_not: ""})
40
+ {
41
+ id
42
+ owner{
43
+ id
44
+ punk
45
+ }
46
+ ctoken
47
+ punkTransfers
48
+ punk {
49
+ id
50
+ owner{
51
+ id
52
+ }
53
+ transferedTo
54
+ assignedTo{
55
+ id
56
+ }
57
+ purchasedBy{
58
+ id
59
+ }
60
+ bid{
61
+ bid
62
+ transaction{
63
+ block
64
+ }
65
+ }
66
+ offer{
67
+ id
68
+ amountOffered
69
+ }
70
+ purchase{
71
+ amount
72
+ seller
73
+ id
74
+ }
75
+ punkTransfer
76
+ }
77
+ assigned
78
+ offer
79
+ {
80
+ id
81
+ offeredBy
82
+ amountOffered
83
+ }
84
+
85
+ bid #done
86
+ {
87
+ id
88
+ owner
89
+ punk
90
+ bidder
91
+ bid
92
+ transaction{
93
+ block
94
+ }
95
+ }
96
+ date # done
97
+ block # done
98
+ }
99
+ }
100
+ GRAPHQL
101
+ query = query.gsub( '$block', block.to_s )
102
+ query = query.gsub( '$id', %Q<"#{id}"> ) ## note: id is defined as BigInt in GraphQL schema (returned in json as string)
103
+ query = query.gsub( '$date', %Q<"#{date}"> ) ## note: date is defined as BigInt in GraphQL schema (returned in json as string)
104
+
105
+ data = query( query )
106
+ data['data']['transactions']
107
+ end
108
+ alias_method :query_txn_details, :query_transaction_details
109
+
110
+
9
111
 
10
112
 
11
113
  #####
12
114
  # generic query via HTTP POST
115
+ BASE_URL = 'https://api.thegraph.com/subgraphs/name/itsjerryokolo/cryptopunks'
116
+
13
117
  def query( query, includes: [] )
14
118
  if includes.size > 0
15
119
  ## check for end-of-line comments with @INCLUDES marker
@@ -17,10 +121,17 @@ module GraphQL
17
121
  includes.join( ' ' ) )
18
122
  end
19
123
 
20
- post( query: query )
21
- end
124
+ res = Webclient.post( BASE_URL, json: {
125
+ query: query } )
22
126
 
127
+ if res.status.nok? ## e.g. != 200
128
+ puts "!! ERROR: HTTP #{res.status.code} #{res.status.message}:"
129
+ pp res.raw ## note: dump inner (raw) response (NOT the wrapped)
130
+ exit 1
131
+ end
23
132
 
133
+ res.json ## return body (utf-8 enconded text) parsed as json
134
+ end
24
135
  end # class Client
25
136
  end # module GraphQL
26
137
  end # module Cryptopunks
@@ -3,7 +3,7 @@ module CryptopunksClient
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: cryptopunks-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-04-04 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/cryptopunks-graphql.rb
61
75
  - lib/cryptopunks/graphql.rb
62
- - lib/cryptopunks/graphql/client.rb
63
76
  - lib/cryptopunks/graphql/query.rb
64
77
  - lib/cryptopunks/graphql/version.rb
65
78
  homepage: https://github.com/cryptopunksnotdead/cryptopunks
@@ -1,43 +0,0 @@
1
-
2
- module Cryptopunks
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 Cryptopunks