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.
800
Instance Attribute Summary collapse
-
#conn ⇒ Faraday::Connection
readonly
The Faraday connection object.
-
#last_request ⇒ Integer
readonly
The monotonic timestamp of the last request performed.
-
#token ⇒ String
readonly
The token used for authentication.
-
#token_time ⇒ Integer
readonly
The monotonic timestamp of the token request.
Instance Method Summary collapse
-
#initialize ⇒ API
constructor
Initialize a new istance of
RARBG::API
. -
#list(params = {}) ⇒ Array<Hash>
List torrents.
-
#search(params = {}) ⇒ Array<Hash>
Search torrents.
Constructor Details
#initialize ⇒ API
Initialize a new istance of RARBG::API
.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rarbg/api.rb', line 38 def initialize @conn = Faraday.new(url: API_ENDPOINT) do |conn| conn.request :json conn.response :json conn.adapter Faraday.default_adapter conn..timeout = 90 conn..open_timeout = 10 conn.params[:app_id] = APP_ID end end |
Instance Attribute Details
#conn ⇒ Faraday::Connection (readonly)
Returns the Faraday connection object.
23 24 25 |
# File 'lib/rarbg/api.rb', line 23 def conn @conn end |
#last_request ⇒ Integer (readonly)
Returns the monotonic timestamp of the last request performed.
32 33 34 |
# File 'lib/rarbg/api.rb', line 32 def last_request @last_request end |
#token ⇒ String (readonly)
Returns the token used for authentication.
26 27 28 |
# File 'lib/rarbg/api.rb', line 26 def token @token end |
#token_time ⇒ Integer (readonly)
Returns the monotonic timestamp of the token request.
29 30 31 |
# File 'lib/rarbg/api.rb', line 29 def token_time @token_time end |
Instance Method Details
#list(params = {}) ⇒ Array<Hash>
List torrents.
80 81 82 83 84 85 86 87 88 |
# File 'lib/rarbg/api.rb', line 80 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.
126 127 128 129 130 131 132 133 134 |
# File 'lib/rarbg/api.rb', line 126 def search(params = {}) raise ArgumentError, 'Expected params hash' unless params.is_a?(Hash) params.update( mode: 'search', token: token? ) call(params) end |