repltalk 2.0.1 → 2.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 +14 -3
  3. data/lib/repltalk.rb +25 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ada3715121c7d61ea64ba460d56d128540495ad5d0e6e40f7b2b3356449a6928
4
- data.tar.gz: f514edbaeb4ffe4bfd90b5d9821329349e5c917d70e7cc91f32c9ce4d74d9684
3
+ metadata.gz: 472eea85f7f18da57609656f46e3da8ba747d59a65be74cabe03cf02efa5d28a
4
+ data.tar.gz: ee9e9f15d772c950a6b7b4ad7fd694abc6b5fa52dc948faa7eaadafd03e9d644
5
5
  SHA512:
6
- metadata.gz: 32cf8cc7d8d8bbcee551ef1fe73ddc1c54102a655fc26d0ea465e77f576ee297f446b4ec9314a9a7e198b9ad9e0566743491a4a52905c3f4ea4e318901b3243f
7
- data.tar.gz: a06595ab22910394812a9144bae621a90570a110785c1d5acf1964e8c58737a3d8d0c2b5847817189c410e4c213b483e53e55960821473d1cd6886d55405e37c
6
+ metadata.gz: 1f8c1ccaeb7b12fd6cebb976dc6bfc57653dee0ef98ef577114db904ca45c4b4271ab45b1ee975ab6359ea4b3b7b3e3b3e0d63fde5357f7744e1df8c93d58473
7
+ data.tar.gz: fda8de303b2b4eb8f01814e683f7303bcc4342d523dbe12c71d251488c5da640ac159865c41f3fc4efce9591cc7f948cdcd179e09b6bb9bb98c65a85e7f2dd7d
data/lib/queries.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Queries
1
+ class Fields
2
2
  @@roles = "
3
3
  id
4
4
  name
@@ -67,6 +67,7 @@ class Queries
67
67
  url
68
68
  title
69
69
  description
70
+ timeCreated
70
71
  size
71
72
  imageUrl
72
73
  isPrivate
@@ -141,8 +142,10 @@ class Queries
141
142
  #{@@comment}
142
143
  }
143
144
  "
145
+ end
144
146
 
145
147
 
148
+ class Queries < Fields
146
149
  def Queries.get_user
147
150
  "query userByUsername($username: String!) {
148
151
  user: userByUsername(username: $username) {
@@ -159,6 +162,14 @@ class Queries
159
162
  }"
160
163
  end
161
164
 
165
+ def Queries.user_search
166
+ "query usernameSearch($username: String!, $count: Int) {
167
+ usernameSearch(query: $username, limit: $count) {
168
+ #{@@user}
169
+ }
170
+ }"
171
+ end
172
+
162
173
  def Queries.get_user_posts
163
174
  "query user($username: String!, $after: String, $order: String, $count: Int) {
164
175
  user: userByUsername(username: $username) {
@@ -340,7 +351,7 @@ class Queries
340
351
  end
341
352
 
342
353
 
343
- class Mutations < Queries
354
+ class Mutations < Fields
344
355
  def Mutations.create_post
345
356
  "mutation createPost($input: CreatePostInput!) {
346
357
  createPost(input: $input) {
@@ -436,7 +447,7 @@ class Mutations < Queries
436
447
  }
437
448
  }
438
449
  }"
439
- end
450
+ end
440
451
 
441
452
  def Mutations.report_post
442
453
  "mutation createBoardReport($id: Int!, $reason: String!) {
data/lib/repltalk.rb CHANGED
@@ -101,8 +101,8 @@ class ReplComment
101
101
 
102
102
  @id = comment["id"]
103
103
  @content = comment["body"]
104
- @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
105
- @repl = Repl.new(@client, comment["repl"])
104
+ @author = comment["user"] == nil ? nil : User.new(@client, comment["user"])
105
+ @repl = comment["repl"] == nil ? nil : Repl.new(@client, comment["repl"])
106
106
  @replies = comment["replies"] == nil ? nil : comment["replies"].map { |c| ReplComment.new(@client, c) }
107
107
  end
108
108
 
@@ -127,7 +127,6 @@ class ReplComment
127
127
  body: content
128
128
  }
129
129
  )
