repltalk 0.1.0 → 0.4.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/queries.rb +133 -265
  3. data/lib/repltalk.rb +80 -15
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5eda6889050be862c69fbce525ca2142b3eb85a976bfba0bb1e2b200da95caf
4
- data.tar.gz: e2d69baf3f93e97e9d8058db4902d9e3a0b4dd45d3e81eb3c72bb141f9b20cdb
3
+ metadata.gz: 0c6e169fd4bb10c07f2e03fad9d16f8675ddd37cc8f3bb38a65948a557c9c723
4
+ data.tar.gz: 92b05683f1c566903c8d08b2c4b9e6dc95eec2c776de8f8bdcd67160229215d8
5
5
  SHA512:
6
- metadata.gz: 19af26777de115b60947660b54e9ddc3ff1aae1ad95ca6f66f3422f22437d1e6abe12592864c6b16aa82aad80c6141a4132b73a50b6454c123293bd8f75c8d42
7
- data.tar.gz: 59a1b5c592b20b369cd86376ce2ad11708c74750f94311c861011998f97707b0e3620f31b38991f652818795da1cc04f1f64831a606d59c5e8cc88f155619e73
6
+ metadata.gz: 04f8a5defd2c471633e07fc2ebabf4c99cea2cfaa25ce7809951f8a388346110eaefb171ad335a07a704ac8ca0eea07b602ed70009464ea84f0c8cfeaeaf4684
7
+ data.tar.gz: 628cdff810a29a5702e65f1db0e3bed0dc4d17c9446e99dd3d49f3ffcba01e4f4fca0079b109833b5d12910f4d47b8cfe65fd06176fb92c6827f5663ade8c36c
data/lib/queries.rb CHANGED
@@ -1,306 +1,174 @@
1
1
  class Queries
2
- def Queries.get_user
3
- "query userByUsername($username: String!) {
4
- user: userByUsername(username: $username) {
5
- id
6
- username
7
- fullName
8
- image
9
- url
10
- ...ProfileHeaderUser
11
- __typename
12
- }
2
+ @@roles = "
3
+ id
4
+ name
5
+ key
6
+ tagline
7
+ "
8
+
9
+ @@organization = "
10
+ id
11
+ name
12
+ "
13
+
14
+ @@language = "
15
+ id
16
+ key
17
+ displayName
18
+ tagline
19
+ icon
20
+ "
21
+
22
+ @@board = "
23
+ id
24
+ name
25
+ color
26
+ "
27
+
28
+ @@user = "
29
+ id
30
+ fullName
31
+ username
32
+ image
33
+ bio
34
+ karma
35
+ isHacker
36
+ timeCreated
37
+ roles {
38
+ #{@@roles}
39
+ }
40
+ organization {
41
+ #{@@organization}
42
+ }
43
+ languages {
44
+ #{@@language}
13
45
  }
46
+ "
14
47
 
15
- fragment ProfileHeaderUser on User {
48
+ @@repl = "
49
+ id
50
+ url
51
+ title
52
+ description
53
+ isPrivate
54
+ isAlwaysOn
55
+ lang {
56
+ #{@@language}
57
+ }
58
+ user {
59
+ #{@@user}
60
+ }
61
+ "
62
+
63
+ @@post = "
64
+ id
65
+ title
66
+ body
67
+ preview(removeMarkdown: true, length: 150)
68
+ url
69
+ commentCount
70
+ isHidden
71
+ isPinned
72
+ isLocked
73
+ isAnnouncement
74
+ timeCreated
75
+ isAnswered
76
+ isAnswerable
77
+ voteCount
78
+ canVote
79
+ hasVoted
80
+ user {
81
+ #{@@user}
82
+ }
83
+ repl {
84
+ #{@@repl}
85
+ }
86
+ board {
87
+ #{@@board}
88
+ }
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 {
16
104
  id
17
- fullName
18
- username
19
- image
20
- bio
21
- karma
22
- isHacker
23
- roles {
24
- id
25
- name
26
- key
27
- tagline
28
- __typename
29
- }
30
- organization {
31
- id
32
- name
33
- __typename
34
- }
35
- languages {
36
- id
37
- key
38
- displayName
39
- tagline
40
- icon
41
- __typename
105
+ }
106
+ "
107
+
108
+
109
+ def Queries.get_user
110
+ "query userByUsername($username: String!) {
111
+ user: userByUsername(username: $username) {
112
+ #{@@user}
42
113
  }
43
- __typename
44
114
  }"
45
115
  end
46
116
 
47
117
  def Queries.get_user_by_id
48
118
  "query user($user_id: Int!) {
49
119
  user: user(id: $user_id) {
50
- id
51
- username
52
- fullName
53
- image
54
- url
55
- ...ProfileHeaderUser
56
- __typename
57
- }
58
- }
59
-
60
- fragment ProfileHeaderUser on User {
61
- id
62
- fullName
63
- username
64
- image
65
- bio
66
- karma
67
- isHacker
68
- roles {
69
- id
70
- name
71
- key
72
- tagline
73
- __typename
74
- }
75
- organization {
76
- id
77
- name
78
- __typename
120
+ #{@@user}
79
121
  }
80
- languages {
81
- id
82
- key
83
- displayName
84
- tagline
85
- icon
86
- __typename
87
- }
88
- __typename
89
122
  }"
