repltalk 0.4.3 → 0.5.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 +117 -54
  3. data/lib/repltalk.rb +103 -7
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56aa983cc7fe53b0a33e5c75c7b60b2136630286f2c7f599dc8ce76ca8d40041
4
- data.tar.gz: 893866d5aa136f6f429257bbc0b1f6aae8284d75154109f2a575fbd3e0e2e507
3
+ metadata.gz: 4becb6db34fded69130f61fe1c0bee4eadd9d9aa2e1e832c48f84a51e48f013d
4
+ data.tar.gz: 348eb30ee7f72b57de14f7a3edcd6b99d0c4b48bee827e29e540e30aaafbb4c9
5
5
  SHA512:
6
- metadata.gz: f4a44b90f04b1a51fec9039b5c4d7098643870dbd7e2f755f0ce253f91e38b9cd03e1d37b346ee165bf942cedcae9a890d057afd1dc8200575af771fbe98587b
7
- data.tar.gz: 727e37ffcbf3f09ac706c443b4c8aa219e250ff5cd8285b21a40737a76285a3c7fe0eb69094fe1adbadfb46d9403d67ea39e2e70921e2bb981c0cd2997345ed7
6
+ metadata.gz: 62fc89da26c4217cdddc3f6c7f472197480f32173d83137189219566b27fe9bdf1559ae77f32df43e43dffd46741cd1a02d582f3f487ab68520f729f0a396536
7
+ data.tar.gz: 899726ce8b541957128993cff59183a8945d4173b5daf02e18fbdb07d38b888d6dbe3132f463471a9793b7a99fe9b63dd611fb3b3c112f776c08ef22fbbd3319
data/lib/queries.rb CHANGED
@@ -50,6 +50,7 @@ class Queries
50
50
  url
51
51
  title
52
52
  description
53
+ imageUrl
53
54
  isPrivate
54
55
  isAlwaysOn
55
56
  lang {
@@ -60,6 +61,35 @@ class Queries
60
61
  }
61
62
  "
62
63
 
64
+ @@comment = "
65
+ id
66
+ body
67
+ timeCreated
68
+ url
69
+ isAnswer
70
+ voteCount
71
+ canVote
72
+ hasVoted
73
+ user {
74
+ #{@@user}
75
+ }
76
+ post {
77
+ id
78
+ }
79
+ "
80
+
81
+ @@repl_comment = "
82
+ id
83
+ body
84
+ timeCreated
85
+ user {
86
+ #{@@user}
87
+ }
88
+ repl {
89
+ #{@@repl}
90
+ }
91
+ "
92
+
63
93
  @@post = "
64
94
  id
65
95
  title
@@ -86,22 +116,8 @@ class Queries
86
116
  board {
87
117
  #{@@board}
88
118
  }
