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.
122 123 124 |
# File 'lib/redditkit/client/links.rb', line 122 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.
50 51 52 53 |
# File 'lib/redditkit/client/links.rb', line 50 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 42 43 |
# File 'lib/redditkit/client/links.rb', line 30 def links(subreddit, = {}) = .clone 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.
64 65 66 67 68 69 70 71 72 |
# File 'lib/redditkit/client/links.rb', line 64 def links_with_domain(domain, = {}) = .clone 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.
107 108 109 |
# File 'lib/redditkit/client/links.rb', line 107 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.
114 115 116 |
# File 'lib/redditkit/client/links.rb', line 114 def mark_sfw(link) post 'api/unmarknsfw', :id => extract_full_name(link) end |
#random_link ⇒ RedditKit::Link
Gets a random link.
136 137 138 139 140 141 142 143 |
# File 'lib/redditkit/client/links.rb', line 136 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/redditkit/client/links.rb', line 83 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.
129 130 131 |
# File 'lib/redditkit/client/links.rb', line 129 def unhide(link) post 'api/unhide', :id => extract_full_name(link) end |