Class: Redd::Client::Unauthenticated
- Inherits:
-
Object
- Object
- Redd::Client::Unauthenticated
- Includes:
- Account, Captcha, LinksComments, Listing, Live, Moderation, Subreddits, Utilities, Wiki
- Defined in:
- lib/redd/client/unauthenticated.rb,
lib/redd/client/unauthenticated/live.rb,
lib/redd/client/unauthenticated/wiki.rb,
lib/redd/client/unauthenticated/account.rb,
lib/redd/client/unauthenticated/captcha.rb,
lib/redd/client/unauthenticated/listing.rb,
lib/redd/client/unauthenticated/utilities.rb,
lib/redd/client/unauthenticated/moderation.rb,
lib/redd/client/unauthenticated/subreddits.rb,
lib/redd/client/unauthenticated/links_comments.rb
Overview
The Client used to connect without needing login credentials.
Direct Known Subclasses
Defined Under Namespace
Modules: Account, Captcha, LinksComments, Listing, Live, Moderation, Subreddits, Utilities, Wiki
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
The site to connect to.
-
#rate_limit ⇒ #after_limit
The handler that takes care of rate limiting.
-
#user_agent ⇒ String
The user-agent used to communicate with reddit.
Instance Method Summary collapse
-
#connection ⇒ Faraday
private
Gets the Faraday connection or creates one if it doesn’t exist yet.
-
#delete(*args) ⇒ Object
private
Performs a DELETE request via #request.
-
#get(*args) ⇒ Object
private
Performs a GET request via #request.
-
#headers ⇒ Hash
private
The headers that are sent with every request.
-
#initialize(options = {}) ⇒ Unauthenticated
constructor
Set up an unauthenticated connection to reddit.
-
#post(*args) ⇒ Object
private
Performs a POST request via #request.
-
#put(*args) ⇒ Object
private
Performs a PUT request via #request.
-
#request(method, path, params = {}) ⇒ String
private
Send a request to the given path.
Methods included from Wiki
Methods included from Utilities
#comment_stream, #comments_from_response, #extract_attribute, #extract_fullname, #extract_id, #object_from_body, #object_from_kind, #object_from_response, #objects_from_listing, #submission_stream
Methods included from Subreddits
#get_subreddits, #search_subreddits, #subreddit
Methods included from Moderation
Methods included from Listing
#by_id, #get_comments, #get_controversial, #get_hot, #get_listing, #get_new, #get_random, #get_top
Methods included from LinksComments
#get_info, #get_replies, #replace_morecomments, #submission_comments
Methods included from Captcha
#captcha_url, #needs_captcha?, #new_captcha
Methods included from Account
Constructor Details
#initialize(options = {}) ⇒ Unauthenticated
Set up an unauthenticated connection to reddit.
52 53 54 55 56 |
# File 'lib/redd/client/unauthenticated.rb', line 52 def initialize( = {}) @rate_limit = [:rate_limit] || Redd::RateLimit.new @user_agent = [:user_agent] || "Redd/Ruby, v#{Redd::VERSION}" @api_endpoint = [:api_endpoint] || "https://www.reddit.com/" end |
Instance Attribute Details
#api_endpoint ⇒ String
Returns The site to connect to.
33 34 35 |
# File 'lib/redd/client/unauthenticated.rb', line 33 def api_endpoint @api_endpoint end |
#rate_limit ⇒ #after_limit
Returns The handler that takes care of rate limiting.
41 42 43 |
# File 'lib/redd/client/unauthenticated.rb', line 41 def rate_limit @rate_limit end |
#user_agent ⇒ String
Returns The user-agent used to communicate with reddit.
37 38 39 |
# File 'lib/redd/client/unauthenticated.rb', line 37 def user_agent @user_agent end |
Instance Method Details
#connection ⇒ Faraday (private)
Gets the Faraday connection or creates one if it doesn’t exist yet.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/redd/client/unauthenticated.rb', line 68 def connection @connection ||= Faraday.new(url: api_endpoint) do |faraday| faraday.use Faraday::Request::UrlEncoded faraday.use Redd::Response::RaiseError faraday.use Redd::Response::ParseJson faraday.adapter Faraday.default_adapter faraday.headers = headers end end |
#delete(*args) ⇒ Object (private)
Performs a DELETE request via #request.
111 112 113 |
# File 'lib/redd/client/unauthenticated.rb', line 111 def delete(*args) request(:delete, *args) end |
#get(*args) ⇒ Object (private)
Performs a GET request via #request.
93 94 95 |
# File 'lib/redd/client/unauthenticated.rb', line 93 def get(*args) request(:get, *args) end |
#headers ⇒ Hash (private)
Returns The headers that are sent with every request.
61 62 63 |
# File 'lib/redd/client/unauthenticated.rb', line 61 def headers @headers ||= {"User-Agent" => @user_agent} end |
#post(*args) ⇒ Object (private)
Performs a POST request via #request.
99 100 101 |
# File 'lib/redd/client/unauthenticated.rb', line 99 def post(*args) request(:post, *args) end |
#put(*args) ⇒ Object (private)
Performs a PUT request via #request.
105 106 107 |
# File 'lib/redd/client/unauthenticated.rb', line 105 def put(*args) request(:put, *args) end |
#request(method, path, params = {}) ⇒ String (private)
Send a request to the given path.
85 86 87 88 89 |
# File 'lib/redd/client/unauthenticated.rb', line 85 def request(method, path, params = {}) rate_limit.after_limit do connection.send(method.to_sym, path, params).body end end |