repltalk 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/queries.rb +93 -1
  3. data/lib/repltalk.rb +29 -10
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c29ae54ca39ef4007759029d6fe54038a6be1d78899531f28f125f7e005d1da
4
- data.tar.gz: 56b3e5523034aa80ceddd37be953e4ce6f41035cf719c2e1e8472ddfd25c1280
3
+ metadata.gz: 85e8d796ec5d9532272e6ffb20cfa6881e49a38990c13ec58b0f6126974c7d2b
4
+ data.tar.gz: 2a9f9217d0af746f6dcec692e498c248480d68a8f8e1c2851eefa50a07933326
5
5
  SHA512:
6
- metadata.gz: 8583dc5b8e2ea98ae39dc3d1eaa5b8896f9730b877c246a37ef3761c31c3333f259e6e33adf6174dbbf5e8452cc35dfd6f16103bfa8f1cffdbce8259aa960d8b
7
- data.tar.gz: df881342da9575ddaf044a7bc49ad3846470936fed45815365203d57854c271802108d7db505e5114a260ac13ff6f443b8c088cbf6484d688593517bfb938028
6
+ metadata.gz: 449d1a9f1f3a0af88d2d4ab6c316f73f437db0f6fca7d521fdc46b66ad783a2f305fc62ea5f72e2b9624a8a0529e026a8ca590f2ca39a161dc0e8ae41daa0aeb
7
+ data.tar.gz: b37f383cb86062cf2f1a9788e4f2c6456d0f155fb9eb49932fbcbb7c5e55f8caa319549dcff10cf25dad845ddc0b06ade7f760c558995aa2c72492e52dad2daa
data/lib/queries.rb CHANGED
@@ -20,6 +20,7 @@ class Queries
20
20
  bio
21
21
  karma
22
22
  isHacker