90
123
  end
91
124
 
92
125
  def Queries.get_user_posts
93
126
  "query ProfilePosts($username: String!, $after: String, $order: String, $count: Int) {
94
127
  user: userByUsername(username: $username) {
95
- id
96
- displayName
97
128
  posts(after: $after, order: $order, count: $count) {
98
129
  items {
99
- id
100
- isHidden
101
- ...PostsFeedItemPost
102
- board {
103
- id
104
- name
105
- url
106
- color
107
- __typename
108
- }
109
- __typename
110
- }
111
- pageInfo {
112
- nextCursor
113
- __typename
130
+ #{@@post}
114
131
  }
115
- __typename
116
- }
117
- __typename
118
- }
119
- }
120
-
121
- fragment PostsFeedItemPost on Post {
122
- id
123
- title
124
- body
125
- preview(removeMarkdown: true, length: 150)
126
- url
127
- commentCount
128
- isPinned
129
- isLocked
130
- isAnnouncement
131
- timeCreated
132
- isAnswered
133
- isAnswerable
134
- ...PostVoteControlPost
135
- ...PostLinkPost
136
- user {
137
- id
138
- username
139
- isHacker
140
- image
141
- ...UserLabelUser
142
- ...UserLinkUser
143
- __typename
144
- }
145
- repl {
146
- id
147
- url
148
- title
149
- description
150
- isPrivate
151
- isAlwaysOn
152
- lang {
153
- id
154
- icon
155
- key
156
- displayName
157
- tagline
158
- __typename
159
132
  }
160
- __typename
161
- }
162
- board {
163
- id
164
- name
165
- color
166
- __typename
167
133
  }
168
- }
169
-
170
- fragment PostVoteControlPost on Post {
171
- id
172
- voteCount
173
- canVote
174
- hasVoted
175
- __typename
176
- }
177
-
178
- fragment PostLinkPost on Post {
179
- id
180
- url
181
- __typename
182
- }
183
-
184
- fragment UserLabelUser on User {
185
- id
186
- username
187
- karma
188
- ...UserLinkUser
189
- __typename
190
- }
191
-
192
- fragment UserLinkUser on User {
193
- id
194
- url
195
- username
196
- roles {
197
- id
198
- name
199
- key
200
- tagline
201
- __typename
202
- }
203
- organization {
204
- id
205
- name
206
- __typename
207
- }
208
- languages {
209
- id
210
- key
211
- displayName
212
- tagline
213
- icon
214
- __typename
215
- }
216
- __typename
217
134
  }"
218
135
  end
219
136
 
220
137
  def Queries.get_user_comments
221
138
  "query ProfileComments($username: String!, $after: String, $order: String, $count: Int) {
222
139
  user: userByUsername(username: $username) {
223
- id
224
- displayName
225
140
  comments(after: $after, order: $order, count: $count) {
226
141
  items {
227
- id
228
- ...ProfileCommentsComment
229
- __typename
230
- }
231
- pageInfo {
232
- nextCursor
233
- __typename
142
+ #{@@comment}
234
143
  }
235
- __typename
236
144
  }
237
- __typename
238
145
  }
