Class: RedditApi::Client
- Inherits:
-
Object
- Object
- RedditApi::Client
- Defined in:
- lib/reddit_api/client.rb
Constant Summary collapse
- SLEEP_TIME =
self.sleep_time
- MAX_FAILURES =
5
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
Class Method Summary collapse
Instance Method Summary collapse
- #get(query) ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 |
# File 'lib/reddit_api/client.rb', line 19 def initialize(args = {}) @client = args.fetch(:client, HTTParty) @requestor = args.fetch(:requestor, RedditApi::Requestor.new(client: client)) @parser = args.fetch(:parser, RedditApi::ResponseParser) @null_response_factory = RedditApi:: NullResponse @failures = args.fetch(:failures, 0) end |
Instance Attribute Details
#failures ⇒ Object
Returns the value of attribute failures.
17 18 19 |
# File 'lib/reddit_api/client.rb', line 17 def failures @failures 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(query) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/reddit_api/client.rb', line 27 def get(query) while query.capture_count < query.count && failures < MAX_FAILURES response = send_request(query) response = parser.parse_response(response, query.count) update_progress(query, response) end reset_failures end |