23
+ timeCreated
23
24
  roles {
24
25
  id
25
26
  name
@@ -65,6 +66,7 @@ class Queries
65
66
  bio
66
67
  karma
67
68
  isHacker
69
+ timeCreated
68
70
  roles {
69
71
  id
70
72
  name
@@ -193,6 +195,7 @@ class Queries
193
195
  id
194
196
  url
195
197
  username
198
+ timeCreated
196
199
  roles {
197
200
  id
198
201
  name
@@ -243,6 +246,7 @@ class Queries
243
246
  body
244
247
  timeCreated
245
248
  url
249
+ isAnswer
246
250
  ...CommentVoteControlComment
247
251
  user {
248
252
  id
@@ -252,6 +256,7 @@ class Queries
252
256
  bio
253
257
  karma
254
258
  isHacker
259
+ timeCreated
255
260
  roles {
256
261
  id
257
262
  name
@@ -353,7 +358,8 @@ class Queries
353
358
  isAnswerable
354
359
  ...PostVoteControlPost
355
360
  user {
356
- id
361
+ id
362
+ timeCreated
357
363
  roles {
358
364
  id
359
365
  name
@@ -451,4 +457,90 @@ class Queries
451
457
  __typename
452
458
  }"
453
459
  end
460
+
461
+ def Queries.get_comment
462
+ "query comment ($id: Int!) {
463
+ comment(id: $id) {
464
+ id
465
+ url
466
+ isAnswer
467
+ ...CommentDetailComment
468
+ comments {
469
+ id
470
+ url
471
+ isAnswer
472
+ ...CommentDetailComment
473
+ __typename
474
+ }
475
+ __typename
476
+ }
477
+ }
478
+
479
+ fragment DepreciatedUserLabelUser on User {
480
+ id
481
+ fullName
482
+ username
483
+ image
484
+ bio
485
+ karma
486
+ isHacker
487
+ timeCreated
488
+ roles {
489
+ id
490
+ name
491
+ key
492
+ tagline
493
+ __typename
494
+ }
495
+ organization {
496
+ id
497
+ name
498
+ __typename
499
+ }
500
+ languages {
501
+ id
502
+ key
503
+ displayName
504
+ tagline
505
+ icon
506
+ __typename
507
+ }
508
+ __typename
509
+ }
510
+
511
+ fragment CommentDetailComment on Comment {
512
+ id
513
+ body
514
+ timeCreated
515
+ url
516
+ isAnswer
517
+ ...CommentVoteControlComment
518
+ user {
519
+ id
520
+ username
521
+ ...DepreciatedUserLabelWithImageUser
522
+ __typename
523
+ }
524
+ post {
525
+ id
526
+ __typename
527
+ }
528
+ __typename
529
+ }
530
+
531
+ fragment DepreciatedUserLabelWithImageUser on User {
532
+ id
533
+ image
534
+ ...DepreciatedUserLabelUser
535
+ __typename
536
+ }
537
+
538
+ fragment CommentVoteControlComment on Comment {
539
+ id
540
+ voteCount
541
+ canVote
542
+ hasVoted
543
+ __typename
544
+ }"
545
+ end
454
546
  end
data/lib/repltalk.rb CHANGED
@@ -89,21 +89,34 @@ end
89
89
 
90
90
 
91
91
  class Comment
92
- attr_reader :id, :url, :author, :content, :vote_count, :can_vote, :has_voted
92
+ attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :comments, :can_vote, :has_voted
93
93
 
94
94
  def initialize(client, comment)
95
95
  @client = client
96
96
 
97
97
  @id = comment["id"]
98
98
  @url = comment["url"]
99
- @author = User.new(@client, comment["user"])
99
+ @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
100
100
  @content = comment["body"]
101
+ @post_id = comment["post"]["id"]
102
+ @is_answer = comment["isAnswer"]
101
103
  @vote_count = comment["voteCount"]
104
+ @timestamp = comment["timeCreated"]
105
+ @comments = comment.include?("comments") ? comment["comments"].map { |c| Comment.new(@client, c)} : Array.new
102
106
 
103
107
  @can_vote = comment["canVote"]
104
108
  @has_voted = comment["hasVoted"]
105
109
  end
106
110
 
111
+ def get_post
112
+ p = @client.graphql(
113
+ "post",
114
+ Queries.get_post,
115
+ id: @post_id
116
+ )
117
+ Post.new(self, p["post"])
118
+ end
119
+
107
120
  def to_s
108
121
  @content
109
122
  end
@@ -125,8 +138,8 @@ class Post
125
138
  @timestamp = post["timeCreated"]
126
139
 
127
140
  @board = Board.new(post["board"])
128
- @author = User.new(@client, post["user"])
129
141
  @repl = post["repl"] == nil ? nil : Repl.new(post["repl"])
142
+ @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
130
143
 
131
144
  @vote_count = post["voteCount"]
132
145
  @comment_count = post["commentCount"]
@@ -151,7 +164,7 @@ end
151
164
 
152
165
 
153
166
  class User
154
- attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :roles, :organization, :languages
167
+ attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :roles, :organization, :languages
155
168
 
156
169
  def initialize(client, user)
157
170
  @client = client
@@ -163,6 +176,7 @@ class User
163
176
  @bio = user["bio"]
164
177
  @cycles = user["karma"]
165
178
  @is_hacker = user["isHacker"]
179
+ @timestamp = user["timeCreated"]
166
180
  @roles = user["roles"].map { |role| Role.new(role) }
167
181
  @organization = user["organization"] == nil ? nil : Organization.new(user["organization"])
168
182
  @languages = user["languages"].map { |lang| Language.new(lang) }
@@ -177,9 +191,7 @@ class User
177
191
  count: count,
178
192
  after: after
179
193
  )
180
- posts = Array.new
181
- p["user"]["posts"]["items"].each { |post| posts << Post.new(@client, post) }
182
- posts
194
+ p["user"]["posts"]["items"].map { |post| Post.new(@client, post) }
183
195
  end
184
196
 
185
197
  def get_comments(order: "new", count: nil, after: nil)
@@ -191,9 +203,7 @@ class User
191
203
  count: count,
192
204
  after: after
193
205
  )
194
- comments = Array.new
195
- c["user"]["comments"]["items"].each { |comment| comments << Comment.new(@client, comment) }
196
- comments
206
+ c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
197
207
  end
198
208
 
199
209
  def to_s
@@ -263,4 +273,13 @@ class Client
263
273
  )
264
274
  Post.new(self, p["post"])
265
275
  end
276
+
277
+ def get_comment(id)
278
+ c = graphql(
279
+ "comment",
280
+ Queries.get_comment,
281
+ id: id
282
+ )
283
+ Comment.new(self, c["comment"])
284
+ end
266
285
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repltalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodingCactus