rarbg 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rarbg.rb +99 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c84c6db4f3317404bb4abd142e84a9ff5575e57
|
4
|
+
data.tar.gz: 8452389a0daacf7c16d9ff045b9905a927923759
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3bb207abc310e70ec1ad5c78b909adb241ce4a2097f9fca6f8dfdece641729b1c52593fd0111bb8602a6cd4eb29e86eaf7712e6f794b8c14c3b7108b0224691
|
7
|
+
data.tar.gz: d59605f3f328d6c7cc8a389aeca5dbd670095f8fd8e19cdcb6cad256fd08a1a6f0cddfce30d257b226108491b1e0705a79c2d2394b0f5ffba620e126138b3802
|
data/lib/rarbg.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'json'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module RARBG
|
7
|
+
VERSION = '0.1.1'.freeze
|
8
|
+
APP_ID = 'rarbg-rubygem'.freeze
|
9
|
+
API_ENDPOINT = 'https://torrentapi.org/pubapi_v2.php'.freeze
|
10
|
+
TOKEN_EXPIRATION = 800
|
11
|
+
|
12
|
+
class RequestError < StandardError; end
|
13
|
+
class APIError < StandardError; end
|
14
|
+
|
15
|
+
class API
|
16
|
+
attr_reader :token, :token_time
|
17
|
+
attr_accessor :default_params
|
18
|
+
|
19
|
+
def initialize(params = {})
|
20
|
+
@default_params = {
|
21
|
+
'limit' => 25,
|
22
|
+
'sort' => 'last',
|
23
|
+
'format' => 'json_extended'
|
24
|
+
}.merge!(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
# list torrents
|
28
|
+
def list(params = {})
|
29
|
+
call({ 'mode' => 'list' }, params)
|
30
|
+
end
|
31
|
+
|
32
|
+
# search torrents
|
33
|
+
def search_string(string, params = {})
|
34
|
+
call({ 'mode' => 'search', 'search_string' => string }, params)
|
35
|
+
end
|
36
|
+
|
37
|
+
# search by imdb
|
38
|
+
def search_imdb(imdbid, params = {})
|
39
|
+
imdbid = "tt#{imdbid}" unless imdbid =~ /^tt\d+$/
|
40
|
+
call({ 'mode' => 'search', 'search_imdb' => imdbid }, params)
|
41
|
+
end
|
42
|
+
|
43
|
+
# search by tvdb
|
44
|
+
def search_tvdb(tvdbid, params = {})
|
45
|
+
call({ 'mode' => 'search', 'search_tvdb' => tvdbid }, params)
|
46
|
+
end
|
47
|
+
|
48
|
+
# search by themoviedb
|
49
|
+
def search_themoviedb(themoviedbid, params = {})
|
50
|
+
call({ 'mode' => 'search', 'search_themoviedb' => themoviedbid }, params)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# perform API call
|
56
|
+
def call(method_params, custom_params)
|
57
|
+
raise ArgumentError, 'not an Hash' unless custom_params.is_a?(Hash)
|
58
|
+
check_token
|
59
|
+
|
60
|
+
res = request.get do |req|
|
61
|
+
req.params['token'] = @token
|
62
|
+
req.params.merge!(@default_params)
|
63
|
+
req.params.merge!(custom_params)
|
64
|
+
req.params.merge!(method_params)
|
65
|
+
end
|
66
|
+
raise RequestError, res.reason_phrase unless res.success?
|
67
|
+
raise APIError, res.body['error'] if res.body['error']
|
68
|
+
|
69
|
+
res.body['torrent_results']
|
70
|
+
end
|
71
|
+
|
72
|
+
# check if token is empty or expired
|
73
|
+
def check_token
|
74
|
+
get_token if @token.nil? || (Time.now - @token_time) >= TOKEN_EXPIRATION
|
75
|
+
end
|
76
|
+
|
77
|
+
# get api token
|
78
|
+
def get_token
|
79
|
+
res = request.get do |req|
|
80
|
+
req.params['get_token'] = 'get_token'
|
81
|
+
end
|
82
|
+
raise RequestError, res.reason_phrase unless res.success?
|
83
|
+
raise APIError, res.body['error'] if res.body['error']
|
84
|
+
|
85
|
+
@token_time = Time.now
|
86
|
+
@token = res.body['token']
|
87
|
+
end
|
88
|
+
|
89
|
+
# setup faraday request
|
90
|
+
def request
|
91
|
+
Faraday.new(url: API_ENDPOINT) do |faraday|
|
92
|
+
faraday.adapter Faraday.default_adapter
|
93
|
+
faraday.request :url_encoded
|
94
|
+
faraday.response :json
|
95
|
+
faraday.params['app_id'] = APP_ID
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rarbg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tommaso Barbato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.10'
|
41
|
+
description: A ruby wrapper for RARBG torrentapi.
|
42
|
+
email: epistrephein@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/rarbg.rb
|
48
|
+
homepage: https://github.com/epistrephein/rarbg
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.6.8
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Ruby wrapper for RARBG torrentapi
|
72
|
+
test_files: []
|