Module: Redd::Clients::Base::Read
- Included in:
- Redd::Clients::Base
- Defined in:
- lib/redd/clients/base/read.rb
Overview
Methods that require the “read” scope
Instance Method Summary collapse
-
#from_fullname(*fnames) ⇒ Objects::Listing<Objects::Thing>
A listing of things with the fullname.
-
#from_url(url) ⇒ Objects::Thing
The thing.
-
#get_comments(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Get the appropriate listing.
-
#get_controversial(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Get the appropriate listing.
-
#get_hot(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Get the appropriate listing.
-
#get_new(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Get the appropriate listing.
-
#get_top(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Get the appropriate listing.
-
#multi_from_path(path) ⇒ Objects::LabeledMulti
Fetch an individual multi from its path.
-
#my_multis ⇒ Object
Fetch a list of multis belonging to the user.
-
#search(query, subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Search.
-
#subreddit_from_name(name) ⇒ Objects::Subreddit
The subreddit if found.
-
#user_from_name(name) ⇒ Objects::User
The user.
Instance Method Details
#from_fullname(*fnames) ⇒ Objects::Listing<Objects::Thing>
Returns A listing of things with the fullname.
9 10 11 12 |
# File 'lib/redd/clients/base/read.rb', line 9 def from_fullname(*fnames) names = fnames.join(',') request_object(:get, '/api/info', id: names) end |
#from_url(url) ⇒ Objects::Thing
Returns The thing.
16 17 18 |
# File 'lib/redd/clients/base/read.rb', line 16 def from_url(url) request_object(:get, '/api/info', url: url).first end |
#get_comments(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Move all listing methods into a helper?
The option :t only applies to the top and controversial sorts.
Get the appropriate listing.
70 71 72 73 74 75 76 77 |
# File 'lib/redd/clients/base/read.rb', line 70 %w(hot new top controversial comments).each do |sort| define_method :"get_#{sort}" do |subreddit = nil, **params| srname = property(subreddit, :display_name) if subreddit path = "/#{sort}.json" path = path.prepend("/r/#{srname}") if subreddit request_object(:get, path, params) end end |
#get_controversial(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Move all listing methods into a helper?
The option :t only applies to the top and controversial sorts.
Get the appropriate listing.
70 71 72 73 74 75 76 77 |
# File 'lib/redd/clients/base/read.rb', line 70 %w(hot new top controversial comments).each do |sort| define_method :"get_#{sort}" do |subreddit = nil, **params| srname = property(subreddit, :display_name) if subreddit path = "/#{sort}.json" path = path.prepend("/r/#{srname}") if subreddit request_object(:get, path, params) end end |
#get_hot(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Move all listing methods into a helper?
The option :t only applies to the top and controversial sorts.
Get the appropriate listing.
70 71 72 73 74 75 76 77 |
# File 'lib/redd/clients/base/read.rb', line 70 %w(hot new top controversial comments).each do |sort| define_method :"get_#{sort}" do |subreddit = nil, **params| srname = property(subreddit, :display_name) if subreddit path = "/#{sort}.json" path = path.prepend("/r/#{srname}") if subreddit request_object(:get, path, params) end end |
#get_new(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Move all listing methods into a helper?
The option :t only applies to the top and controversial sorts.
Get the appropriate listing.
70 71 72 73 74 75 76 77 |
# File 'lib/redd/clients/base/read.rb', line 70 %w(hot new top controversial comments).each do |sort| define_method :"get_#{sort}" do |subreddit = nil, **params| srname = property(subreddit, :display_name) if subreddit path = "/#{sort}.json" path = path.prepend("/r/#{srname}") if subreddit request_object(:get, path, params) end end |
#get_top(subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
Move all listing methods into a helper?
The option :t only applies to the top and controversial sorts.
Get the appropriate listing.
70 71 72 73 74 75 76 77 |
# File 'lib/redd/clients/base/read.rb', line 70 %w(hot new top controversial comments).each do |sort| define_method :"get_#{sort}" do |subreddit = nil, **params| srname = property(subreddit, :display_name) if subreddit path = "/#{sort}.json" path = path.prepend("/r/#{srname}") if subreddit request_object(:get, path, params) end end |
#multi_from_path(path) ⇒ Objects::LabeledMulti
Fetch an individual multi from its path.
41 42 43 44 45 |
# File 'lib/redd/clients/base/read.rb', line 41 def multi_from_path(path) # rubocop:disable Style/RegexpLiteral without_slash = path.gsub(/^\//, '') request_object(:get, '/api/multi/' + without_slash) end |
#my_multis ⇒ Object
Fetch a list of multis belonging to the user.
33 34 35 36 |
# File 'lib/redd/clients/base/read.rb', line 33 def my_multis multis = get('/api/multi/mine').body multis.map { |thing| object_from_body(thing) } end |
#search(query, subreddit = nil, **params) ⇒ Objects::Listing<Objects::Thing>
The option :t only applies to the top and controversial sorts.
Search.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/redd/clients/base/read.rb', line 100 def search(query, subreddit = nil, **params) path = '/search.json' params[:q] = query if subreddit params[:restrict_sr] = true srname = property(subreddit, :display_name) path = path.prepend("/r/#{srname}") end request_object(:get, path, params) end |
#subreddit_from_name(name) ⇒ Objects::Subreddit
Returns The subreddit if found.
28 29 30 |
# File 'lib/redd/clients/base/read.rb', line 28 def subreddit_from_name(name) request_object(:get, "/r/#{name}/about.json") end |
#user_from_name(name) ⇒ Objects::User
Returns The user.
22 23 24 |
# File 'lib/redd/clients/base/read.rb', line 22 def user_from_name(name) request_object(:get, "/user/#{name}/about.json") end |