subtitle_source 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ require "rspec"
2
+ require "webmock/rspec"
3
+ require "subtitle_source"
4
+ require "vcr"
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ config.extend VCR::RSpec::Macros
9
+ end
10
+
11
+ VCR.config do |c|
12
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
13
+ c.stub_with :webmock
14
+ c.default_cassette_options = {
15
+ record: :new_episodes
16
+ }
17
+ c.allow_http_connections_when_no_cassette = false
18
+ end
@@ -0,0 +1,139 @@
1
+ require "spec_helper"
2
+
3
+ describe SubtitleSource do
4
+ def did_request?(path)
5
+ a_request(:get, "http://www.subtitlesource.org/api/#{@s.api_key}/3.0/#{path}").should have_been_made.once
6
+ end
7
+
8
+ before(:each) do
9
+ @s = SubtitleSource.new(ENV["API_KEY"])
10
+ end
11
+
12
+ describe "requests" do
13
+ it "should raise an error if no key is given" do
14
+ lambda {
15
+ SubtitleSource.new(nil)
16
+ }.should raise_error(ArgumentError, "You must specify an Subtitle Source API key.")
17
+ end
18
+
19
+ it "should be possible to set a language" do
20
+ VCR.use_cassette("heroes-english") do
21
+ @s.query("heroes").language("English").fetch
22
+ end
23
+
24
+ did_request?("xmlsearch/heroes/english/0")
25
+ end
26
+
27
+ it "should be possible to search for a query with whitespace" do
28
+ VCR.use_cassette("prison-break-english") do
29
+ @s.query("prison break").language("Swedish").fetch
30
+ end
31
+
32
+ did_request?("xmlsearch/prison%20break/swedish/0")
33
+ end
34
+
35
+ it "should be possible to list subtitles for any language" do
36
+ VCR.use_cassette("heroes-any-language-english") do
37
+ @s.query("Heroes.S03E09.HDTV.XviD-LOL").fetch
38
+ end
39
+
40
+ did_request?("xmlsearch/Heroes.S03E09.HDTV.XviD-LOL/all/0")
41
+ end
42
+
43
+ it "should list all subtitles related to an imdb id" do
44
+ VCR.use_cassette("imdb-0813715") do
45
+ @s.imdb("0813715").fetch
46
+ end
47
+
48
+ did_request?("xmlsearch/0813715/imdb/0")
49
+
50
+ VCR.use_cassette("imdb-0813715-page-2") do
51
+ @s.page(2).imdb("tt0813715").fetch
52
+ end
53
+
54
+ did_request?("xmlsearch/0813715/imdb/20")
55
+ end
56
+
57
+ it "should be possible to set a page" do
58
+ VCR.use_cassette("imdb-page-2") do
59
+ @s.page(2).imdb("0813715").fetch
60
+ end
61
+
62
+ did_request?("xmlsearch/0813715/imdb/20")
63
+ end
64
+
65
+ it "should be able to cache" do
66
+ VCR.use_cassette("imdb-page-2") do
67
+ 5.times { @s.page(2).imdb("0813715").fetch }
68
+ end
69
+
70
+ did_request?("xmlsearch/0813715/imdb/20")
71
+ end
72
+
73
+ it "should use the current url as cache key" do
74
+ VCR.use_cassette("imdb-page-2") do
75
+ 3.times { @s.page(1).imdb("0813715").fetch }
76
+ 3.times { @s.page(2).imdb("0813715").fetch }
77
+ end
78
+
79
+ did_request?("xmlsearch/0813715/imdb/0")
80
+ did_request?("xmlsearch/0813715/imdb/20")
81
+ end
82
+
83
+ it "should escape non valid chars in url" do
84
+ VCR.use_cassette("non-valid-chars") do
85
+ @s.query("[]").fetch
86
+ end
87
+
88
+ did_request?("xmlsearch/%5B%5D/all/0")
89
+ end
90
+ end
91
+
92
+ describe "data" do
93
+ use_vcr_cassette("imdb-0813715")
94
+ it "should return 20 subtitles" do
95
+ fetch = @s.imdb("0813715").fetch
96
+ fetch.count.should eq(20)
97
+ fetch.should be_instance_of(SubtitleSourceModule::Subtitles)
98
+ fetch.first.title.should be_instance_of(String)
99
+ fetch.first.imdb.should be_instance_of(String)
100
+ fetch.first.id.should be_instance_of(Fixnum)
101
+ fetch.first.rid.should be_instance_of(Fixnum)
102
+ fetch.first.language.should be_instance_of(String)
103
+ fetch.first.season.should be_instance_of(Fixnum)
104
+ fetch.first.episode.should be_instance_of(Fixnum)
105
+ fetch.first.release_name.should be_instance_of(String)
106
+ fetch.first.fps.should be_instance_of(Fixnum)
107
+ fetch.first.cd.should be_instance_of(Fixnum)
108
+ fetch.first.hi.should be_instance_of(Fixnum)
109
+ end
110
+
111
+ it "should return the correct imdb id" do
112
+ @s.imdb("0813715").fetch.first.imdb.should eq("tt0813715")
113
+ end
114
+
115
+ it "should be able to generate an details link" do
116
+ sub = @s.imdb("0813715").fetch.first
117
+
118
+ VCR.use_cassette("0813715-details") do
119
+ lambda {
120
+ RestClient.get(sub.details)
121
+ }.should_not raise_error(RestClient::Exception)
122
+ end
123
+
124
+ a_request(:get, "http://www.subtitlesource.org/subs/#{sub.id}/#{sub.release_name}").should have_been_made.once
125
+ end
126
+
127
+ it "should have a direct download url" do
128
+ sub = @s.imdb("0813715").fetch.first
129
+
130
+ VCR.use_cassette("0813715-url") do
131
+ lambda {
132
+ RestClient.get(sub.url)
133
+ }.should_not raise_error(RestClient::Exception)
134
+ end
135
+
136
+ a_request(:get, "http://www.subtitlesource.org/download/zip/#{sub.id}").should have_been_made.once
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "subtitle_source"
6
+ s.version = "0.0.3"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Linus Oleander"]
9
+ s.email = ["linus@oleander.nu"]
10
+ s.homepage = "https://github.com/oleander/subtitle_source"
11
+ s.summary = %q{Ruby bindings for subtitlesource.org}
12
+ s.description = %q{Ruby bindings for subtitlesource.org.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency("rest-client")
20
+ s.add_dependency("nokogiri")
21
+ s.add_dependency("levenshteinish")
22
+
23
+ s.add_development_dependency("vcr")
24
+ s.add_development_dependency("rspec")
25
+ s.add_development_dependency("webmock")
26
+
27
+ s.required_ruby_version = "~> 1.9.0"
28
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subtitle_source
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.3
6
+ platform: ruby
7
+ authors:
8
+ - Linus Oleander
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-12 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rest-client
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: levenshteinish
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: vcr
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: webmock
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
82
+ description: Ruby bindings for subtitlesource.org.
83
+ email:
84
+ - linus@oleander.nu
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - lib/subtitle_source.rb
98
+ - lib/subtitle_source/array.rb
99
+ - spec/array_spec.rb
100
+ - spec/fixtures/vcr_cassettes/0813715-details.yml
101
+ - spec/fixtures/vcr_cassettes/0813715-url.yml
102
+ - spec/fixtures/vcr_cassettes/heroes-any-language-english.yml
103
+ - spec/fixtures/vcr_cassettes/heroes-english.yml
104
+ - spec/fixtures/vcr_cassettes/imdb-0813715-page-2.yml
105
+ - spec/fixtures/vcr_cassettes/imdb-0813715.yml
106
+ - spec/fixtures/vcr_cassettes/imdb-page-2.yml
107
+ - spec/fixtures/vcr_cassettes/non-valid-chars.yml
108
+ - spec/fixtures/vcr_cassettes/prison-break-english.yml
109
+ - spec/fixtures/vcr_cassettes/tt0840361.yml
110
+ - spec/spec_helper.rb
111
+ - spec/subtitle_source_spec.rb
112
+ - subtitle_source.gemspec
113
+ has_rdoc: true
114
+ homepage: https://github.com/oleander/subtitle_source
115
+ licenses: []
116
+
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ version: 1.9.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.6.2
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Ruby bindings for subtitlesource.org
141
+ test_files:
142
+ - spec/array_spec.rb
143
+ - spec/fixtures/vcr_cassettes/0813715-details.yml
144
+ - spec/fixtures/vcr_cassettes/0813715-url.yml
145
+ - spec/fixtures/vcr_cassettes/heroes-any-language-english.yml
146
+ - spec/fixtures/vcr_cassettes/heroes-english.yml
147
+ - spec/fixtures/vcr_cassettes/imdb-0813715-page-2.yml
148
+ - spec/fixtures/vcr_cassettes/imdb-0813715.yml
149
+ - spec/fixtures/vcr_cassettes/imdb-page-2.yml
150
+ - spec/fixtures/vcr_cassettes/non-valid-chars.yml
151
+ - spec/fixtures/vcr_cassettes/prison-break-english.yml
152
+ - spec/fixtures/vcr_cassettes/tt0840361.yml
153
+ - spec/spec_helper.rb
154
+ - spec/subtitle_source_spec.rb