239
- }
146
+ }"
147
+ end
240
148
 
241
- fragment ProfileCommentsComment on Comment {
242
- id
243
- body
244
- timeCreated
245
- url
246
- ...CommentVoteControlComment
247
- user {
248
- id
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
- }
149
+ def Queries.get_post
150
+ "query post($id: Int!) {
151
+ post(id: $id) {
152
+ #{@@post}
275
153
  }
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
- }
293
- __typename
154
+ }"
155
+ end
156
+
157
+ def Queries.get_comment
158
+ "query comment ($id: Int!) {
159
+ comment(id: $id) {
160
+ #{@@comment}
294
161
  }
295
- __typename
296
- }
162
+ }"
163
+ end
297
164
 
298
- fragment CommentVoteControlComment on Comment {
299
- id
300
- voteCount
301
- canVote
302
- hasVoted
303
- __typename
165
+ def Queries.get_posts
166
+ "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
167
+ posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
168
+ items {
169
+ #{@@post}
170
+ }
171
+ }
304
172
  }"
305
173
  end
306
174
  end
data/lib/repltalk.rb CHANGED
@@ -16,6 +16,8 @@ class Role
16
16
  end
17
17
  end
18
18
 
19
+
20
+
19
21
  class Organization
20
22
  attr_reader :id, :name
21
23
 
@@ -29,6 +31,8 @@ class Organization
29
31
  end
30
32
  end
31
33
 
34
+
35
+
32
36
  class Language
33
37
  attr_reader :id, :key, :name, :tagline, :icon
34
38
 
@@ -45,13 +49,18 @@ class Language
45
49
  end
46
50
  end
47
51
 
52
+
53
+
48
54
  class Repl
49
- attr_reader :id, :url, :title, :description, :language, :is_private, :is_always_on
55
+ attr_reader :id, :url, :title, :author, :description, :language, :is_private, :is_always_on
56
+
57
+ def initialize(client, repl)
58
+ @client = client
50
59
 
51
- def initialize(repl)
52
60
  @id = repl["id"]
53
61
  @url = repl["url"]
54
62
  @title = repl["title"]
63
+ @author = User.new(@client, repl["user"])
55
64
  @description = repl["description"]
56
65
  @language = Language.new(repl["lang"])
57
66
 
@@ -64,6 +73,8 @@ class Repl
64
73
  end
65
74
  end
66
75
 
76
+
77
+
67
78
  class Board
68
79
  attr_reader :id, :name, :color
69
80
 
@@ -78,29 +89,46 @@ class Board
78
89
  end
79
90
  end
80
91
 
92
+
93
+
81
94
  class Comment
82
- attr_reader :id, :url, :author, :content, :vote_count, :can_vote, :has_voted
95
+ attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :comments, :can_vote, :has_voted
83
96
 
84
97
  def initialize(client, comment)
85
98
  @client = client
86
99
 
87
100
  @id = comment["id"]
88
101
  @url = comment["url"]
89
- @author = User.new(@client, comment["user"])
102
+ @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
90
103
  @content = comment["body"]
104
+ @post_id = comment["post"]["id"]
105
+ @is_answer = comment["isAnswer"]
91
106
  @vote_count = comment["voteCount"]
107
+ @timestamp = comment["timeCreated"]
108
+ @comments = comment.include?("comments") ? comment["comments"].map { |c| Comment.new(@client, c)} : Array.new
92
109
 
93
110
  @can_vote = comment["canVote"]
94
111
  @has_voted = comment["hasVoted"]
95
112
  end
96
113
 
114
+ def get_post
115
+ p = @client.graphql(
116
+ "post",
117
+ Queries.get_post,
118
+ id: @post_id
119
+ )
120
+ Post.new(self, p["post"])
121
+ end
122
+
97
123
  def to_s
98
124
  @content
99
125
  end
100
126
  end
101
127
 
128
+
129
+
102
130
  class Post
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
131
+ 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
104
132
 
105
133
  def initialize(client, post)
106
134
  @client = client
@@ -113,8 +141,8 @@ class Post
113
141
  @timestamp = post["timeCreated"]
114
142
 
115
143
  @board = Board.new(post["board"])