89
- "
90
-
91
- @@comment = "
92
- id
93
- body
94
- timeCreated
95
- url
96
- isAnswer
97
- voteCount
98
- canVote
99
- hasVoted
100
- user {
101
- #{@@user}
102
- }
103
- post {
104
- id
119
+ answer {
120
+ #{@@comment}
105
121
  }
106
122
  "
107
123
 
@@ -123,7 +139,7 @@ class Queries
123
139
  end
124
140
 
125
141
  def Queries.get_user_posts
126
- "query ProfilePosts($username: String!, $after: String, $order: String, $count: Int) {
142
+ "query user($username: String!, $after: String, $order: String, $count: Int) {
127
143
  user: userByUsername(username: $username) {
128
144
  posts(after: $after, order: $order, count: $count) {
129
145
  items {
@@ -135,7 +151,7 @@ class Queries
135
151
  end
136
152
 
137
153
  def Queries.get_user_comments
138
- "query ProfileComments($username: String!, $after: String, $order: String, $count: Int) {
154
+ "query user($username: String!, $after: String, $order: String, $count: Int) {
139
155
  user: userByUsername(username: $username) {
140
156
  comments(after: $after, order: $order, count: $count) {
141
157
  items {
@@ -146,6 +162,18 @@ class Queries
146
162
  }"
147
163
  end
148
164
 
165
+ def Queries.get_user_repls
166
+ "query user($username: String!, $count: Int, $order: String, $direction: String, $before: String, $after: String, $pinnedReplsFirst: Boolean, $showUnnamed: Boolean) {
167
+ user: userByUsername(username: $username) {
168
+ publicRepls(count: $count, order: $order, direction: $direction, before: $before, after: $after, pinnedReplsFirst: $pinnedReplsFirst, showUnnamed: $showUnnamed) {
169
+ items {
170
+ #{@@repl}
171
+ }
172
+ }
173
+ }
174
+ }"
175
+ end
176
+
149
177
  def Queries.get_post
150
178
  "query post($id: Int!) {
151
179
  post(id: $id) {
@@ -166,6 +194,20 @@ class Queries
166
194
  }"
167
195
  end
168
196
 
197
+ def Queries.get_posts_upvoters
198
+ "query post($id: Int!, $count: Int) {
199
+ post(id: $id) {
200
+ votes(count: $count) {
201
+ items {
202
+ user {
203
+ #{@@user}
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }"
209
+ end
210
+
169
211
  def Queries.get_comment
170
212
  "query comment ($id: Int!) {
171
213
  comment(id: $id) {
@@ -174,53 +216,74 @@ class Queries
174
216
  }"
175
217
  end
176
218
 
177
- def Queries.get_posts
178
- "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
179
- posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
180
- items {
181
- #{@@post}
219
+ def Queries.get_comments_comments
220
+ "query comment ($id: Int!) {
221
+ comment(id: $id) {
222
+ comments {
223
+ #{@@comment}
182
224
  }
183
225
  }
184
226
  }"
185
227
  end
186
228
 
187
- def Queries.get_leaderboard
188
- "query LeaderboardQuery($after: String, $since: KarmaSince) {
189
- leaderboard(after: $after, since: $since) {
190
- items {
229
+ def Queries.get_parent_comment
230
+ "query comment ($id: Int!) {
231
+ comment(id: $id) {
232
+ parentComment {
233
+ #{@@comment}
191
234
  }
192
235
  }
193
- }
236
+ }"
237
+ end
194
238
 
195
- fragment UserLabelWithImageUser on User {
196
- id
197
- image
198
- ...UserLabelUser
199
- __typename
200
- }
239
+ def Queries.get_repl
240
+ "query ReplView($url: String!) {
241
+ repl(url: $url) {
242
+ ... on Repl {
243
+ #{@@repl}
244
+ }
245
+ }
246
+ }"
247
+ end
201
248
 
202
- fragment UserLabelUser on User {
203
- id
204
- username
205
- karma
206
- ...UserLinkUser
207
- __typename
208
- }
249
+ def Queries.get_repl_forks
250
+ "query ReplViewForks($url: String!, $count: Int!, $after: String) {
251
+ repl(url: $url) {
252
+ ... on Repl {
253
+ publicForks(count: $count, after: $after) {
254
+ items {
255
+ #{@@repl}
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }"
261
+ end
209
262
 
210
- fragment UserLinkUser on User {
211
- id
212
- url
213
- username
214
- __typename
215
- }
263
+ def Queries.get_repl_comments
264
+ "query ReplViewComments($url: String!, $count: Int, $after: String) {
265
+ repl(url: $url) {
266
+ ... on Repl {
267
+ comments(count: $count, after: $after) {
268
+ items {
269
+ #{@@repl_comment}
270
+ replies {
271
+ #{@@repl_comment}
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ }"
278
+ end
216
279
 
217
- fragment TopLeaderUser on User {
218
- id
219
- username
220
- karmaSince: karma(since: $since)
221
- ...UserLabelWithImageUser
222
- ...UserLinkUser
223
- __typename
280
+ def Queries.get_posts
281
+ "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
282
+ posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
283
+ items {
284
+ #{@@post}
285
+ }
286
+ }
224
287
  }"
225
288
  end
226
289
  end
data/lib/repltalk.rb CHANGED
@@ -53,8 +53,28 @@ end
53
53
 
54
54
 
55
55
 
56
+ class ReplComment
57
+ attr_reader :id, :content, :author, :repl, :replies
58
+
59
+ def initialize(client, comment)
60
+ @client = client
61
+
62
+ @id = comment["id"]
63
+ @content = comment["body"]
64
+ @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
65
+ @repl = Repl.new(@client, comment["repl"])
66
+ @replies = comment["replies"] == nil ? nil : comment["replies"].map { |c| ReplComment.new(@client, c) }
67
+ end
68
+
69
+ def to_s
70
+ @content
71
+ end
72
+ end
73
+
74
+
75
+
56
76
  class Repl
57
- attr_reader :id, :url, :title, :author, :description, :language, :is_private, :is_always_on
77
+ attr_reader :id, :url, :title, :author, :description, :language, :img_url, :is_private, :is_always_on
58
78
 
59
79
  def initialize(client, repl)
60
80
  @client = client
@@ -65,11 +85,34 @@ class Repl
65
85
  @author = User.new(@client, repl["user"])
66
86
  @description = repl["description"]
67
87
  @language = Language.new(repl["lang"])
88
+ @image_url = repl["imageUrl"]
68
89
 
69
90
  @is_private = repl["isPrivate"]
70
91
  @is_always_on = repl["isAlwaysOn"]
71
92
  end
72
93
 
94
+ def get_forks(count: 100, after: nil)
95
+ f = @client.graphql(
96
+ "ReplViewForks",
97
+ Queries.get_repl_forks,
98
+ url: @url,
99
+ count: count,
100
+ after: after
101
+ )
102
+ f["repl"]["publicForks"]["items"].map { |repl| Repl.new(@client, repl) }
103
+ end
104
+
105
+ def get_comments(count: nil, after: nil)
106
+ c = @client.graphql(
107
+ "ReplViewComments",
108
+ Queries.get_repl_comments,
109
+ url: @url,
110
+ count: count,
111
+ after: after
112
+ )
113
+ c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
114
+ end
115
+
73
116
  def to_s
74
117
  @title
75
118
  end
@@ -94,7 +137,7 @@ end
94
137
 
95
138
 
96
139
  class Comment
97
- attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :comments, :can_vote, :has_voted
140
+ attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :can_vote, :has_voted
98
141
 
99
142
  def initialize(client, comment)
100
143
  @client = client
@@ -107,7 +150,6 @@ class Comment
107
150
  @is_answer = comment["isAnswer"]
108
151
  @vote_count = comment["voteCount"]
109
152
  @timestamp = comment["timeCreated"]
110
- @comments = comment.include?("comments") ? comment["comments"].map { |c| Comment.new(@client, c)} : Array.new
111
153
 
112
154
  @can_vote = comment["canVote"]
113
155
  @has_voted = comment["hasVoted"]
@@ -119,7 +161,25 @@ class Comment
119
161
  Queries.get_post,
120
162
  id: @post_id
121
163
  )
122
- Post.new(self, p["post"])
164
+ Post.new(@client, p["post"])
165
+ end
166
+
167
+ def get_comments
168
+ c = @client.graphql(
169
+ "comment",
170
+ Queries.get_comments_comments,
171
+ id: @id
172
+ )
173
+ c["comment"]["comments"].map { |comment| Comment.new(@client, comment) }
174
+ end
175
+
176
+ def get_parent
177
+ c = @client.graphql(
178
+ "comment",
179
+ Queries.get_parent_comment,
180
+ id: @id
181
+ )
182
+ c["comment"]["parentComment"] == nil ? nil : Comment.new(@client, c["comment"]["parentComment"])
123
183
  end
124
184
 
125
185
  def to_s
@@ -130,7 +190,7 @@ end
130
190
 
131
191
 
132
192
  class Post
133
- attr_reader :id, :url, :repl, :board, :title, :author, :content, :preview, :timestamp, :vote_count, :comment_count, :can_vote, :has_voted, :is_answered, :is_answerable, :is_hidden, :is_pinned, :is_locked, :is_announcement
193
+ attr_reader :id, :url, :repl, :board, :title, :author, :answer, :content, :preview, :timestamp, :vote_count, :comment_count, :can_vote, :has_voted, :is_answered, :is_answerable, :is_hidden, :is_pinned, :is_locked, :is_announcement
134
194
 
135
195
  def initialize(client, post)
136
196
  @client = client
@@ -145,6 +205,7 @@ class Post
145
205
  @board = Board.new(post["board"])
146
206
  @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
147
207
  @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
208
+ @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
148
209
 
149
210
  @vote_count = post["voteCount"]
150
211
  @comment_count = post["commentCount"]
@@ -173,6 +234,16 @@ class Post
173
234
  c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
174
235
  end
175
236
 
237
+ def get_upvotes(count: nil)
238
+ u = @client.graphql(
239
+ "post",
240
+ Queries.get_posts_upvoters,
241
+ id: @id,
242
+ count: count
243
+ )
244
+ u["post"]["votes"]["items"].map { |vote| User.new(@client, vote["user"]) }
245
+ end
246
+
176
247
  def to_s
177
248
  @title
178
249
  end
@@ -201,7 +272,7 @@ class User
201
272
 
202
273
  def get_posts(order: "new", count: nil, after: nil)
203
274
  p = @client.graphql(
204
- "ProfilePosts",
275
+ "user",
205
276
  Queries.get_user_posts,
206
277
  username: @username,
207
278
  order: order,
@@ -213,7 +284,7 @@ class User
213
284
 
214
285
  def get_comments(order: "new", count: nil, after: nil)
215
286
  c = @client.graphql(
216
- "ProfileComments",
287
+ "user",
217
288
  Queries.get_user_comments,
218
289
  username: @username,
219
290
  order: order,
@@ -223,6 +294,22 @@ class User
223
294
  c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
224
295
  end
225
296
 
297
+ def get_repls(count: nil, order: nil, direction: nil, before: nil, after: nil, pinnedReplsFirst: nil, showUnnamed: nil)
298
+ r = @client.graphql(
299
+ "user",
300
+ Queries.get_user_repls,
301
+ username: @username,
302
+ order: order,
303
+ count: count,
304
+ direction: direction,
305
+ before: before,
306
+ after: after,
307
+ pinnedReplsFirst: pinnedReplsFirst,
308
+ showUnnamed: showUnnamed
309
+ )
310
+ r["user"]["publicRepls"]["items"].map { |repl| Repl.new(@client, repl) }
311
+ end
312
+
226
313
  def to_s
227
314
  @username
228
315
  end
@@ -303,6 +390,15 @@ class Client
303
390
  )
304
391
  Comment.new(self, c["comment"])
305
392
  end
393
+
394
+ def get_repl(url)
395
+ r = graphql(
396
+ "ReplView",
397
+ Queries.get_repl,
398
+ url: url
399
+ )
400
+ Repl.new(self, r["repl"])
401
+ end
306
402
 
307
403
  def get_posts(board: "all", order: "new", count: nil, after: nil, search: nil, languages: nil)
308
404
  p = graphql(
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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodingCactus