Module: RedditKit::Client::Links
- Included in:
- RedditKit::Client
- Defined in:
- lib/redditkit/client/links.rb
Overview
Methods for retrieving, submitting and interacting with links.
Instance Method Summary collapse
-
#front_page(options = {}) ⇒ RedditKit::PaginatedResponse
Gets the links currently on the front page.
-
#hide(link) ⇒ Object
Hides a link.
-
#link(link_full_name) ⇒ RedditKit::Link
Gets a link object from its full name.
-
#links(subreddit, options = {}) ⇒ RedditKit::PaginatedResponse
Gets an array of links from a specific subreddit.
-
#links_with_domain(domain, options = {}) ⇒ RedditKit::PaginatedResponse
Gets links with a specific domain.
-
#mark_nsfw(link) ⇒ Object
Marks a link as not safe for work.
-
#mark_sfw(link) ⇒ Object
(also: #unmark_nsfw)
Marks a link as safe for work.
-
#random_link ⇒ RedditKit::Link
Gets a random link.
-
#submit(title, subreddit, options = {}) ⇒ Object
Submits a link or self post to reddit.
-
#unhide(link) ⇒ Object
Unhides a link.
Instance Method Details
#front_page(options = {}) ⇒ RedditKit::PaginatedResponse
Gets the links currently on the front page.
17 18 19 |
# File 'lib/redditkit/client/links.rb', line 17 def front_page( = {}) links nil, end |
#hide(link) ⇒ Object
Hides a link.
118 119 120 |
# File 'lib/redditkit/client/links.rb', line 118 def hide(link) post('api/hide', { :id => extract_full_name(link) }) end |
#link(link_full_name) ⇒ RedditKit::Link
This method will return nil if there is not a user currently signed in.
Gets a link object from its full name.
48 49 50 51 |
# File 'lib/redditkit/client/links.rb', line 48 def link(link_full_name) links = objects_from_response(:get, 'api/info.json', { :id => link_full_name }) links.first end |
#links(subreddit, options = {}) ⇒ RedditKit::PaginatedResponse
Gets an array of links from a specific subreddit.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redditkit/client/links.rb', line 30 def links(subreddit, = {}) subreddit_name = extract_string(subreddit, :display_name) if subreddit category = [:category] || :hot path = "%s/#{category.to_s}.json" % ('r/' + subreddit_name if subreddit_name) [:t] = [:time] if [:time] .delete :category .delete :time objects_from_response(:get, path, ) end |
#links_with_domain(domain, options = {}) ⇒ RedditKit::PaginatedResponse
Gets links with a specific domain.
62 63 64 65 66 67 68 |
# File 'lib/redditkit/client/links.rb', line 62 def links_with_domain(domain, = {}) parameters = { :url => domain, :t => [:time] } .merge! parameters .delete :t objects_from_response(:get, 'api/info.json', ) end |
#mark_nsfw(link) ⇒ Object
Marks a link as not safe for work.
103 104 105 |
# File 'lib/redditkit/client/links.rb', line 103 def mark_nsfw(link) post('api/marknsfw', { :id => extract_full_name(link) }) end |
#mark_sfw(link) ⇒ Object Also known as: unmark_nsfw
Marks a link as safe for work.
110 111 112 |
# File 'lib/redditkit/client/links.rb', line 110 def mark_sfw(link) post('api/unmarknsfw', { :id => extract_full_name(link) }) end |
#random_link ⇒ RedditKit::Link
Gets a random link.
132 133 134 135 136 137 138 139 |
# File 'lib/redditkit/client/links.rb', line 132 def random_link response = get('/random', nil) headers = response[:response_headers] location = headers[:location] link_id = location[/\/tb\/(.*)/, 1] link "t3_#{link_id}" end |
#submit(title, subreddit, options = {}) ⇒ Object
Submits a link or self post to reddit.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/redditkit/client/links.rb', line 79 def submit(title, subreddit, = {}) subreddit_name = extract_string subreddit, :display_name parameters = { :title => title, :sr => subreddit_name, :iden => [:captcha_identifier], :captcha => [:captcha_value], :save => [:save] } if [:url] parameters[:url] = [:url] parameters[:kind] = 'link' else parameters[:text] = [:text] parameters[:kind] = 'self' end post('api/submit', parameters) end |
#unhide(link) ⇒ Object
Unhides a link.
125 126 127 |
# File 'lib/redditkit/client/links.rb', line 125 def unhide(link) post('api/unhide', { :id => extract_full_name(link) }) end |