Class: RedditApi::Client
- Inherits:
-
Object
- Object
- RedditApi::Client
- Defined in:
- lib/reddit_api/client.rb
Constant Summary collapse
- MAX_FAILURES =
5
- ERROR_CODES =
(400..511)
- SLEEP_TIME =
self.sleep_time
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #get(endpoint, count, resource_type) ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 |
# File 'lib/reddit_api/client.rb', line 20 def initialize(args = {}) @client = args.fetch(:client, HTTParty) @requestor = args.fetch(:requestor, RedditApi::Requestor.new(client: client)) @failures = args.fetch(:failures, 0) @null_response_factory = RedditApi:: NullResponse @last_record = nil end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
14 15 16 |
# File 'lib/reddit_api/client.rb', line 14 def agent @agent end |
#failures ⇒ Object
Returns the value of attribute failures.
14 15 16 |
# File 'lib/reddit_api/client.rb', line 14 def failures @failures end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/reddit_api/client.rb', line 14 def id @id end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
14 15 16 |
# File 'lib/reddit_api/client.rb', line 14 def password @password end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
14 15 16 |
# File 'lib/reddit_api/client.rb', line 14 def secret @secret end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
14 15 16 |
# File 'lib/reddit_api/client.rb', line 14 def username @username end |
Class Method Details
.sleep_time ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/reddit_api/client.rb', line 6 def self.sleep_time if ENV["ENVIRONMENT"] == "TEST" || ENV["RAILS_ENV"] == "test" 0 else 3 end end |
Instance Method Details
#get(endpoint, count, resource_type) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/reddit_api/client.rb', line 28 def get(endpoint, count, resource_type) if count > 1 get_many(endpoint, count, resource_type) else get_one(endpoint, count, resource_type) end end |