the_pirate_bay 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/the_pirate_bay.rb +9 -9
- data/lib/the_pirate_bay/client.rb +6 -6
- data/lib/the_pirate_bay/torrent.rb +60 -95
- data/lib/the_pirate_bay/torrent/collection.rb +19 -54
- data/lib/the_pirate_bay/version.rb +1 -1
- data/spec/fixtures/torrent/search.html +4 -4
- data/spec/spec_helper.rb +1 -2
- data/spec/the_pirate_bay/torrent_spec.rb +42 -42
- data/spec/the_pirate_bay_spec.rb +5 -5
- data/the_pirate_bay.gemspec +11 -10
- metadata +20 -7
- data/lib/the_pirate_bay/api.rb +0 -21
- data/lib/the_pirate_bay/errors.rb +0 -18
- data/lib/the_pirate_bay/model.rb +0 -36
data/lib/the_pirate_bay.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require 'hyper_api'
|
2
|
+
|
3
|
+
require 'the_pirate_bay/core_ext/string'
|
4
|
+
require 'the_pirate_bay/version'
|
5
|
+
require 'the_pirate_bay/connection'
|
6
|
+
require 'the_pirate_bay/client'
|
7
7
|
|
8
8
|
module ThePirateBay
|
9
9
|
|
10
|
-
ENDPOINT =
|
10
|
+
ENDPOINT = 'http://thepiratebay.org'.freeze
|
11
11
|
|
12
12
|
class << self
|
13
13
|
|
14
14
|
# Handle for the client instance
|
15
15
|
attr_accessor :api_client
|
16
16
|
|
17
|
-
def new
|
18
|
-
@api_client = ThePirateBay::Client.new
|
17
|
+
def new
|
18
|
+
@api_client = ThePirateBay::Client.new
|
19
19
|
end
|
20
20
|
|
21
21
|
# Delegate to ThePirateBay::Client
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'the_pirate_bay/torrent'
|
2
|
+
require 'the_pirate_bay/torrent/collection'
|
3
3
|
|
4
4
|
module ThePirateBay
|
5
|
-
class Client
|
6
|
-
|
5
|
+
class Client
|
6
|
+
|
7
7
|
def torrents
|
8
8
|
Torrent
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
end # Client
|
12
|
-
end # ThePirateBay
|
12
|
+
end # ThePirateBay
|
@@ -1,34 +1,45 @@
|
|
1
1
|
module ThePirateBay
|
2
|
-
class Torrent <
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
2
|
+
class Torrent < HyperAPI::Base
|
3
|
+
extend Connection
|
4
|
+
|
5
|
+
integer id: 'a[title=Files]' do
|
6
|
+
attribute('href').value.match(/(\d+)\/$/)[1]
|
7
|
+
end
|
8
|
+
|
9
|
+
string name: 'div#title' do
|
10
|
+
text.sanitize!
|
11
|
+
end
|
12
|
+
|
13
|
+
string magnet_uri: 'div.download a' do
|
14
|
+
attribute('href').value
|
15
|
+
end
|
16
|
+
|
17
|
+
string hash: '#details dd' do
|
18
|
+
last.next.text.strip
|
19
|
+
end
|
20
|
+
|
21
|
+
string description: 'div.nfo' do
|
22
|
+
text.strip
|
23
|
+
end
|
24
|
+
|
25
|
+
string imdb_id: '#details dd a[title=IMDB]' do
|
26
|
+
attribute('href').value.match(/\/(\w+)\/$/)[1]
|
27
|
+
end
|
28
|
+
|
29
|
+
OPTIONAL_ATTRS = {
|
30
|
+
:seeders => 'Seeders',
|
31
|
+
:leechers => 'Leechers',
|
32
|
+
:quality => 'Quality',
|
33
|
+
:size => 'Size',
|
34
|
+
:type => 'Type',
|
35
|
+
:uploaded_at => 'Uploaded',
|
36
|
+
:uploaded_by => 'By',
|
37
|
+
:comments_count => 'Comments',
|
38
|
+
:files_count => 'Files',
|
39
|
+
:spoken_language => 'Spoken language(s)',
|
40
|
+
:written_language => 'Texted language(s)',
|
41
|
+
:tags => 'Tag(s)',
|
42
|
+
}
|
32
43
|
|
33
44
|
class << self
|
34
45
|
|
@@ -41,18 +52,18 @@ module ThePirateBay
|
|
41
52
|
#
|
42
53
|
# Examples
|
43
54
|
#
|
44
|
-
# search(
|
45
|
-
# search(
|
55
|
+
# search('Fringe')
|
56
|
+
# search('Fringe s05e07')
|
46
57
|
#
|
47
58
|
# Returns an array of ThePirateBay::Torrent::Collection objects.
|
48
59
|
def search(query)
|
49
|
-
uri =
|
60
|
+
uri = 'search/' + CGI::escape(query)
|
50
61
|
html = request(uri) # Returns search html
|
51
62
|
|
52
63
|
# Get torrents table rows from html
|
53
64
|
# and return as ruby objects
|
54
|
-
html.
|
55
|
-
Torrent::Collection.new(torrent_html)
|
65
|
+
html.css('#searchResult tr')[1..-1].collect do |torrent_html|
|
66
|
+
Torrent::Collection.new(torrent_html.to_s)
|
56
67
|
end
|
57
68
|
end
|
58
69
|
|
@@ -64,82 +75,36 @@ module ThePirateBay
|
|
64
75
|
#
|
65
76
|
# Examples
|
66
77
|
#
|
67
|
-
# find(
|
78
|
+
# find('7723168')
|
68
79
|
# find(7723709)
|
69
80
|
#
|
70
81
|
# Returns an instance of ThePirateBay::Torrent
|
71
82
|
def find(id)
|
72
83
|
html = request("torrent/#{id}") # Returns torrent html
|
73
|
-
|
74
|
-
# Initialize Torrent from html
|
75
|
-
new(id, html)
|
84
|
+
new(html)
|
76
85
|
end
|
77
86
|
alias :get :find
|
78
87
|
end
|
79
88
|
|
80
|
-
def initialize(
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
# Get attributes and values html lists
|
85
|
-
attrs = html.css("#details dt").map(&:text).map { |a| a.gsub(":", "") }
|
86
|
-
values = html.css("#details dd").map(&:text)
|
89
|
+
def initialize(html)
|
90
|
+
opt_attrs = html.css('#details dt').map(&:text).map { |a| a.gsub(':', '') }
|
91
|
+
values = html.css('#details dd').map(&:text)
|
87
92
|
|
88
|
-
|
89
|
-
set_attributes(attrs, values)
|
93
|
+
set_optional_attributes(opt_attrs, values)
|
90
94
|
|
91
|
-
|
95
|
+
super(html.to_s)
|
92
96
|
end
|
93
97
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
self.public_send("#{attr}=", value) unless value.empty?
|
102
|
-
rescue NoMethodError => e
|
103
|
-
raise e unless e.name == :"="
|
104
|
-
raise UnknownAttributeError, "unknown attribute: #{dirty_attr}"
|
98
|
+
def set_optional_attributes(opt_attrs, values)
|
99
|
+
opt_attrs.zip(values).each do |opt_attr, value|
|
100
|
+
attr = OPTIONAL_ATTRS.key(opt_attr) or next
|
101
|
+
instance_variable_set("@#{attr}", value.sanitize!)
|
102
|
+
|
103
|
+
self.class.send :define_method, attr do
|
104
|
+
instance_variable_get("@#{attr}")
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
def name
|
110
|
-
@name ||= html.css("div#title").text.sanitize!
|
111
|
-
end
|
112
|
-
|
113
|
-
def magnet_uri
|
114
|
-
@magnet_uri ||= html.css("div.download a").attribute("href").value
|
115
|
-
end
|
116
|
-
|
117
|
-
def hash
|
118
|
-
@hash ||= html.css("#details dd")[-1].next.text.strip
|
119
|
-
end
|
120
|
-
|
121
|
-
def description
|
122
|
-
@description ||= html.css("div.nfo").text.strip
|
123
|
-
end
|
124
|
-
|
125
|
-
def imdb_id
|
126
|
-
@imdb_id ||= html.css("#details dd a[title=IMDB]").attribute("href").value.
|
127
|
-
match(/\/(\w+)\/$/)[1]
|
128
|
-
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
def attributes_map
|
133
|
-
ATTRS_MAP
|
134
|
-
end
|
135
|
-
|
136
|
-
def class_attributes
|
137
|
-
ATTRS
|
138
|
-
end
|
139
|
-
|
140
|
-
def skip_attributes
|
141
|
-
SKIP_ATTRS
|
142
|
-
end
|
143
|
-
|
144
109
|
end # Torrent
|
145
110
|
end # ThePirateBay
|
@@ -1,72 +1,37 @@
|
|
1
1
|
module ThePirateBay
|
2
|
-
class Torrent::Collection
|
3
|
-
include Model
|
2
|
+
class Torrent::Collection < HyperAPI::Base
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
attr_accessor *ATTRS, :html
|
9
|
-
|
10
|
-
def initialize(html)
|
11
|
-
@html = html # Save html to get instance attributes
|
12
|
-
set_attributes
|
13
|
-
|
14
|
-
return self
|
15
|
-
end
|
16
|
-
|
17
|
-
def set_attributes
|
18
|
-
class_attributes.collect do |attr|
|
19
|
-
self.public_send("#{attr}=", send(attr))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def id
|
24
|
-
@id ||= html.css('td div.detName').inner_html.match(/\/torrent\/(\d+)\//)[1]
|
4
|
+
integer id: '.detName a' do
|
5
|
+
attribute('href').value.match(/\/torrent\/(\d+)\//)[1]
|
25
6
|
end
|
26
7
|
|
27
|
-
|
28
|
-
@name ||= html.css('td div.detName a').text
|
29
|
-
end
|
30
|
-
|
31
|
-
def type
|
32
|
-
@type ||= html.css('td[1] a').map(&:text).join(" > ")
|
33
|
-
end
|
8
|
+
string name: '.detName a'
|
34
9
|
|
35
|
-
|
36
|
-
|
10
|
+
string magnet_uri: '.detName + a' do
|
11
|
+
attribute('href').value
|
37
12
|
end
|
38
13
|
|
39
|
-
|
40
|
-
@seeders ||= html.css('td')[2].text
|
41
|
-
end
|
14
|
+
integer seeders: 'td[3]'
|
42
15
|
|
43
|
-
|
44
|
-
@leechers ||= html.css('td')[3].text
|
45
|
-
end
|
46
|
-
|
47
|
-
def magnet_uri
|
48
|
-
@magnet_uri ||= html.css('td')[1].css('div.detName + a').attribute("href").value
|
49
|
-
end
|
16
|
+
integer leechers: 'td[4]'
|
50
17
|
|
51
|
-
|
52
|
-
|
18
|
+
string size: 'font.detDesc' do
|
19
|
+
text.match(/Size (.*),/)[1].gsub('i', '')
|
53
20
|
end
|
54
21
|
|
55
|
-
|
56
|
-
|
22
|
+
string type: 'td[1] a' do
|
23
|
+
map(&:text).join(' > ')
|
57
24
|
end
|
58
25
|
|
59
|
-
|
60
|
-
|
61
|
-
comments.attribute("alt").value.match(/\d+/)[0]
|
62
|
-
end
|
26
|
+
string uploaded_at: 'font.detDesc' do
|
27
|
+
text.match(/Uploaded (.*), S/)[1]
|
63
28
|
end
|
64
29
|
|
65
|
-
|
30
|
+
string uploaded_by: 'font.detDesc a'
|
66
31
|
|
67
|
-
|
68
|
-
|
32
|
+
integer comments_count: 'img[@src*="comment.gif"]' do
|
33
|
+
attribute('alt').value.match(/\d+/)[0]
|
69
34
|
end
|
70
35
|
|
71
|
-
end
|
72
|
-
end
|
36
|
+
end
|
37
|
+
end
|
@@ -166,7 +166,7 @@
|
|
166
166
|
<div class="detName"> <a href="/torrent/7810640/Fringe_S05E06_Season_5_Episode_6_HDTV_x264_[GlowGaze]" class="detLink" title="Details for Fringe S05E06 Season 5 Episode 6 HDTV x264 [GlowGaze]">Fringe S05E06 Season 5 Episode 6 HDTV x264 [GlowGaze]</a>
|
167
167
|
</div>
|
168
168
|
<a href="magnet:?xt=urn:btih:0f4e3c1a4618b6d9658427e7778c602cd7c05ea0&dn=Fringe+S05E06+Season+5+Episode+6+HDTV+x264+%5BGlowGaze%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80" title="Download this torrent using magnet"><img src="//static.thepiratebay.se/img/icon-magnet.gif" alt="Magnet link" /></a><img src="//static.thepiratebay.se/img/icon_comment.gif" alt="This torrent has 2 comments." title="This torrent has 2 comments." /><img src="//static.thepiratebay.se/img/icon_image.gif" alt="This torrent has a cover image" title="This torrent has a cover image" /><a href="/user/GlowGaze"><img src="//static.thepiratebay.se/img/trusted.png" alt="Trusted" title="Trusted" style="width:11px;" border='0' /></a>
|
169
|
-
<font class="detDesc">Uploaded Today
|
169
|
+
<font class="detDesc">Uploaded Today 04:11, Size 303.89 MiB, ULed by <a class="detDesc" href="/user/GlowGaze/" title="Browse GlowGaze">GlowGaze</a></font>
|
170
170
|
</td>
|
171
171
|
<td align="right">413</td>
|
172
172
|
<td align="right">117</td>
|
@@ -649,8 +649,8 @@
|
|
649
649
|
|
650
650
|
<iframe src="http://cdn1.adexprt.com/clkads/bottom.html" width="728" height="90" frameborder="0" scrolling="no"></iframe>
|
651
651
|
<p>
|
652
|
-
<a href="/login" title="Login">Login</a> |
|
653
|
-
<a href="/register" title="Register">Register</a> |
|
652
|
+
<a href="/login" title="Login">Login</a> |
|
653
|
+
<a href="/register" title="Register">Register</a> |
|
654
654
|
<a href="/language" title="Select language">Language / Select language</a> |
|
655
655
|
<a href="/about" title="About">About</a> |
|
656
656
|
<a href="/legal" title="Legal threats">Legal threats</a> |
|
@@ -689,4 +689,4 @@
|
|
689
689
|
<script type="text/javascript" src="http://cdn2.adexprt.com/clkads/pop.js"></script>
|
690
690
|
<!-- abc: MX 0 -->
|
691
691
|
</body>
|
692
|
-
</html>
|
692
|
+
</html>
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,6 @@ require "webmock/rspec"
|
|
8
8
|
#
|
9
9
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
10
|
RSpec.configure do |config|
|
11
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
11
|
config.run_all_when_everything_filtered = true
|
13
12
|
config.filter_run :focus
|
14
13
|
|
@@ -29,4 +28,4 @@ end
|
|
29
28
|
|
30
29
|
def stub_get(path, endpoint = ThePirateBay::ENDPOINT.to_s)
|
31
30
|
stub_request(:get, [endpoint, path].join('/'))
|
32
|
-
end
|
31
|
+
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThePirateBay::Torrent do
|
4
4
|
let(:api) { ThePirateBay.new }
|
5
5
|
|
6
|
-
context
|
6
|
+
context '.search' do
|
7
7
|
before do
|
8
|
-
stub_get(
|
9
|
-
to_return(:status => 200, :body => fixture(
|
10
|
-
@torrents = api.torrents.search(
|
8
|
+
stub_get('search/Fringe').
|
9
|
+
to_return(:status => 200, :body => fixture('torrent/search.html'))
|
10
|
+
@torrents = api.torrents.search('Fringe')
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
@torrents.class.
|
13
|
+
it 'returns torrents results' do
|
14
|
+
expect(@torrents.class).to eq(Array)
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
@torrents.first.class.
|
17
|
+
it 'instantiates torrents collection objects' do
|
18
|
+
expect(@torrents.first.class).to eq(ThePirateBay::Torrent::Collection)
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'parses torrents attributes correctly' do
|
22
22
|
torrent = @torrents.first
|
23
|
-
torrent.id.
|
24
|
-
torrent.name.
|
25
|
-
torrent.type.
|
26
|
-
torrent.size
|
27
|
-
torrent.seeders
|
28
|
-
torrent.leechers
|
29
|
-
torrent.magnet_uri
|
30
|
-
torrent.uploaded_at
|
31
|
-
torrent.uploaded_by
|
32
|
-
torrent.comments_count
|
23
|
+
expect(torrent.id).to eq(7810640)
|
24
|
+
expect(torrent.name).to eq('Fringe S05E06 Season 5 Episode 6 HDTV x264 [GlowGaze]')
|
25
|
+
expect(torrent.type).to eq('Video > TV shows')
|
26
|
+
expect(torrent.size).to eq('303.89 MB')
|
27
|
+
expect(torrent.seeders).to eq(413)
|
28
|
+
expect(torrent.leechers).to eq(117)
|
29
|
+
expect(torrent.magnet_uri).to eq('magnet:?xt=urn:btih:0f4e3c1a4618b6d9658427e7778c602cd7c05ea0&dn=Fringe+S05E06+Season+5+Episode+6+HDTV+x264+%5BGlowGaze%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80')
|
30
|
+
expect(torrent.uploaded_at).to eq('Today 04:11')
|
31
|
+
expect(torrent.uploaded_by).to eq('GlowGaze')
|
32
|
+
expect(torrent.comments_count).to eq(2)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
37
|
-
it
|
38
|
-
stub_get(
|
39
|
-
to_return(:status => 200, :body => fixture(
|
36
|
+
context '.find' do
|
37
|
+
it 'returns a particular torrent' do
|
38
|
+
stub_get('torrent/7723168').
|
39
|
+
to_return(:status => 200, :body => fixture('torrent/find.html'))
|
40
40
|
|
41
|
-
torrent = api.torrents.find(
|
42
|
-
torrent.id.
|
43
|
-
torrent.name.
|
44
|
-
torrent.description.
|
45
|
-
torrent.seeders.
|
46
|
-
torrent.leechers.
|
47
|
-
torrent.quality.
|
48
|
-
torrent.size.
|
49
|
-
torrent.type.
|
50
|
-
torrent.hash.
|
51
|
-
torrent.uploaded_at.
|
52
|
-
torrent.uploaded_by.
|
53
|
-
torrent.comments_count.
|
54
|
-
torrent.files_count.
|
55
|
-
torrent.spoken_language.
|
56
|
-
torrent.written_language.
|
57
|
-
torrent.tags.
|
58
|
-
torrent.imdb_id.
|
41
|
+
torrent = api.torrents.find('7723168')
|
42
|
+
expect(torrent.id).to eq(7723168)
|
43
|
+
expect(torrent.name).to eq('Fringe S05E03 HDTV x264-LOL [eztv]')
|
44
|
+
expect(torrent.description).to eq("#EZTV @ EFNet -> To avoid fakes, ALWAYS check that the torrent was added by eztv. \nhttp://eztv.it/\n\nEpisode: Fringe S05E03 HDTV x264-LOL\nScreenshots:")
|
45
|
+
expect(torrent.seeders).to eq('2461')
|
46
|
+
expect(torrent.leechers).to eq('118')
|
47
|
+
expect(torrent.quality).to eq('+4 / -0 (+4)')
|
48
|
+
expect(torrent.size).to eq('288.87 MiB (302897843 Bytes)')
|
49
|
+
expect(torrent.type).to eq('Video > TV shows')
|
50
|
+
expect(torrent.hash).to eq('84C153E4064D1AC1CC151A09070C8740C318D271')
|
51
|
+
expect(torrent.uploaded_at).to eq('2012-10-13 12:33:16 GMT')
|
52
|
+
expect(torrent.uploaded_by).to eq('eztv')
|
53
|
+
expect(torrent.comments_count).to eq('6')
|
54
|
+
expect(torrent.files_count).to eq('1')
|
55
|
+
expect(torrent.spoken_language).to eq('English')
|
56
|
+
expect(torrent.written_language).to eq('French')
|
57
|
+
expect(torrent.tags).to eq('YIFY 720p 1080p movies x264 Bluray BrRip')
|
58
|
+
expect(torrent.imdb_id).to eq('tt1985966')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/spec/the_pirate_bay_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe ThePirateBay do
|
4
|
-
|
4
|
+
|
5
5
|
it "should respond to 'new' message" do
|
6
|
-
subject.
|
6
|
+
expect(subject).to respond_to(:new)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should receive 'new' and initialize ThePirateBay::Client instance" do
|
10
|
-
subject.new.
|
10
|
+
expect(subject.new).to be_a(ThePirateBay::Client)
|
11
11
|
end
|
12
|
-
|
13
|
-
end
|
12
|
+
|
13
|
+
end
|
data/the_pirate_bay.gemspec
CHANGED
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'the_pirate_bay/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'the_pirate_bay'
|
8
8
|
gem.version = ThePirateBay::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
9
|
+
gem.authors = ['Javier Saldana']
|
10
|
+
gem.email = ['javier@tractical.com']
|
11
11
|
gem.description = %q{Ruby Client for ThePirateBay.se}
|
12
12
|
gem.summary = %q{ThePirateBay.se Client}
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = 'https://github.com/jassa/the_pirate_bay'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.add_dependency
|
21
|
-
gem.add_dependency
|
22
|
-
gem.add_dependency
|
20
|
+
gem.add_dependency 'faraday', '~> 0.8.4'
|
21
|
+
gem.add_dependency 'faraday_middleware', '~> 0.8.4'
|
22
|
+
gem.add_dependency 'nokogiri', '~> 1.6.0'
|
23
|
+
gem.add_dependency 'hyper_api', '~> 0.1.1'
|
23
24
|
|
24
|
-
gem.add_development_dependency
|
25
|
-
gem.add_development_dependency
|
25
|
+
gem.add_development_dependency 'rspec', '~> 3.0.0.beta1'
|
26
|
+
gem.add_development_dependency 'webmock', '~> 1.9.0'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_pirate_bay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.6.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: hyper_api
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.1.1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.1.1
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: rspec
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +82,7 @@ dependencies:
|
|
66
82
|
requirements:
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
85
|
+
version: 3.0.0.beta1
|
70
86
|
type: :development
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
93
|
+
version: 3.0.0.beta1
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: webmock
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,12 +122,9 @@ files:
|
|
106
122
|
- README.md
|
107
123
|
- Rakefile
|
108
124
|
- lib/the_pirate_bay.rb
|
109
|
-
- lib/the_pirate_bay/api.rb
|
110
125
|
- lib/the_pirate_bay/client.rb
|
111
126
|
- lib/the_pirate_bay/connection.rb
|
112
127
|
- lib/the_pirate_bay/core_ext/string.rb
|
113
|
-
- lib/the_pirate_bay/errors.rb
|
114
|
-
- lib/the_pirate_bay/model.rb
|
115
128
|
- lib/the_pirate_bay/response.rb
|
116
129
|
- lib/the_pirate_bay/response/htmlize.rb
|
117
130
|
- lib/the_pirate_bay/torrent.rb
|
data/lib/the_pirate_bay/api.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require "the_pirate_bay/connection"
|
2
|
-
|
3
|
-
module ThePirateBay
|
4
|
-
class API
|
5
|
-
extend Connection
|
6
|
-
|
7
|
-
def initialize(options={}, &block)
|
8
|
-
super()
|
9
|
-
set_api_client
|
10
|
-
self
|
11
|
-
|
12
|
-
self.instance_eval(&block) if block_given?
|
13
|
-
end
|
14
|
-
|
15
|
-
# Assigns current api class
|
16
|
-
def set_api_client
|
17
|
-
ThePirateBay.api_client = self
|
18
|
-
end
|
19
|
-
|
20
|
-
end # API
|
21
|
-
end # ThePirateBay
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ThePirateBay
|
2
|
-
|
3
|
-
# Generic ThePirateBay exception class.
|
4
|
-
class ThePirateBayError < StandardError
|
5
|
-
end
|
6
|
-
|
7
|
-
# Raised when a connection to the api can't be established.
|
8
|
-
class ConnectionNotEstablished < StandardError
|
9
|
-
end
|
10
|
-
|
11
|
-
# Raised when the record was not found given an id or set of ids.
|
12
|
-
class RecordNotFound < StandardError
|
13
|
-
end
|
14
|
-
|
15
|
-
# Raised when unknown attributes are supplied via mass assignment.
|
16
|
-
class UnknownAttributeError < NoMethodError
|
17
|
-
end
|
18
|
-
end
|
data/lib/the_pirate_bay/model.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module ThePirateBay
|
2
|
-
module Model
|
3
|
-
|
4
|
-
def attributes
|
5
|
-
attrs = {}
|
6
|
-
class_attributes.each do |name|
|
7
|
-
attrs[name] = send(name)
|
8
|
-
end
|
9
|
-
attrs
|
10
|
-
end
|
11
|
-
|
12
|
-
def inspect
|
13
|
-
inspection = unless id.nil?
|
14
|
-
class_attributes.collect { |name|
|
15
|
-
"#{name}: #{attribute_for_inspect(name)}"
|
16
|
-
}.compact.join(", ")
|
17
|
-
else
|
18
|
-
"not initialized"
|
19
|
-
end
|
20
|
-
"#<#{self.class} #{inspection}>"
|
21
|
-
end
|
22
|
-
|
23
|
-
def attribute_for_inspect(attr_name)
|
24
|
-
value = send(attr_name)
|
25
|
-
|
26
|
-
if value.is_a?(String) && value.length > 50
|
27
|
-
"#{value[0..50]}...".inspect
|
28
|
-
elsif value.is_a?(Date) || value.is_a?(Time)
|
29
|
-
%("#{value.to_s(:db)}")
|
30
|
-
else
|
31
|
-
value.inspect
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end # Model
|
36
|
-
end # ThePirateBay
|