Module: Snoo::LinksComments
- Defined in:
- lib/snoo/links_comments.rb
Overview
Methods for interacting with links and comments, such as leaving a comment, voting, etc
Instance Method Summary collapse
-
#comment(text, id) ⇒ Object
Posts a comment to the site.
-
#delete(id) ⇒ Object
Deletes a thing from the site.
-
#downvote(id) ⇒ Object
Downvote An alias for
vote -1, id
. -
#edit(text, id) ⇒ Object
Edits a thing.
-
#hide(id) ⇒ Object
Hides a thing.
-
#info(opts = {}) ⇒ Object
Get a listing of things which have the provided URL.
-
#mark_nsfw(id) ⇒ Object
Marks a post NSFW.
-
#report(id) ⇒ Object
Reports a comment or link.
-
#save(id) ⇒ Object
Saves a link.
-
#sidevote(id) ⇒ Object
Sidevote (clear your vote) An alias for
vote 0, id
. -
#submit(title, subreddit, opts = {}) ⇒ Object
Submit a link or self post.
-
#unhide(id) ⇒ Object
Unhide a thing.
-
#unmark_nsfw(id) ⇒ Object
(also: #mark_sfw)
Un-mark NSFW a thing.
-
#unsave(id) ⇒ Object
Un-save a thing.
-
#upvote(id) ⇒ Object
Upvote An alias for
vote 1, id
. -
#vote(direction, id) ⇒ Object
Vote on a comment or link.
Instance Method Details
#comment(text, id) ⇒ Object
Posts a comment to the site
12 13 14 15 |
# File 'lib/snoo/links_comments.rb', line 12 def comment text, id logged_in? post('/api/comment', body: { text: text, thing_id: id, uh: @modhash, api_type: 'json'}) end |
#delete(id) ⇒ Object
Deletes a thing from the site
21 22 23 24 |
# File 'lib/snoo/links_comments.rb', line 21 def delete id logged_in? post('/api/del', body: { id: id, uh: @modhash, api_type: 'json' }) end |
#downvote(id) ⇒ Object
Downvote
An alias for vote -1, id
156 157 158 |
# File 'lib/snoo/links_comments.rb', line 156 def downvote id vote -1, id end |
#edit(text, id) ⇒ Object
Edits a thing. Can be a self post body, or a comment
31 32 33 34 |
# File 'lib/snoo/links_comments.rb', line 31 def edit text, id logged_in? post('/api/editusertext', body: {text: text, thing_id: id, uh: @modhash, api_type: 'json'}) end |
#hide(id) ⇒ Object
Hides a thing
40 41 42 43 |
# File 'lib/snoo/links_comments.rb', line 40 def hide id logged_in? post('/api/hide', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#info(opts = {}) ⇒ Object
Using Snoo::Listings#search is probably better for url lookups
Get a listing of things which have the provided URL. You can use a plain url, or a reddit link id to get reposts of said link
54 55 56 57 58 |
# File 'lib/snoo/links_comments.rb', line 54 def info opts = {} query = { limit: 100 } query.merge! opts get('/api/info.json', query: query) end |
#mark_nsfw(id) ⇒ Object
Marks a post NSFW. Currently, this only works on links
64 65 66 67 |
# File 'lib/snoo/links_comments.rb', line 64 def mark_nsfw id logged_in? post('/api/marknsfw', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#report(id) ⇒ Object
Reports a comment or link
73 74 75 76 |
# File 'lib/snoo/links_comments.rb', line 73 def report id logged_in? post('/api/report', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#save(id) ⇒ Object
Saves a link
82 83 84 85 |
# File 'lib/snoo/links_comments.rb', line 82 def save id logged_in? post('/api/save', body: { id: id, uh: @modhash, api_type: 'json'}) end |
#sidevote(id) ⇒ Object
Sidevote (clear your vote)
An alias for vote 0, id
163 164 165 |
# File 'lib/snoo/links_comments.rb', line 163 def sidevote id vote 0, id end |
#submit(title, subreddit, opts = {}) ⇒ Object
Submit a link or self post
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/snoo/links_comments.rb', line 95 def submit title, subreddit, opts = {} logged_in? post = { title: title, sr: subreddit, uh: @modhash, kind: (opts[:url] ? "link" : "self"), api_type: 'json' } post.merge! opts post('/api/submit', body: post) end |
#unhide(id) ⇒ Object
Unhide a thing
112 113 114 115 |
# File 'lib/snoo/links_comments.rb', line 112 def unhide id logged_in? post('/api/unhide', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#unmark_nsfw(id) ⇒ Object Also known as: mark_sfw
Un-mark NSFW a thing.
121 122 123 124 |
# File 'lib/snoo/links_comments.rb', line 121 def unmark_nsfw id logged_in? post('/api/unmarknsfw', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#unsave(id) ⇒ Object
Un-save a thing
131 132 133 134 |
# File 'lib/snoo/links_comments.rb', line 131 def unsave id logged_in? post('/api/unsave', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#upvote(id) ⇒ Object
Upvote
An alias for vote 1, id
149 150 151 |
# File 'lib/snoo/links_comments.rb', line 149 def upvote id vote 1, id end |
#vote(direction, id) ⇒ Object
Vote on a comment or link
141 142 143 144 |
# File 'lib/snoo/links_comments.rb', line 141 def vote direction, id logged_in? post('/api/vote', body: {id: id, dir: direction, uh: @modhash, api_type: 'json'}) end |