repltalk 0.0.4 → 0.1.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 +79 -11
  3. data/lib/repltalk.rb +37 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 640639f4f0a1f4ab9ba6dab62ab76813e3b1aaab87083c584392dd981042f630
4
- data.tar.gz: cacc2efc694130135eafa0ea768c696875a5c14ba4fad8d6fed42e67985f1da3
3
+ metadata.gz: b5eda6889050be862c69fbce525ca2142b3eb85a976bfba0bb1e2b200da95caf
4
+ data.tar.gz: e2d69baf3f93e97e9d8058db4902d9e3a0b4dd45d3e81eb3c72bb141f9b20cdb
5
5
  SHA512:
6
- metadata.gz: 298f683ee539b0a13afc39d60abb1b3bde2b003aea988632109e5f8e33ce64932fe2db2ac7f3aeabceb00e1e1db9526adad5e221c5919a81b20827350f0faadc
7
- data.tar.gz: 005e485bd1f425971fe02d654694b70282d6b8843d8acca964c7a26b454b3fc31a078e328ae072d06a6faffb12e9bc2168a67f14d958b6743ebc9a58fa4dac26
6
+ metadata.gz: 19af26777de115b60947660b54e9ddc3ff1aae1ad95ca6f66f3422f22437d1e6abe12592864c6b16aa82aad80c6141a4132b73a50b6454c123293bd8f75c8d42
7
+ data.tar.gz: 59a1b5c592b20b369cd86376ce2ad11708c74750f94311c861011998f97707b0e3620f31b38991f652818795da1cc04f1f64831a606d59c5e8cc88f155619e73
data/lib/queries.rb CHANGED
@@ -165,12 +165,6 @@ class Queries
165
165
  color
166
166
  __typename
167
167
  }
168
- recentComments(count: 3) {
169
- id
170
- ...SimpleCommentComment
171
- __typename
172
- }
173
- __typename
174
168
  }
175
169
 
176
170
  fragment PostVoteControlPost on Post {
@@ -220,18 +214,92 @@ class Queries
220
214
  __typename
221
215
  }
222
216
  __typename
217
+ }"
218
+ end
219
+
220
+ def Queries.get_user_comments
221
+ "query ProfileComments($username: String!, $after: String, $order: String, $count: Int) {
222
+ user: userByUsername(username: $username) {
223
+ id
224
+ displayName
225
+ comments(after: $after, order: $order, count: $count) {
226
+ items {
227
+ id
228
+ ...ProfileCommentsComment
229
+ __typename
230
+ }
231
+ pageInfo {
232
+ nextCursor
233
+ __typename
234
+ }
235
+ __typename
236
+ }
237
+ __typename
238
+ }
223
239
  }
224
240
 
225
- fragment SimpleCommentComment on Comment {
241
+ fragment ProfileCommentsComment on Comment {
226
242
  id
243
+ body
244
+ timeCreated
245
+ url
246
+ ...CommentVoteControlComment
227
247
  user {
228
248
  id
229
- ...UserLabelUser
230
- ...UserLinkUser
249
+ fullName
250
+ username
251
+ image
252
+ bio
253
+ karma
254
+ isHacker
255
+ roles {
256
+ id
257
+ name
258
+ key
259
+ tagline
260
+ __typename
261
+ }
262
+ organization {
263
+ id
264
+ name
265
+ __typename
266
+ }
267
+ languages {
268
+ id
269
+ key
270
+ displayName
271
+ tagline
272
+ icon
273
+ __typename
274
+ }
275
+ }
276
+ post {
277
+ id
278
+ title
279
+ url
280
+ user {
281
+ id
282
+ username
283
+ url
284
+ __typename
285
+ }
286
+ board {
287
+ id
288
+ name
289
+ url
290
+ slug
291
+ __typename
292
+ }
231
293
  __typename
232
294
  }
233
- preview(removeMarkdown: true, length: 500)
234
- timeCreated
295
+ __typename
296
+ }
297
+
298
+ fragment CommentVoteControlComment on Comment {
299
+ id
300
+ voteCount
301
+ canVote
302
+ hasVoted
235
303
  __typename
236
304
  }"
237
305
  end
data/lib/repltalk.rb CHANGED
@@ -78,6 +78,27 @@ class Board
78
78
  end
79
79
  end
80
80
 
81
+ class Comment
82
+ attr_reader :id, :url, :author, :content, :vote_count, :can_vote, :has_voted
83
+
84
+ def initialize(client, comment)
85
+ @client = client
86
+
87
+ @id = comment["id"]
88
+ @url = comment["url"]
89
+ @author = User.new(@client, comment["user"])
90
+ @content = comment["body"]
91
+ @vote_count = comment["voteCount"]
92
+
93
+ @can_vote = comment["canVote"]
94
+ @has_voted = comment["hasVoted"]
95
+ end
96
+
97
+ def to_s
98
+ @content
99
+ end
100
+ end
101
+
81
102
  class Post
82
103
  attr_reader :id, :url, :repl, :board, :title, :author, :content, :preview, :timestamp, :vote_count, :comment_count, :can_vote, :has_voted, :is_anwered, :is_answerable, :is_hidden, :is_pinned, :is_locked, :is_announcement
83
104
 
@@ -133,7 +154,7 @@ class User
133
154
  @languages = user["languages"].map { |lang| Language.new(lang) }
134
155
  end
135
156
 
136
- def get_posts(order="top", count=nil, after=nil)
157
+ def get_posts(order: "new", count: nil, after: nil)
137
158
  p = @client.graphql(
138
159
  "ProfilePosts",
139
160
  Queries.get_user_posts,
@@ -143,12 +164,24 @@ class User
143
164
  after: after
144
165
  )
145
166
  posts = Array.new
146
- p["user"]["posts"]["items"].each do |post|
147
- posts << Post.new(@client, post)
148
- end
167
+ p["user"]["posts"]["items"].each { |post| posts << Post.new(@client, post) }
149
168
  posts
150
169
  end
151
170
 
171
+ def get_comments(order: "new", count: nil, after: nil)
172
+ c = @client.graphql(
173
+ "ProfileComments",
174
+ Queries.get_user_comments,
175
+ username: @username,
176
+ order: order,
177
+ count: count,
178
+ after: after
179
+ )
180
+ comments = Array.new
181
+ c["user"]["comments"]["items"].each { |comment| comments << Comment.new(@client, comment) }
182
+ comments
183
+ end
184
+
152
185
  def to_s
153
186
  @username
154
187
  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.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodingCactus