Class: Reddit::Api
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#last_action ⇒ Object
readonly
Returns the value of attribute last_action.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#browse(subreddit, options = {}) ⇒ Array<Reddit::Submission>
Browse submissions by subreddit.
-
#comments ⇒ Array<Reddit::Message>
Read received comments.
-
#initialize(user = nil, password = nil, options = {}) ⇒ Api
constructor
A new instance of Api.
- #inspect ⇒ Object
-
#post_replies ⇒ Array<Reddit::Message>
Read post replies.
-
#received_messages ⇒ Array<Reddit::Message>
Read received messages.
-
#search(terms = nil, options = {}) ⇒ Array<Reddit::Submission>
Search reddit.
-
#sent_messages ⇒ Array<Reddit::Message>
Read sent messages.
-
#unread_messages ⇒ Array<Reddit::Message>
Read unread messages.
Methods inherited from Base
base_headers, #base_headers, #cookie, #logged_in?, #login, #logout, #modhash, #read, #user_agent, user_agent, #user_id
Constructor Details
#initialize(user = nil, password = nil, options = {}) ⇒ Api
Returns a new instance of Api.
8 9 10 11 12 |
# File 'lib/ruby_reddit_api/api.rb', line 8 def initialize(user=nil,password=nil, ={}) @user = user @password = password @debug = StringIO.new end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
6 7 8 |
# File 'lib/ruby_reddit_api/api.rb', line 6 def debug @debug end |
#last_action ⇒ Object (readonly)
Returns the value of attribute last_action.
6 7 8 |
# File 'lib/ruby_reddit_api/api.rb', line 6 def last_action @last_action end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/ruby_reddit_api/api.rb', line 5 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/ruby_reddit_api/api.rb', line 5 def user @user end |
Instance Method Details
#browse(subreddit, options = {}) ⇒ Array<Reddit::Submission>
Browse submissions by subreddit
21 22 23 24 25 26 27 28 |
# File 'lib/ruby_reddit_api/api.rb', line 21 def browse(subreddit, ={}) subreddit = sanitize_subreddit(subreddit) .merge! :handler => "Submission" if [:limit] .merge!({:query => {:limit => [:limit]}}) end read("/r/#{subreddit}.json", ) end |
#comments ⇒ Array<Reddit::Message>
Read received comments
72 73 74 |
# File 'lib/ruby_reddit_api/api.rb', line 72 def comments :comments end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/ruby_reddit_api/api.rb', line 14 def inspect "<Reddit::Api>" end |
#post_replies ⇒ Array<Reddit::Message>
Read post replies
78 79 80 |
# File 'lib/ruby_reddit_api/api.rb', line 78 def post_replies :selfreply end |
#received_messages ⇒ Array<Reddit::Message>
Read received messages
60 61 62 |
# File 'lib/ruby_reddit_api/api.rb', line 60 def :inbox end |
#search(terms = nil, options = {}) ⇒ Array<Reddit::Submission>
Search reddit
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_reddit_api/api.rb', line 35 def search(terms=nil, ={}) = {:verb => "get", :query => {}} subreddit = [:in] sort = .fetch(:sort){ "relevance" } [:query].merge!({:sort => sort}) if subreddit [:query].merge!({:restrict_sr => "1"}) end if terms [:query].merge!({:q => terms}) end path = subreddit.to_s == "" ? "/r/search.json" : "/r/#{subreddit}/search.json" read(path, ) end |
#sent_messages ⇒ Array<Reddit::Message>
Read sent messages
54 55 56 |
# File 'lib/ruby_reddit_api/api.rb', line 54 def :sent end |
#unread_messages ⇒ Array<Reddit::Message>
Read unread messages
66 67 68 |
# File 'lib/ruby_reddit_api/api.rb', line 66 def :unread end |