module Redd::Clients::Base::Read
Methods that require the “read” scope
Public Instance Methods
@param [Array<String>] fnames A list of fullnames. @return [Objects::Listing<Objects::Thing>] A listing of things with
the fullname.
# File lib/redd/clients/base/read.rb, line 9 def from_fullname(*fnames) names = fnames.join(',') request_object(:get, '/api/info', id: names) end
@param [String] url The url of the thing. @return [Objects::Thing] The thing.
# File lib/redd/clients/base/read.rb, line 16 def from_url(url) request_object(:get, '/api/info', url: url).first end
Fetch an individual multi from its path. @param [String] path The multi's path. @return [Objects::LabeledMulti]
# 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
Fetch a list of multis belonging to the user.
# 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. @param query [String] The query string. @param subreddit [Objects::Subreddit, String] The subreddit to query. @param params [Hash] A list of params to send with the request. @option params [String] :after Return results after the given
fullname.
@option params [String] :before Return results before the given
fullname.
@option params [Integer] :count The number of items already seen in
the listing.
@option params [1..100] :limit The maximum number of things to
return.
@option params [:cloudsearch, :lucene, :plain] :syntax The type of
syntax to use.
@option params [:relevance, :new, :hot, :top, :comments] :sort The
way to sort the results.
@option params [:hour, :day, :week, :month, :year, :all] :t The
time period to consider when sorting.
@note The option :t only applies to the top and controversial sorts. @return [Objects::Listing<Objects::Thing>]
# 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
@param [String] name The subreddit's display name. @return [Objects::Subreddit] The subreddit if found.
# File lib/redd/clients/base/read.rb, line 28 def subreddit_from_name(name) request_object(:get, "/r/#{name}/about.json") end
@param [String] name The username. @return [Objects::User] The user.
# File lib/redd/clients/base/read.rb, line 22 def user_from_name(name) request_object(:get, "/user/#{name}/about.json") end