Module: NeonRAW::Objects::Subreddit::Utilities
- Included in:
- NeonRAW::Objects::Subreddit
- Defined in:
- lib/NeonRAW/objects/subreddit/utilities.rb
Overview
Utilities for subreddits.
Instance Method Summary collapse
-
#info(params = {}) ⇒ NeonRAW::Objects::Comment/Submission/Subreddit
Get info on a link/comment/subreddit.
-
#recommended_subreddits(opts = {}) ⇒ Array<String>
Gets recommended subreddits for the subreddit.
-
#submit(title, params = {}) ⇒ NeonRAW::Objects::Submission
Submit a thread to the subreddit.
-
#subscribe! ⇒ Object
Toggle your subscription to the subreddit.
-
#unsubscribe! ⇒ Object
Toggle your subscription to the subreddit.
Instance Method Details
#info(params = {}) ⇒ NeonRAW::Objects::Comment/Submission/Subreddit
Get info on a link/comment/subreddit.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/NeonRAW/objects/subreddit/utilities.rb', line 13 def info(params = {}) path = "/r/#{display_name}/api/info" data = @client.request_data(path, :get, params) case data[:data][:children][0][:kind] when 't1' Comment.new(@client, data[:data][:children][0][:data]) when 't3' Submission.new(@client, data[:data][:children][0][:data]) when 't5' Subreddit.new(@client, data[:data][:children][0][:data]) end end |
#recommended_subreddits(opts = {}) ⇒ Array<String>
Gets recommended subreddits for the subreddit.
51 52 53 54 55 56 |
# File 'lib/NeonRAW/objects/subreddit/utilities.rb', line 51 def recommended_subreddits(opts = {}) params = { omit: opts[:omit], srnames: display_name } path = "/api/recommend/sr/#{display_name}" data = @client.request_data(path, :get, params) data.map { |subreddit| subreddit[:sr_name] } end |
#submit(title, params = {}) ⇒ NeonRAW::Objects::Submission
Submit a thread to the subreddit.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/NeonRAW/objects/subreddit/utilities.rb', line 34 def submit(title, params = {}) params[:kind] = 'self' if params[:text] params[:kind] = 'link' if params[:url] params[:sr] = display_name params[:title] = title response = @client.request_data('/api/submit', :post, params) # Seriously though, fucking convoluted data structures. submission_id = response[:jquery].last[3].first.split('/')[6] info(id: 't3_' + submission_id) end |
#subscribe! ⇒ Object
Toggle your subscription to the subreddit.
61 62 63 64 65 66 67 68 69 |
# File 'lib/NeonRAW/objects/subreddit/utilities.rb', line 61 %w(subscribe unsubscribe).each do |type| define_method :"#{type}!" do params = { sr: name } params[:action] = 'sub' if type == 'subscribe' params[:action] = 'unsub' if type == 'unsubscribe' @client.request_data('/api/subscribe', :post, params) refresh! end end |
#unsubscribe! ⇒ Object
Toggle your subscription to the subreddit.
61 62 63 64 65 66 67 68 69 |
# File 'lib/NeonRAW/objects/subreddit/utilities.rb', line 61 %w(subscribe unsubscribe).each do |type| define_method :"#{type}!" do params = { sr: name } params[:action] = 'sub' if type == 'subscribe' params[:action] = 'unsub' if type == 'unsubscribe' @client.request_data('/api/subscribe', :post, params) refresh! end end |