130
- puts c
131
130
  ReplComment.new(@client, c["updateReplComment"])
132
131
  end
133
132
 
@@ -148,7 +147,7 @@ end
148
147
 
149
148
 
150
149
  class Repl
151
- attr_reader :id, :url, :title, :author, :description, :size, :language, :img_url, :origin_url, :is_private, :is_always_on
150
+ attr_reader :id, :url, :title, :author, :description, :timestamp, :size, :language, :img_url, :origin_url, :is_private, :is_always_on
152
151
 
153
152
  def initialize(client, repl)
154
153
  @client = client
@@ -158,6 +157,7 @@ class Repl
158
157
  @title = repl["title"]
159
158
  @author = User.new(@client, repl["user"])
160
159
  @description = repl["description"]
160
+ @timestamp = repl["timeCreated"]
161
161
  @size = repl["size"]
162
162
  @language = Language.new(repl["lang"])
163
163
  @image_url = repl["imageUrl"]
@@ -320,7 +320,7 @@ class Post
320
320
 
321
321
  @board = Board.new(post["board"])
322
322
  @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
323
- @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
323
+ @author = post["user"] == nil ? nil : User.new(@client, post["user"])
324
324
  @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
325
325
 
326
326
  @vote_count = post["voteCount"]
@@ -417,6 +417,7 @@ class User
417
417
  attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :subscription, :roles, :organization, :languages
418
418
 
419
419
  def initialize(client, user)
420
+ return nil if user == nil
420
421
  @client = client
421
422
 
422
423
  @id = user["id"]
@@ -535,6 +536,7 @@ class Client
535
536
  Queries.get_user,
536
537
  username: name
537
538
  )
539
+ return nil if u == nil || u["user"] == nil
538
540
  User.new(self, u["user"])
539
541
  end
540
542
 
@@ -544,15 +546,28 @@ class Client
544
546
  Queries.get_user_by_id,
545
547
  user_id: id
546
548
  )
549
+ return nil if u == nil || u["user"] == nil
547
550
  User.new(self, u["user"])
548
551
  end
549
552
 
553
+ def search_user(username, count: 10)
554
+ u = graphql(
555
+ "usernameSearch",
556
+ Queries.user_search,
557
+ username: username,
558
+ count: count
559
+ )
560
+ return nil if u["usernameSearch"] == nil
561
+ u["usernameSearch"].map { |user| User.new(self, user) }
562
+ end
563
+
550
564
  def get_post(id)
551
565
  p = graphql(
552
566
  "post",
553
567
  Queries.get_post,
554
568
  id: id
555
569
  )
570
+ return nil if p == nil || p["post"] == nil
556
571
  Post.new(self, p["post"])
557
572
  end
558
573
 
@@ -562,6 +577,7 @@ class Client
562
577
  Queries.get_comment,
563
578
  id: id
564
579
  )
580
+ return nil if c == nil || c["comment"] == nil
565
581
  Comment.new(self, c["comment"])
566
582
  end
567
583
 
@@ -571,6 +587,7 @@ class Client
571
587
  Queries.get_repl,
572
588
  url: url
573
589
  )
590
+ return nil if r == nil || r["repl"] == nil
574
591
  Repl.new(self, r["repl"])
575
592
  end
576
593
 
@@ -580,6 +597,7 @@ class Client
580
597
  Queries.get_repl_comment,
581
598
  id: id
582
599
  )
600
+ return nil if c == nil || c["replComment"] == nil
583
601
  ReplComment.new(self, c["replComment"])
584
602
  end
585
603
 
@@ -589,6 +607,7 @@ class Client
589
607
  Queries.get_board,
590
608
  slug: name
591
609
  )
610
+ return nil if b == nil || b["board"] == nil
592
611
  Board.new(b["board"])
593
612
  end
594
613
 
@@ -607,7 +626,7 @@ class Client
607
626
  p = graphql(
608
627
  "PostsFeed",
609
628
  Queries.get_posts,
610
- baordSlugs: [board],
629
+ boardSlugs: [board],
611
630
  order: order,
612
631
  count: count,
613
632
  after: after,
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: 2.0.1
4
+ version: 2.1.0
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-08 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http