pirata 0.2.2 → 1.2.2

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/pirata/torrent.rb +19 -82
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc2d1243005c2ea6bec88db19ba7cf62eb494633
4
- data.tar.gz: e41695acee0c7b401b72432012860b8cc0c908f8
3
+ metadata.gz: 0ad3a24405afc01433400fc2a207c8998ff7ac8f
4
+ data.tar.gz: 788fd46e74c0790e3ba25fdd3d3092742988cd6f
5
5
  SHA512:
6
- metadata.gz: 77405ccaafb20e89fdfcd042262507463351ad50f40bf4430e780790c8f8e73c3bfe9057eebe2c4c8a8ecbe1f2f1a9751fb600d12af2f53e752f6d09523f093e
7
- data.tar.gz: 69afbad0569cc2572158950acb5f2b2b6188a3874fca80c1a3abf9c5bf897652172e3fd997450179cdb551a7f238b625c1e2a1cdfbcc15426ed44f4d82fdacea
6
+ metadata.gz: ac0bd0bc6b98ed22a3790d050958b2f8d6cf0c50e272338634b77c6e5c0c792f2081b1882ad2d6f2add60d7162f834c1d44bc257e0a1013e83be96eb998e7509
7
+ data.tar.gz: e545ee074b4891980354b7dd31c95496d910071c1c77cbfb760286898b15a32f7f729d257dc1369d8cc0ed53b66f0da1a129a462209294ff18cf26eee140abb8
@@ -7,90 +7,17 @@ require 'pirata/config'
7
7
  module Pirata
8
8
  class Torrent
9
9
 
10
- attr_reader :title
10
+ attr_reader :title, :category, :url, :id, :magnet
11
11
 
12
12
  def initialize(params_hash)
13
- @params = params_hash
14
- @title = params_hash[:title]
15
- end
16
-
17
- def category
18
- @params[:category]
19
- end
20
-
21
- def title
22
- @params[:title]
23
- end
24
-
25
- def url
26
- @params[:url]
27
- end
28
-
29
- def id
30
- @params[:id]
31
- end
32
-
33
- def magnet
34
- unless @params[:magnet]
35
- update_params
36
- end
37
- @params[:magnet]
38
- end
39
-
40
- def seeders
41
- unless @params[:seeders]
42
- update_params
43
- end
44
- @params[:seeders]
45
- end
46
-
47
- def leechers
48
- unless @params[:leechers]
49
- update_params
50
- end
51
- @params[:leechers]
52
- end
53
-
54
- def uploader
55
- unless @params[:uploader]
56
- update_params
57
- end
58
- @params[:uploader]
59
- end
60
-
61
- def files
62
- unless @params[:files]
63
- update_params
64
- end
65
- @params[:files]
66
- end
13
+ @params = params_hash
14
+ @title = @params[:title]
15
+ @category = @params[:category]
16
+ @url = @params[:url]
17
+ @id = @params[:id]
18
+ @magnet = @params[:magnet]
67
19
 
68
- def size
69
- unless @params[:size]
70
- update_params
71
- end
72
- @params[:size]
73
- end
74
-
75
- def date
76
- unless @params[:date]
77
- update_params
78
- end
79
- @params[:date]
80
- end
81
-
82
- def comments
83
- unless @params[:comments]
84
- update_params
85
- end
86
- @params[:comments]
87
- end
88
-
89
- def hash
90
- unless @params[:hash]
91
- update_params
92
- end
93
- @params[:hash]
20
+ build_getters()
94
21
  end
95
22
 
96
23
  # Return a Torrent object from a corresponding ID
@@ -102,7 +29,7 @@ module Pirata
102
29
  Pirata::Torrent.new(results_hash)
103
30
  end
104
31
 
105
- def update_params
32
+ def update_params!
106
33
  html = Nokogiri::HTML(open(@params[:url], :allow_redirections => Pirata::Config::REDIRECT))
107
34
  updated_params = Pirata::Torrent.parse_torrent_page(html)
108
35
  @params.merge!(updated_params)
@@ -110,6 +37,16 @@ module Pirata
110
37
 
111
38
  private #-------------------------------------------------
112
39
 
40
+ # Initialize getters for +1 request variables, fetching them if we need them
41
+ def build_getters
42
+ [:seeders, :leechers, :uploader, :files, :size, :date, :comments, :hash].each do |m|
43
+ self.class.send(:define_method, m) {
44
+ update_params! unless @params[m]
45
+ @params[m]
46
+ }
47
+ end
48
+ end
49
+
113
50
  def self.parse_torrent_page(html)
114
51
  if html.css("#err").text.include?("404")
115
52
  raise "No torrent for supplied ID found"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pirata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Lindsay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-22 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 5.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 5.0.0
47
61
  description: A Ruby gem that exposes an API for using The Pirate Bay torrent tracker
48
62
  service.
49
63
  email: clindsay107@gmail.com
@@ -60,7 +74,7 @@ files:
60
74
  - lib/pirata/user.rb
61
75
  homepage: https://github.com/strong-code/pirata
62
76
  licenses:
63
- - GPL
77
+ - GPL-3.0
64
78
  metadata: {}
65
79
  post_install_message:
66
80
  rdoc_options: []