Class: Reddit::Base::BasicClient
- Inherits:
-
Object
- Object
- Reddit::Base::BasicClient
- Extended by:
- Forwardable
- Defined in:
- lib/reddit/base/basic_client.rb
Overview
Basic client that doesn’t make assumptions regarding response type.
The reddit API isn’t always consistent with its response types so may return HTML even when JSON is requested. Error pages are a common and unavoidable example.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_URL =
'http://www.reddit.com'.freeze
- DEFAULT_URL_SECURE =
'https://ssl.reddit.com'.freeze
- DEFAULT_OPTIONS =
{ headers: {'User-Agent' => "reddit-base, a reddit client for ruby by /u/dobs (v#{VERSION})"}, rem: true, url: DEFAULT_URL }.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ BasicClient
constructor
A new instance of BasicClient.
Constructor Details
#initialize(options) ⇒ BasicClient
Returns a new instance of BasicClient.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/reddit/base/basic_client.rb', line 24 def initialize() @secure = .delete(:secure) @options = DEFAULT_OPTIONS.merge() @options[:url] = DEFAULT_URL_SECURE if @secure @connection = Faraday.new(url: @options[:url], headers: @options[:headers]) do |builder| builder.request :multipart builder.request :url_encoded builder.request :reddit_authentication, @options builder.response :follow_redirects builder.use :reddit_rate_limit builder.use :reddit_modhash builder.adapter Faraday.default_adapter end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
20 21 22 |
# File 'lib/reddit/base/basic_client.rb', line 20 def connection @connection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/reddit/base/basic_client.rb', line 20 def @options end |