Class: RARBG::API
- Inherits:
-
Object
- Object
- RARBG::API
- Defined in:
- lib/rarbg/api.rb
Overview
Base class for RARBG API.
Constant Summary collapse
- API_ENDPOINT =
RARBG API endpoint.
'https://torrentapi.org/pubapi_v2.php'
- APP_ID =
App name identifier.
'rarbg-rubygem'
- TOKEN_EXPIRATION =
Default token expiration time (seconds).
800
- RATE_LIMIT =
Default API rate limit (seconds).
2.1
Instance Attribute Summary collapse
-
#connection ⇒ Faraday::Connection
readonly
The underlying
Faraday::Connection
object used to perform requests. -
#last_request ⇒ Float
readonly
The monotonic timestamp of the last request performed.
-
#token ⇒ String
readonly
The token used for authentication.
-
#token_time ⇒ Float
readonly
The monotonic timestamp of the token request.
Instance Method Summary collapse
-
#initialize ⇒ API
constructor
Initialize a new instance of
RARBG::API
. -
#list(params = {}) ⇒ Array<Hash>
List torrents.
-
#search(params = {}) ⇒ Array<Hash>
Search torrents.
-
#token! ⇒ String
Generate the authentication token.
Constructor Details
#initialize ⇒ API
Initialize a new instance of RARBG::API
.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rarbg/api.rb', line 56 def initialize @connection = Faraday.new(url: API_ENDPOINT) do |conn| conn.response :logger if $VERBOSE conn.adapter Faraday.default_adapter conn..timeout = 30 conn..open_timeout = 10 conn.headers[:user_agent] = APP_ID conn.params[:app_id] = APP_ID end end |
Instance Attribute Details
#connection ⇒ Faraday::Connection (readonly)
For more info regarding this object refer to the Faraday documentation.
The underlying Faraday::Connection
object used to perform requests.
31 32 33 |
# File 'lib/rarbg/api.rb', line 31 def connection @connection end |
#last_request ⇒ Float (readonly)
The monotonic timestamp of the last request performed. Used to comply with the endpoint rate limit based on RATE_LIMIT.
37 38 39 |
# File 'lib/rarbg/api.rb', line 37 def last_request @last_request end |
#token ⇒ String (readonly)
44 45 46 |
# File 'lib/rarbg/api.rb', line 44 def token @token end |
#token_time ⇒ Float (readonly)
The monotonic timestamp of the token request. Used to compute the next required token request based on TOKEN_EXPIRATION.
50 51 52 |
# File 'lib/rarbg/api.rb', line 50 def token_time @token_time end |
Instance Method Details
#list(params = {}) ⇒ Array<Hash>
List torrents.
102 103 104 105 106 107 |
# File 'lib/rarbg/api.rb', line 102 def list(params = {}) raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash) params.update(mode: 'list', token: token?) call(params) end |
#search(params = {}) ⇒ Array<Hash>
Search torrents.
148 149 150 151 152 153 |
# File 'lib/rarbg/api.rb', line 148 def search(params = {}) raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash) params.update(mode: 'search', token: token?) call(params) end |
#token! ⇒ String
Generate the authentication token.
162 163 164 |
# File 'lib/rarbg/api.rb', line 162 def token! token? end |