Class: Arxiv::Downloader::Client
- Inherits:
-
Object
- Object
- Arxiv::Downloader::Client
- Defined in:
- lib/arxiv/downloader/client.rb
Constant Summary collapse
- SOURCE_URL =
'https://github.com/xoengineering/arxiv-dl'.freeze
- DEFAULT_RATE_LIMIT =
3
Instance Attribute Summary collapse
-
#rate_limit ⇒ Object
readonly
Returns the value of attribute rate_limit.
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(rate_limit: DEFAULT_RATE_LIMIT, log: nil) ⇒ Client
constructor
A new instance of Client.
- #user_agent ⇒ Object
Constructor Details
#initialize(rate_limit: DEFAULT_RATE_LIMIT, log: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/arxiv/downloader/client.rb', line 11 def initialize rate_limit: DEFAULT_RATE_LIMIT, log: nil @rate_limit = rate_limit @log = log end |
Instance Attribute Details
#rate_limit ⇒ Object (readonly)
Returns the value of attribute rate_limit.
9 10 11 |
# File 'lib/arxiv/downloader/client.rb', line 9 def rate_limit @rate_limit end |
Instance Method Details
#get(url) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/arxiv/downloader/client.rb', line 20 def get url throttle response = HTTP.headers('User-Agent' => user_agent).follow.get(url) @last_request_at = Time.now log_request url, response response end |
#user_agent ⇒ Object
16 17 18 |
# File 'lib/arxiv/downloader/client.rb', line 16 def user_agent "arxiv-dl/#{VERSION} (+#{SOURCE_URL})" end |