rarbg 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rarbg.rb +34 -12
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f275ed1e2baccaf9cfc2863790ad634f5dec9f7
4
- data.tar.gz: 415204f9fae36b2429022dc2d5017f9ec68b6a79
3
+ metadata.gz: df7a25793709ac040727f5773f929996be08dd84
4
+ data.tar.gz: a769ebf5a4236dce346a9322585361626a3ae3b4
5
5
  SHA512:
6
- metadata.gz: c51a5b95dc0404065851ac8106326badb4c907f3188b0b2af11cd6d59db016f53fec2939b1853a71ae1a9864c5c80a848699ca9384d8ac86c25f3ba2bfb35b69
7
- data.tar.gz: 13361c8ee8b2fa1b60d6c3c1d735e8acdc20986cdbf76c6ead9eff390d37a7a8863dd146132b8e4f5c918fdd23e5ed942fcedb24e8dd19f4a815461cae602d0e
6
+ metadata.gz: '07729fdfb40503aa686ff406efcc2805db57f9b91a3265a24b0021c6a504196f3d5cbba231cd3425657dcb8acc7df7519dd74efb657e9961cde392a9f5d0a7ae'
7
+ data.tar.gz: 620904fedf16ebd5c33d0c05e81db1463f9d7355af7407acaab08b7b954e2a4ab5e057cae1f3da00889178e42598d97e34403f75f5634401f2cdccdfe4b696d7
data/lib/rarbg.rb CHANGED
@@ -3,19 +3,27 @@ require 'faraday_middleware'
3
3
  require 'json'
4
4
  require 'time'
5
5
 
6
+ # A ruby wrapper for RARBG torrentapi.
6
7
  module RARBG
7
- VERSION = '0.1.3'.freeze
8
+ VERSION = '0.1.4'.freeze
8
9
  APP_ID = 'rarbg-rubygem'.freeze
9
10
  API_ENDPOINT = 'https://torrentapi.org/pubapi_v2.php'.freeze
10
11
  TOKEN_EXPIRATION = 800
11
12
 
13
+ # Exception for low level request errors.
12
14
  class RequestError < StandardError; end
15
+ # Exception for high level API errors.
13
16
  class APIError < StandardError; end
14
17
 
18
+ # API class for performing requests.
15
19
  class API
20
+ # API +token+ is stored with timestamped +token_time+.
16
21
  attr_reader :token, :token_time
22
+
23
+ # Any API call passes +default_params+ unless overidden.
17
24
  attr_accessor :default_params
18
25
 
26
+ # Returns a new API object with +@default_params+ defined in +params+.
19
27
  def initialize(params = {})
20
28
  @default_params = {
21
29
  'limit' => 25,
@@ -24,35 +32,49 @@ module RARBG
24
32
  }.merge!(params)
25
33
  end
26
34
 
27
- # list torrents
35
+ # Lists all torrents.
36
+ # Accepts query parameters from +params+.
37
+ # Returns an array of hashes.
28
38
  def list(params = {})
29
39
  call({ 'mode' => 'list' }, params)
30
40
  end
31
41
 
32
- # search torrents
42
+ # Searches torrents by literal name from +string+.
43
+ # Accepts query parameters from +params+.
44
+ # Returns an array of hashes of matching elements.
45
+ # Raises APIError if no results are found.
33
46
  def search_string(string, params = {})
34
47
  call({ 'mode' => 'search', 'search_string' => string }, params)
35
48
  end
36
49
 
37
- # search by imdb
50
+ # Searches by IMDb ID from +imdbid+.
51
+ # Accepts query parameters from +params+.
52
+ # Returns an array of hashes of matching elements.
53
+ # Raises APIError if no results are found.
38
54
  def search_imdb(imdbid, params = {})
39
55
  imdbid = "tt#{imdbid}" unless imdbid =~ /^tt\d+$/
40
56
  call({ 'mode' => 'search', 'search_imdb' => imdbid }, params)
41
57
  end
42
58
 
43
- # search by tvdb
59
+ # Searches by TVDB ID from +tvdbid+.
60
+ # Accepts query parameters from +params+.
61
+ # Returns an array of hashes of matching elements.
62
+ # Raises APIError if no results are found.
44
63
  def search_tvdb(tvdbid, params = {})
45
64
  call({ 'mode' => 'search', 'search_tvdb' => tvdbid }, params)
46
65
  end
47
66
 
48
- # search by themoviedb
67
+ # Searches by The Movie Database ID from +themoviedbid+
68
+ # Accepts query parameters from +params+.
69
+ # Returns an array of hashes of matching elements.
70
+ # Raises APIError if no results are found.
49
71
  def search_themoviedb(themoviedbid, params = {})
50
72
  call({ 'mode' => 'search', 'search_themoviedb' => themoviedbid }, params)
51
73
  end
52
74
 
53
75
  private
54
76
 
55
- # perform API call
77
+ # Performs API call.
56
78
  def call(method_params, custom_params)
57
79
  raise ArgumentError, 'not an Hash' unless custom_params.is_a?(Hash)
58
80
  check_token
@@ -71,12 +93,12 @@ module RARBG
71
93
  res.body['torrent_results']
72
94
  end
73
95
 
74
- # check if token is empty or expired
96
+ # Checks if +token+ is empty or expired.
75
97
  def check_token
76
98
  get_token if @token.nil? || (Time.now - @token_time) >= TOKEN_EXPIRATION
77
99
  end
78
100
 
79
- # get api token
101
+ # Requests or renews API token.
80
102
  def get_token
81
103
  res = request.get do |req|
82
104
  req.params['get_token'] = 'get_token'
@@ -89,12 +111,12 @@ module RARBG
89
111
  @token = res.body['token']
90
112
  end
91
113
 
92
- # setup faraday request
114
+ # Setups Faraday request.
93
115
  def request
94
116
  Faraday.new(url: API_ENDPOINT) do |faraday|
95
- faraday.adapter Faraday.default_adapter
96
- faraday.request :url_encoded
97
117
  faraday.response :json
118
+ faraday.request :url_encoded
119
+ faraday.adapter Faraday.default_adapter
98
120
  end
99
121
  end
100
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rarbg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Barbato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 2.6.8
68
+ rubygems_version: 2.6.14
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: Ruby wrapper for RARBG torrentapi