repltalk 0.4.1 → 0.4.2

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 +12 -0
  3. data/lib/repltalk.rb +19 -5
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c6e169fd4bb10c07f2e03fad9d16f8675ddd37cc8f3bb38a65948a557c9c723
4
- data.tar.gz: 92b05683f1c566903c8d08b2c4b9e6dc95eec2c776de8f8bdcd67160229215d8
3
+ metadata.gz: cb325d2217b8b9e4a283dce8405cc1288fb430377d030f7fb201d344e8348f23
4
+ data.tar.gz: 3f35941f2a9d0542bc6c6fb205d9d1bd97c570921b6ab666b4b49aeef9f40c8a
5
5
  SHA512:
6
- metadata.gz: 04f8a5defd2c471633e07fc2ebabf4c99cea2cfaa25ce7809951f8a388346110eaefb171ad335a07a704ac8ca0eea07b602ed70009464ea84f0c8cfeaeaf4684
7
- data.tar.gz: 628cdff810a29a5702e65f1db0e3bed0dc4d17c9446e99dd3d49f3ffcba01e4f4fca0079b109833b5d12910f4d47b8cfe65fd06176fb92c6827f5663ade8c36c
6
+ metadata.gz: 20f4e65ddc1174889fb2767a1b87a1bf3d7ee418094b665e3b8b3de77884f0ddad956aa417b4db134f0fa9a57266dc4f5f6727aa26710a9ca4242fc3a0b79f56
7
+ data.tar.gz: 03d580505be28f0aa190d417ef6a33c4a71f154e15c0a26e196b0fe8e38a3efe4661a53d28a5a0a82cb6a2b0a6ff667e9da57c53bd17f329d6523b5da7075fef
data/lib/queries.rb CHANGED
@@ -154,6 +154,18 @@ class Queries
154
154
  }"
155
155
  end
156
156
 
157
+ def Queries.get_posts_comments
158
+ "query post($postId: Int!, $order: String, $count: Int, $after: String) {
159
+ post(id: $postId) {
160
+ comments(order: $order, count: $count, after: $after) {
161
+ items {
162
+ #{@@comment}
163
+ }
164
+ }
165
+ }
166
+ }"
167
+ end
168
+
157
169
  def Queries.get_comment
158
170
  "query comment ($id: Int!) {
159
171
  comment(id: $id) {
data/lib/repltalk.rb CHANGED
@@ -2,6 +2,8 @@ require "http"
2
2
  require "json"
3
3
  require_relative "queries"
4
4
 
5
+ $BASE_URL = "https://repl.it"
6
+
5
7
  class Role
6
8
  attr_reader :name, :key, :tagline
7
9
 
@@ -58,7 +60,7 @@ class Repl
58
60
  @client = client
59
61
 
60
62
  @id = repl["id"]
61
- @url = repl["url"]
63
+ @url = $BASE_URL + repl["url"]
62
64
  @title = repl["title"]
63
65
  @author = User.new(@client, repl["user"])
64
66
  @description = repl["description"]
@@ -98,7 +100,7 @@ class Comment
98
100
  @client = client
99
101
 
100
102
  @id = comment["id"]
101
- @url = comment["url"]
103
+ @url = $BASE_URL + comment["url"]
102
104
  @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
103
105
  @content = comment["body"]
104
106
  @post_id = comment["post"]["id"]
@@ -134,7 +136,7 @@ class Post
134
136
  @client = client
135
137
 
136
138
  @id = post["id"]
137
- @url = post["url"]
139
+ @url = $BASE_URL + post["url"]
138
140
  @title = post["title"]
139
141
  @content = post["body"]
140
142
  @preview = post["preview"]
@@ -159,6 +161,18 @@ class Post
159
161
  @is_announcement = post["isAnnouncement"]
160
162
  end
161
163
 
164
+ def get_comments(order: "new", count: nil, after: nil)
165
+ c = @client.graphql(
166
+ "post",
167
+ Queries.get_posts_comments,
168
+ postId: @id,
169
+ order: order,
170
+ count: count,
171
+ after: after
172
+ )
173
+ c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
174
+ end
175
+
162
176
  def to_s
163
177
  @title
164
178
  end
@@ -234,11 +248,11 @@ class Client
234
248
  "connect.sid": @sid
235
249
  )
236
250
  .headers(
237
- referer: "https://repl.it/@CodingCactus/repltalk",
251
+ referer: "#{$BASE_URL}/@CodingCactus/repltalk",
238
252
  "X-Requested-With": "ReplTalk"
239
253
  )
240
254
  .post(
241
- "https://repl.it/graphql",
255
+ "#{$BASE_URL}/graphql",
242
256
  form: payload
243
257
  )
244
258
  begin data = JSON.parse(r)
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodingCactus