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

Author:

Instance Method Summary collapse

Instance Method Details

#comment(text, id) ⇒ Object

Posts a comment to the site

Parameters:

  • text (String)

    The comment text, formatted as markdown

  • id (String)

    The parent object id. Should be a comment or link



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

Parameters:

  • id (String)

    The thing to target.



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



147
148
149
# File 'lib/snoo/links_comments.rb', line 147

def downvote id
  vote -1, id
end

#edit(text, id) ⇒ Object

Edits a thing. Can be a self post body, or a comment

Parameters:

  • text (String)

    The comment text, formatted as markdown

  • id (String)

    The parent object id. Should be a comment or link



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

Parameters:

  • id (String)

    The thing to target.



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

Note:

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

Parameters:

  • opts (Hash) (defaults to: {})

    An options hash

Options Hash (opts):

  • :id (String)

    The id of a reddit thing to look up. Specify either this or a url, not both

  • :url (String)

    The url to search for matching things. Specify either this or an id, not both

  • :limit (Fixnum)

    The number of things to return. Go too high and the API will ignore you



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

Parameters:

  • id (String)

    The thing to target.



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

Parameters:

  • id (String)

    The thing to target.



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

Parameters:

  • id (String)

    The thing to target.



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



154
155
156
# File 'lib/snoo/links_comments.rb', line 154

def sidevote id
  vote 0, id
end

#submit(title, subreddit, opts = {}) ⇒ Object

Submit a link or self post

Parameters:

  • title (String)

    Title of the post

  • subreddit (String)

    The subreddit in which we are posting

  • opts (Hash) (defaults to: {})

    An options hash

Options Hash (opts):

  • :url (String)

    The url for the post. If this is specified, it will not be a self post, and text will be ignored

  • :text (String)

    The self-post text. Can be formatted in markdown



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

Parameters:

  • id (String)

    The thing to target.



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.

Parameters:

  • id (String)

    The thing to target.



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

#upvote(id) ⇒ Object

Upvote An alias for vote 1, id



140
141
142
# File 'lib/snoo/links_comments.rb', line 140

def upvote id
  vote 1, id
end

#vote(direction, id) ⇒ Object

Vote on a comment or link

Parameters:

  • direction (-1, 0, 1)

    The direction to vote in. -1 is a downvote, 1 is an upvote, 0 cancels any vote

  • id (String)

    The thing to target.



132
133
134
135
# File 'lib/snoo/links_comments.rb', line 132

def vote direction, id
  logged_in?
  post('/api/vote', body: {id: id, dir: direction, uh: @modhash, api_type: 'json'})
end