the_pirate_bay 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,27 @@
1
1
  require "faraday"
2
+ require "faraday_middleware"
2
3
  require "the_pirate_bay/response"
3
4
  require "the_pirate_bay/response/htmlize"
4
5
 
5
6
  module ThePirateBay
6
7
  module Connection
7
8
  extend self
8
-
9
+
9
10
  @connection = nil
10
-
11
+
11
12
  def connection
12
13
  @connection ||= Faraday.new(:url => ThePirateBay::ENDPOINT) do |faraday|
14
+ faraday.use FaradayMiddleware::FollowRedirects, limit: 5 # TPB is moving a lot
13
15
  faraday.response :logger if ENV['DEBUG'] # log requests to STDOUT
14
- faraday.adapter :net_http # make requests with NetHTTP
15
- faraday.use ThePirateBay::Response::Htmlize
16
+ faraday.adapter :net_http # make requests with NetHTTP
17
+ faraday.use ThePirateBay::Response::Htmlize
16
18
  end
17
19
  end
18
-
20
+
19
21
  def request(path, params={})
20
22
  response = connection.get(path, params)
21
23
  response.body
22
24
  end
23
-
25
+
24
26
  end # Connection
25
- end # ThePirateBay
27
+ end # ThePirateBay
@@ -1,19 +1,19 @@
1
1
  module ThePirateBay
2
2
  class Torrent::Collection
3
3
  include Model
4
-
4
+
5
5
  ATTRS = [:id, :name, :seeders, :leechers, :magnet_uri,
6
6
  :size, :type, :uploaded_at, :uploaded_by, :comments_count].freeze
7
-
7
+
8
8
  attr_accessor *ATTRS, :html
9
-
9
+
10
10
  def initialize(html)
11
11
  @html = html # Save html to get instance attributes
12
12
  set_attributes
13
-
13
+
14
14
  return self
15
15
  end
16
-
16
+
17
17
  def set_attributes
18
18
  class_attributes.collect do |attr|
19
19
  self.public_send("#{attr}=", send(attr))
@@ -23,50 +23,50 @@ module ThePirateBay
23
23
  def id
24
24
  @id ||= html.css('td[2] div.detName').inner_html.match(/\/torrent\/(\d+)\//)[1]
25
25
  end
26
-
26
+
27
27
  def name
28
28
  @name ||= html.css('td[2] div.detName a').text
29
29
  end
30
-
30
+
31
31
  def type
32
32
  @type ||= html.css('td[1] a').map(&:text).join(" > ")
33
33
  end
34
-
34
+
35
35
  def size
36
36
  @size ||= html.css('td[2] font.detDesc').text.match(/Size (.*),/)[1].gsub('i', '')
37
37
  end
38
-
38
+
39
39
  def seeders
40
40
  @seeders ||= html.css('td[3]').text
41
41
  end
42
-
42
+
43
43
  def leechers
44
44
  @leechers ||= html.css('td[4]').text
45
45
  end
46
-
46
+
47
47
  def magnet_uri
48
48
  @magnet_uri ||= html.css('td[2] div.detName + a').attribute("href").value
49
49
  end
50
-
50
+
51
51
  def uploaded_at
52
52
  @uploaded_at ||= html.css('td[2] font.detDesc').text.match(/Uploaded (.*), S/)[1]
53
53
  end
54
-
54
+
55
55
  def uploaded_by
56
56
  @uploaded_by ||= html.css('td[2] font.detDesc a').text
57
57
  end
58
-
58
+
59
59
  def comments_count
60
60
  @comments_count ||= unless (comments = html.css('td[2] img[@src*="comment.gif"]')).empty?
61
61
  comments.attribute("alt").value.match(/\d+/)[0]
62
62
  end
63
63
  end
64
-
64
+
65
65
  private
66
-
66
+
67
67
  def class_attributes
68
68
  ATTRS
69
69
  end
70
-
70
+
71
71
  end # Torrent::Collection
72
- end # ThePirateBay
72
+ end # ThePirateBay
@@ -1,3 +1,3 @@
1
1
  module ThePirateBay
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -7,7 +7,7 @@ require "the_pirate_bay/client"
7
7
 
8
8
  module ThePirateBay
9
9
 
10
- ENDPOINT = "http://thepiratebay.pe".freeze
10
+ ENDPOINT = "http://thepiratebay.org".freeze
11
11
 
12
12
  class << self
13
13
 
@@ -16,10 +16,11 @@ Gem::Specification.new do |gem|
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
18
  gem.require_paths = ["lib"]
19
-
20
- gem.add_dependency "faraday", "~> 0.8.4"
21
- gem.add_dependency "nokogiri", "~> 1.5.5"
22
-
19
+
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
+
23
24
  gem.add_development_dependency "rspec", "~> 2.12.0"
24
25
  gem.add_development_dependency "webmock", "~> 1.9.0"
25
26
  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.1.0
4
+ version: 0.1.1
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: 2013-12-13 00:00:00.000000000 Z
12
+ date: 2013-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.8.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.4
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.4
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: nokogiri
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +50,7 @@ dependencies:
34
50
  requirements:
35
51
  - - ~>
36
52
  - !ruby/object:Gem::Version
37
- version: 1.5.5
53
+ version: 1.6.0
38
54
  type: :runtime
39
55
  prerelease: false
40
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +58,7 @@ dependencies:
42
58
  requirements:
43
59
  - - ~>
44
60
  - !ruby/object:Gem::Version
45
- version: 1.5.5
61
+ version: 1.6.0
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rspec
48
64
  requirement: !ruby/object:Gem::Requirement