ruqqus 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/CHANGELOG.md +24 -1
- data/Gemfile +1 -1
- data/README.md +152 -23
- data/Rakefile +1 -2
- data/TODO.md +27 -0
- data/exe/ruqqus-oauth +98 -0
- data/lib/ruqqus.rb +55 -72
- data/lib/ruqqus/client.rb +474 -0
- data/lib/ruqqus/routes.rb +68 -0
- data/lib/ruqqus/token.rb +148 -0
- data/lib/ruqqus/types.rb +11 -0
- data/lib/ruqqus/{badge.rb → types/badge.rb} +0 -0
- data/lib/ruqqus/types/comment.rb +38 -0
- data/lib/ruqqus/{guild.rb → types/guild.rb} +0 -0
- data/lib/ruqqus/{item_base.rb → types/item_base.rb} +4 -2
- data/lib/ruqqus/{post.rb → types/post.rb} +0 -33
- data/lib/ruqqus/{submission.rb → types/submission.rb} +5 -20
- data/lib/ruqqus/{title.rb → types/title.rb} +0 -0
- data/lib/ruqqus/{user.rb → types/user.rb} +0 -3
- data/lib/ruqqus/version.rb +1 -1
- data/ruqqus.gemspec +4 -2
- metadata +48 -15
- data/lib/ruqqus/comment.rb +0 -61
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
|