the_pirate_bay 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ only:
3
+ - master
4
+ rvm:
5
+ - 1.9.2
6
+ - 1.9.3
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Gem dependencies are specified in the_pirate_bay.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "rake", ">= 0.8.7"
8
+ end
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new do |r|
5
+ r.verbose = false
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,11 @@
1
+ require "the_pirate_bay/torrent"
2
+
3
+ module ThePirateBay
4
+ class Client < API
5
+
6
+ def torrents
7
+ Torrent
8
+ end
9
+
10
+ end # Client
11
+ end # ThePirateBay
@@ -0,0 +1,22 @@
1
+ require "faraday"
2
+
3
+ module ThePirateBay
4
+ module Connection
5
+ extend self
6
+
7
+ @connection = nil
8
+
9
+ def connection
10
+ @connection ||= Faraday.new(:url => ThePirateBay::ENDPOINT) do |faraday|
11
+ faraday.response :logger if ENV['DEBUG'] # log requests to STDOUT
12
+ faraday.adapter :net_http # make requests with NetHTTP
13
+ end
14
+ end
15
+
16
+ def request(path, params={})
17
+ response = connection.get(path, params)
18
+ response.body
19
+ end
20
+
21
+ end # Connection
22
+ end # ThePirateBay
@@ -0,0 +1,53 @@
1
+ module ThePirateBay
2
+ module Model
3
+
4
+ attr_accessor :klass
5
+
6
+ def initialize(params=nil)
7
+ @klass = self.class
8
+ self.attributes = params
9
+ end
10
+
11
+ def attributes=(params=nil)
12
+ params.each do |attr, value|
13
+ begin
14
+ self.public_send("#{klass::ATTRS_MAP.key(attr)}=", value)
15
+ rescue NoMethodError
16
+ raise UnknownAttributeError, "unknown attribute: #{attr}"
17
+ end
18
+ end if params
19
+ end
20
+
21
+ def attributes
22
+ attrs = {}
23
+ klass::ATTRS_MAP.keys.each do |name|
24
+ attrs[name] = send(name)
25
+ end
26
+ attrs
27
+ end
28
+
29
+ def inspect
30
+ inspection = unless id.nil?
31
+ klass::ATTRS_MAP.keys.collect { |name|
32
+ "#{name}: #{attribute_for_inspect(name)}"
33
+ }.compact.join(", ")
34
+ else
35
+ "not initialized"
36
+ end
37
+ "#<#{self.class} #{inspection}>"
38
+ end
39
+
40
+ def attribute_for_inspect(attr_name)
41
+ value = send(attr_name)
42
+
43
+ if value.is_a?(String) && value.length > 50
44
+ "#{value[0..50]}...".inspect
45
+ elsif value.is_a?(Date) || value.is_a?(Time)
46
+ %("#{value.to_s(:db)}")
47
+ else
48
+ value.inspect
49
+ end
50
+ end
51
+
52
+ end # Model
53
+ end # ThePirateBay
@@ -0,0 +1,22 @@
1
+ module ThePirateBay
2
+ class Torrent < API
3
+ include Model
4
+
5
+ ATTRS = [:id, :name, :description, :seeders, :leechers, :hash, :magnet_uri, :quality, :size, :type,
6
+ :uploaded_at, :comments_count, :files_count, :spoken_language, :written_language, :imdb_id].freeze
7
+
8
+ attr_accessor *ATTRS, :comments, :uploader, :tags
9
+
10
+ class << self
11
+ def search(query)
12
+ data = request("search/#{query}/0/99/0")
13
+ end
14
+
15
+ def find(id)
16
+ data = request("torrent/#{id}")
17
+ end
18
+ alias :get :find
19
+ end
20
+
21
+ end # Torrent
22
+ end # ThePirateBay
@@ -1,3 +1,3 @@
1
1
  module ThePirateBay
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,4 +1,30 @@
1
1
  require "the_pirate_bay/version"
2
+ require "the_pirate_bay/api"
3
+ require "the_pirate_bay/model"
4
+ require "the_pirate_bay/client"
2
5
 
3
6
  module ThePirateBay
4
- end
7
+
8
+ ENDPOINT = "http://thepiratebay.se".freeze
9
+
10
+ class << self
11
+
12
+ # Handle for the client instance
13
+ attr_accessor :api_client
14
+
15
+ def new(options={}, &block)
16
+ @api_client = ThePirateBay::Client.new(options, &block)
17
+ end
18
+
19
+ # Delegate to ThePirateBay::Client
20
+ def method_missing(method, *args, &block)
21
+ return super unless new.respond_to?(method)
22
+ new.send(method, *args, &block)
23
+ end
24
+
25
+ def respond_to?(method, include_private = false)
26
+ new.respond_to?(method, include_private) || super(method, include_private)
27
+ end
28
+
29
+ end # Self
30
+ end # ThePirateBay
@@ -0,0 +1,19 @@
1
+ require "the_pirate_bay"
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe ThePirateBay::Torrent do
4
+ let(:api) { ThePirateBay.new }
5
+
6
+ context ".search" do
7
+ it "returns html torrents results" do
8
+ api.torrents.search("Fringe").should include("Fringe")
9
+ end
10
+ end
11
+
12
+ context ".find" do
13
+ it "returns a particular torrent html" do
14
+ api.torrents.find("7723168").should include("Fringe S05E03 HDTV")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe ThePirateBay do
4
+
5
+ it "should respond to 'new' message" do
6
+ subject.should respond_to :new
7
+ end
8
+
9
+ it "should receive 'new' and initialize ThePirateBay::Client instance" do
10
+ subject.new.should be_a ThePirateBay::Client
11
+ end
12
+
13
+ end
@@ -16,4 +16,9 @@ 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
+
23
+ gem.add_development_dependency "rspec", "~> 2.11.0"
19
24
  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.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,41 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-19 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70282189528700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70282189528700
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70282189528200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.5.5
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70282189528200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70282189527740 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.11.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70282189527740
14
47
  description: Ruby Client for ThePirateBay.se
15
48
  email:
16
49
  - javier@tractical.com
@@ -19,12 +52,22 @@ extensions: []
19
52
  extra_rdoc_files: []
20
53
  files:
21
54
  - .gitignore
55
+ - .rspec
56
+ - .travis.yml
22
57
  - Gemfile
23
58
  - LICENSE.txt
24
59
  - README.md
25
60
  - Rakefile
26
61
  - lib/the_pirate_bay.rb
62
+ - lib/the_pirate_bay/api.rb
63
+ - lib/the_pirate_bay/client.rb
64
+ - lib/the_pirate_bay/connection.rb
65
+ - lib/the_pirate_bay/model.rb
66
+ - lib/the_pirate_bay/torrent.rb
27
67
  - lib/the_pirate_bay/version.rb
68
+ - spec/spec_helper.rb
69
+ - spec/the_pirate_bay/torrent_spec.rb
70
+ - spec/the_pirate_bay_spec.rb
28
71
  - the_pirate_bay.gemspec
29
72
  homepage: https://github.com/jassa/the_pirate_bay
30
73
  licenses: []
@@ -50,4 +93,7 @@ rubygems_version: 1.8.11
50
93
  signing_key:
51
94
  specification_version: 3
52
95
  summary: ThePirateBay.se Client
53
- test_files: []
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/the_pirate_bay/torrent_spec.rb
99
+ - spec/the_pirate_bay_spec.rb