116
- @author = User.new(@client, post["user"])
117
- @repl = post["repl"] == nil ? nil : Repl.new(post["repl"])
144
+ @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
145
+ @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
118
146
 
119
147
  @vote_count = post["voteCount"]
120
148
  @comment_count = post["commentCount"]
@@ -136,8 +164,10 @@ class Post
136
164
  end
137
165
  end
138
166
 
167
+
168
+
139
169
  class User
140
- attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :roles, :organization, :languages
170
+ attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :roles, :organization, :languages
141
171
 
142
172
  def initialize(client, user)
143
173
  @client = client
@@ -149,6 +179,7 @@ class User
149
179
  @bio = user["bio"]
150
180
  @cycles = user["karma"]
151
181
  @is_hacker = user["isHacker"]
182
+ @timestamp = user["timeCreated"]
152
183
  @roles = user["roles"].map { |role| Role.new(role) }
153
184
  @organization = user["organization"] == nil ? nil : Organization.new(user["organization"])
154
185
  @languages = user["languages"].map { |lang| Language.new(lang) }
@@ -163,9 +194,7 @@ class User
163
194
  count: count,
164
195
  after: after
165
196
  )
166
- posts = Array.new
167
- p["user"]["posts"]["items"].each { |post| posts << Post.new(@client, post) }
168
- posts
197
+ p["user"]["posts"]["items"].map { |post| Post.new(@client, post) }
169
198
  end
170
199
 
171
200
  def get_comments(order: "new", count: nil, after: nil)
@@ -177,9 +206,7 @@ class User
177
206
  count: count,
178
207
  after: after
179
208
  )
180
- comments = Array.new
181
- c["user"]["comments"]["items"].each { |comment| comments << Comment.new(@client, comment) }
182
- comments
209
+ c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
183
210
  end
184
211
 
185
212
  def to_s
@@ -187,6 +214,8 @@ class User
187
214
  end
188
215
  end
189
216
 
217
+
218
+
190
219
  class Client
191
220
  attr_writer :sid
192
221
 
@@ -217,6 +246,10 @@ class Client
217
246
  puts "\e[31mERROR\n#{r}\e[0m"
218
247
  return nil
219
248
  end
249
+ if data.include?("errors")
250
+ puts "\e[31mERROR\n#{r}\e[0m"
251
+ return nil
252
+ end
220
253
  data = data["data"] if data.include?("data")
221
254
  data
222
255
  end
@@ -236,6 +269,38 @@ class Client
236
269
  Queries.get_user_by_id,
237
270
  user_id: id
238
271
  )
239
- User.new(u["user"])
272
+ User.new(self, u["user"])
273
+ end
274
+
275
+ def get_post(id)
276
+ p = graphql(
277
+ "post",
278
+ Queries.get_post,
279
+ id: id
280
+ )
281
+ Post.new(self, p["post"])
282
+ end
283
+
284
+ def get_comment(id)
285
+ c = graphql(
286
+ "comment",
287
+ Queries.get_comment,
288
+ id: id
289
+ )
290
+ Comment.new(self, c["comment"])
291
+ end
292
+
293
+ def get_posts(board: "all", order: "new", count: nil, after: nil, search: nil, languages: nil)
294
+ p = graphql(
295
+ "PostsFeed",
296
+ Queries.get_posts,
297
+ baordSlugs: [board],
298
+ order: order,
299
+ count: count,
300
+ after: after,
301
+ searchQuery: search,
302
+ languages: languages
303
+ )
304
+ p["posts"]["items"].map { |post| Post.new(self, post) }
240
305
  end
241
306
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repltalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodingCactus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: With the repltalk gem, you can easily interect with the repltalk graphql
42
- api.
42
+ api. See https://github.com/Coding-Cactus/repltalk for documentation
43
43
  email: codingcactus.cc@gmail.com
44
44
  executables: []
45
45
  extensions: []
@@ -50,7 +50,7 @@ files:
50
50
  homepage:
51
51
  licenses: []
52
52
  metadata:
53
- source_code_uri: https://github.com/Codin-Cactus/repltalk
53
+ source_code_uri: https://github.com/Coding-Cactus/repltalk
54
54
  post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths: