ruqqus 1.0.0 → 1.1.4
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.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/CHANGELOG.md +48 -1
- data/Gemfile +1 -1
- data/README.md +160 -23
- data/Rakefile +1 -2
- data/TODO.md +25 -0
- data/exe/ruqqus-oauth +98 -0
- data/lib/ruqqus.rb +217 -64
- data/lib/ruqqus/client.rb +571 -0
- data/lib/ruqqus/routes.rb +68 -0
- data/lib/ruqqus/token.rb +124 -0
- data/lib/ruqqus/types.rb +11 -0
- data/lib/ruqqus/{badge.rb → types/badge.rb} +0 -0
- data/lib/ruqqus/types/comment.rb +44 -0
- data/lib/ruqqus/{guild.rb → types/guild.rb} +51 -33
- data/lib/ruqqus/{item_base.rb → types/item_base.rb} +25 -15
- data/lib/ruqqus/types/post.rb +70 -0
- data/lib/ruqqus/{submission.rb → types/submission.rb} +66 -59
- data/lib/ruqqus/{title.rb → types/title.rb} +0 -0
- data/lib/ruqqus/types/user.rb +118 -0
- data/lib/ruqqus/version.rb +7 -3
- data/ruqqus.gemspec +6 -2
- metadata +50 -16
- data/lib/ruqqus/comment.rb +0 -61
- data/lib/ruqqus/post.rb +0 -85
- data/lib/ruqqus/user.rb +0 -96
data/lib/ruqqus/comment.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require_relative 'submission'
|
2
|
-
|
3
|
-
module Ruqqus
|
4
|
-
|
5
|
-
##
|
6
|
-
# Describes a comment in a post.
|
7
|
-
class Comment < Submission
|
8
|
-
|
9
|
-
##
|
10
|
-
# Captures the ID of a comment from a Ruqqus URL
|
11
|
-
COMMENT_REGEX = /ruqqus.com\/post\/.+\/.+\/([A-Za-z0-9]+)\/?/.freeze
|
12
|
-
|
13
|
-
##
|
14
|
-
# @return [Integer] the level of "nesting" in the comment tree, starting at `1` when in direct reply to the post.
|
15
|
-
def level
|
16
|
-
@data[:level]
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# @return [String] the unique ID of the parent for this comment.
|
21
|
-
def parent_id
|
22
|
-
@data[:parent]
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# @return [Post,Comment] the parent for this content.
|
27
|
-
def parent
|
28
|
-
#noinspection RubyYardReturnMatch
|
29
|
-
@parent ||= level > 1 ? Ruqqus.comment(parent_id) : Ruqqus.post(parent_id)
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# @return [String] the ID of the post this comment belongs to.
|
34
|
-
def post_id
|
35
|
-
@data[:post]
|
36
|
-
end
|
37
|
-
|
38
|
-
##
|
39
|
-
# @return [Post] the post this comment belongs to.
|
40
|
-
def post
|
41
|
-
#noinspection RubyYardReturnMatch
|
42
|
-
Ruqqus.post(post_id)
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
# Creates a new {Comment} instance from the specified URL.
|
47
|
-
#
|
48
|
-
# @param url [String] a URL link to a comment.
|
49
|
-
#
|
50
|
-
# @return [Comment] the {Comment} instance the URL links to.
|
51
|
-
#
|
52
|
-
# @raise [ArgumentError] then `url` is `nil`.
|
53
|
-
# @raise [Ruqqus::Error] when the link is not for a Ruqqus comment.
|
54
|
-
def self.from_url(url)
|
55
|
-
raise(ArgumentError, 'url cannot be nil') unless url
|
56
|
-
match = COMMENT_REGEX.match(url)
|
57
|
-
raise(ArgumentError, 'invalid URL for a comment') unless match
|
58
|
-
Ruqqus.comment($1)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/lib/ruqqus/post.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require_relative 'submission'
|
2
|
-
|
3
|
-
module Ruqqus
|
4
|
-
|
5
|
-
##
|
6
|
-
# Represents a post on Ruqqus.
|
7
|
-
class Post < Submission
|
8
|
-
|
9
|
-
##
|
10
|
-
# Captures the ID of a post from a Ruqqus URL
|
11
|
-
POST_REGEX = /ruqqus.com\/post\/([A-Za-z0-9]+)\/?.*/.freeze
|
12
|
-
|
13
|
-
##
|
14
|
-
# @return [Title?] the title assigned to the author, or `nil` if none is defined.
|
15
|
-
def author_title
|
16
|
-
#noinspection RubyYardReturnMatch
|
17
|
-
@author_title ||= @data[:author_title] ? Title.new(@data[:author_title]) : nil
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# @return [Integer] the number of comments made on the post.
|
22
|
-
def comment_count
|
23
|
-
@data[:comment_count]
|
24
|
-
end
|
25
|
-
|
26
|
-
##
|
27
|
-
# @return [String] the domain name for link posts, otherwise a short descriptor of the post type.
|
28
|
-
def domain
|
29
|
-
@data[:domain]
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# @return [String] the embed URL for the post.
|
34
|
-
def embed_url
|
35
|
-
@data[:embed_url]
|
36
|
-
end
|
37
|
-
|
38
|
-
##
|
39
|
-
# @return [String] the name of the guild this post was originally posted in.
|
40
|
-
def original_guild_name
|
41
|
-
@data[:original_guild_name]
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
# @return [Guild] the guild this post was originally posted in.
|
46
|
-
def original_guild
|
47
|
-
@original_guild ||= Ruqqus.guild(original_guild_name)
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# @return [String?] the URL of the post's thumbnail image, or `nil` if none exists.
|
52
|
-
def thumb_url
|
53
|
-
@data[:thumb_url]
|
54
|
-
end
|
55
|
-
|
56
|
-
##
|
57
|
-
# @return [String?] the URL the post links to, or `nil` if none is specified.
|
58
|
-
def url
|
59
|
-
#noinspection RubyYardReturnMatch
|
60
|
-
@data[:url]&.empty? ? nil : @data[:url]
|
61
|
-
end
|
62
|
-
|
63
|
-
##
|
64
|
-
# @return [String] the string representation of the object.
|
65
|
-
def to_s
|
66
|
-
@data[:title] || inspect
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Creates a new {Post} instance from the specified URL.
|
71
|
-
#
|
72
|
-
# @param url [String] a URL link to a post.
|
73
|
-
#
|
74
|
-
# @return [Post] the {Post} instance the URL links to.
|
75
|
-
#
|
76
|
-
# @raise [ArgumentError] then `url` is `nil`.
|
77
|
-
# @raise [Ruqqus::Error] when the link is not for a Ruqqus post.
|
78
|
-
def self.from_url(url)
|
79
|
-
raise(ArgumentError, 'url cannot be nil') unless url
|
80
|
-
match = POST_REGEX.match(url)
|
81
|
-
raise(ArgumentError, 'invalid URL for a post') unless match
|
82
|
-
Ruqqus.post($1)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/ruqqus/user.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require_relative 'badge'
|
2
|
-
require_relative 'title'
|
3
|
-
require_relative 'item_base'
|
4
|
-
|
5
|
-
module Ruqqus
|
6
|
-
|
7
|
-
##
|
8
|
-
# Represents a Ruqqus user account.
|
9
|
-
class User < ItemBase
|
10
|
-
|
11
|
-
##
|
12
|
-
# @return [Integer] the number of comments the user has created.
|
13
|
-
def comment_count
|
14
|
-
@data[:comment_count] || 0
|
15
|
-
end
|
16
|
-
|
17
|
-
##
|
18
|
-
# @return [Integer] the number of posts the user has created.
|
19
|
-
def post_count
|
20
|
-
@data[:post_count] || 0
|
21
|
-
end
|
22
|
-
|
23
|
-
##
|
24
|
-
# @return [Integer] the amount of rep the user has earned from comments.
|
25
|
-
def comment_rep
|
26
|
-
@data[:comment_rep] || 0
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# @return [Integer] the amount of rep the user has earned from posts.
|
31
|
-
def post_rep
|
32
|
-
@data[:post_rep] || 0
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# @return [Integer] the total amount of rep the user has earned from comments and posts.
|
37
|
-
def total_rep
|
38
|
-
comment_rep + post_rep
|
39
|
-
end
|
40
|
-
|
41
|
-
##
|
42
|
-
# @return [String] the username of the account.
|
43
|
-
def username
|
44
|
-
@data[:username]
|
45
|
-
end
|
46
|
-
|
47
|
-
##
|
48
|
-
# @return [Array<Badge>] an array of badges associated with this account.
|
49
|
-
def badges
|
50
|
-
@badges ||= @data[:badges].map { |b| Badge.new(b) }
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# @return [Title?] the title the user has associated with their account, or `nil` if none is assigned.
|
55
|
-
def title
|
56
|
-
#noinspection RubyYardReturnMatch
|
57
|
-
@title ||= @data[:title] ? Title.new(@data[title]) : nil
|
58
|
-
end
|
59
|
-
|
60
|
-
##
|
61
|
-
# @return [String] the URL for the banner image associated with the account.
|
62
|
-
def banner_url
|
63
|
-
@data[:banner_url]
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# @return [String] the URL for the profile image associated with the account.
|
68
|
-
def profile_url
|
69
|
-
@data[:profile_url]
|
70
|
-
end
|
71
|
-
|
72
|
-
##
|
73
|
-
# @return [String] A brief statement/biography the user has associated with their account.
|
74
|
-
def bio
|
75
|
-
@data[:bio]
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# @return [String] a brief statement/biography the user has associated with their account in HTML format.
|
80
|
-
def bio_html
|
81
|
-
@data[:bio_html]
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# @return [String?] the reason the user was banned if they were, otherwise `nil`.
|
86
|
-
def ban_reason
|
87
|
-
@data[:ban_reason]
|
88
|
-
end
|
89
|
-
|
90
|
-
##
|
91
|
-
# @return [String] the string representation of the object.
|
92
|
-
def to_s
|
93
|
-
@data[:username] || inspect
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|