subdb 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Wilker Lucio da Silva
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1 @@
1
+ Under development
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ task :default => [:test]
2
+
3
+ desc "Download fixture files for tests"
4
+ task :download_fixtures do
5
+ puts "need implementation"
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :test do
10
+ $: << File.expand_path("../lib", __FILE__)
11
+ $: << File.expand_path("../test", __FILE__)
12
+
13
+ Dir["test/**/*_test.rb"].each do |test|
14
+ require test
15
+ end
16
+ end
data/lib/subdb.rb ADDED
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2011 Wilker Lucio da Silva
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'digest/md5'
23
+
24
+ class Subdb
25
+ VIDEO_EXTENSIONS = ['.avi', '.mkv', '.mp4', '.mov', '.mpg', '.wmv', '.rm', '.rmvb', '.divx']
26
+ SUB_EXTESNIONS = ['.srt', '.sub']
27
+
28
+ API = "http://api.thesubdb.com/"
29
+ SANDBOX = "http://sandbox.thesubdb.com/"
30
+
31
+ class << self
32
+ attr_accessor :test_mode
33
+
34
+ def api_url
35
+ test_mode ? SANDBOX : API
36
+ end
37
+ end
38
+
39
+ self.test_mode = false
40
+
41
+ attr_reader :hash
42
+
43
+ def initialize(path)
44
+ fail "#{@path} is not a file" unless File.exists?(path)
45
+
46
+ @path = path
47
+ @hash = build_hash
48
+ end
49
+
50
+ protected
51
+
52
+ def build_hash
53
+ chunk_size = 64 * 1024
54
+
55
+ size = File.size(@path)
56
+ file = File.open(@path, "r")
57
+ data = file.read(chunk_size)
58
+ file.seek(size - chunk_size)
59
+ data += file.read(chunk_size)
60
+
61
+ Digest::MD5.hexdigest(data)
62
+ end
63
+ end
data/subdb.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{subdb}
3
+ s.version = "0.0.1"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Wilker Lucio"]
7
+ s.date = %q{2011-04-19}
8
+ s.description = %q{API for SubDB}
9
+ s.email = %q{wilkerlucio@gmail.com}
10
+ s.extra_rdoc_files = [
11
+ "LICENSE",
12
+ "README.textile"
13
+ ]
14
+ s.files = [
15
+ ".gitignore",
16
+ "LICENSE",
17
+ "README.textile",
18
+ "Rakefile",
19
+ "lib/subdb.rb",
20
+ "subdb.gemspec",
21
+ ]
22
+ s.homepage = %q{http://github.com/wilkerlucio/mongoid_taggable}
23
+ s.rdoc_options = ["--charset=UTF-8"]
24
+ s.require_paths = ["lib"]
25
+ s.rubygems_version = %q{1.7.2}
26
+ s.summary = %q{SubDB Ruby API}
27
+ s.test_files = [
28
+ "test/test_helper.rb",
29
+ "test/subdb_test.rb"
30
+ ]
31
+
32
+ if s.respond_to? :specification_version then
33
+ s.specification_version = 3
34
+
35
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
36
+ else
37
+ end
38
+ else
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2011 Wilker Lucio da Silva
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'test_helper'
23
+
24
+ class SubdbTest < Test::Unit::TestCase
25
+ TEST_FILES = {
26
+ :dexter => {
27
+ :path => File.expand_path("../fixtures/dexter.mp4", __FILE__),
28
+ :hash => "ffd8d4aa68033dc03d1c8ef373b9028c"
29
+ },
30
+
31
+ :justified => {
32
+ :path => File.expand_path("../fixtures/justified.mp4", __FILE__),
33
+ :hash => "edc1981d6459c6111fe36205b4aff6c2"
34
+ }
35
+ }
36
+
37
+ def test_self_api_url
38
+ Subdb.test_mode = false
39
+ assert_equal("http://api.thesubdb.com/", Subdb.api_url)
40
+
41
+ Subdb.test_mode = true
42
+ assert_equal("http://sandbox.thesubdb.com/", Subdb.api_url)
43
+ end
44
+
45
+ def test_initialize_with_invalid_file
46
+ assert_raise(RuntimeError) { Subdb.new("invalid") }
47
+ end
48
+
49
+ def test_file_hash
50
+ TEST_FILES.each do |name, file|
51
+ sub = Subdb.new(file[:path])
52
+ assert_equal(file[:hash], sub.hash)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2011 Wilker Lucio da Silva
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'test/unit'
23
+ require 'subdb'
24
+
25
+ Subdb.test_mode = true
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subdb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Wilker Lucio
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-19 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: API for SubDB
23
+ email: wilkerlucio@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.textile
31
+ files:
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.textile
35
+ - Rakefile
36
+ - lib/subdb.rb
37
+ - subdb.gemspec
38
+ - test/test_helper.rb
39
+ - test/subdb_test.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/wilkerlucio/mongoid_taggable
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: SubDB Ruby API
74
+ test_files:
75
+ - test/test_helper.rb
76
+ - test/subdb_test.rb