ruby-tmdb 0.0.21 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ruby-tmdb/tmdb.rb +8 -2
- data/ruby-tmdb.gemspec +3 -2
- data/test/fixtures/blank_result.txt +16 -0
- data/test/setup/url_mocks.rb +4 -0
- data/test/unit/tmdb_test.rb +9 -3
- metadata +4 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/ruby-tmdb/tmdb.rb
CHANGED
@@ -23,13 +23,19 @@ class Tmdb
|
|
23
23
|
def self.api_call(method, data, language = "en")
|
24
24
|
raise ArgumentError, "Tmdb.api_key must be set before using the API" if(Tmdb.api_key.nil? || Tmdb.api_key.empty?)
|
25
25
|
url = Tmdb.base_api_url + method + '/' + language + '/yaml/' + Tmdb.api_key + '/' + CGI::escape(data.to_s)
|
26
|
+
# Memoize this API call
|
26
27
|
response = @@api_response[url] ||= begin
|
27
28
|
Tmdb.get_url(url)
|
28
29
|
end
|
29
30
|
if(response.code.to_i != 200)
|
30
|
-
return
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
body = YAML::load(response.body)
|
34
|
+
if( body.first.include?("Nothing found"))
|
35
|
+
return nil
|
36
|
+
else
|
37
|
+
return body
|
31
38
|
end
|
32
|
-
YAML::load(response.body)
|
33
39
|
end
|
34
40
|
|
35
41
|
# Get a URL and return a response object, follow upto 'limit' re-directs on the way
|
data/ruby-tmdb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby-tmdb}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Gough"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-21}
|
13
13
|
s.description = %q{An ActiveRecord-style API wrapper for TheMovieDB.org}
|
14
14
|
s.email = %q{aaron@aarongough.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/ruby-tmdb/tmdb_cast.rb",
|
28
28
|
"lib/ruby-tmdb/tmdb_movie.rb",
|
29
29
|
"ruby-tmdb.gemspec",
|
30
|
+
"test/fixtures/blank_result.txt",
|
30
31
|
"test/fixtures/example_com.txt",
|
31
32
|
"test/fixtures/image.jpg",
|
32
33
|
"test/fixtures/incorrect_api_url.txt",
|
@@ -0,0 +1,16 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx
|
3
|
+
Date: Wed, 21 Jul 2010 19:39:08 GMT
|
4
|
+
Content-Type: text/x-yaml; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Keep-Alive: timeout=20
|
8
|
+
Status: 200 OK
|
9
|
+
Cache-Control: public, max-age=43200
|
10
|
+
X-Varnish: 2146446054 2146440076
|
11
|
+
Age: 28
|
12
|
+
Via: 1.1 varnish
|
13
|
+
X-Cache: HIT
|
14
|
+
|
15
|
+
---
|
16
|
+
- Nothing found.
|
data/test/setup/url_mocks.rb
CHANGED
@@ -22,6 +22,10 @@ def register_api_url_stubs
|
|
22
22
|
|
23
23
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "incorrect_api_url.txt")) do |file|
|
24
24
|
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Movie.blarg/" + ".*")).to_return(file)
|
25
|
+
|
26
|
+
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "blank_result.txt")) do |file|
|
27
|
+
stub_request(:get, Regexp.new(Tmdb.base_api_url + "Search.empty/" + ".*")).to_return(file)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "example_com.txt")) do |file|
|
data/test/unit/tmdb_test.rb
CHANGED
@@ -97,10 +97,16 @@ class TmdbTest < Test::Unit::TestCase
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
test "failed API call should return
|
100
|
+
test "failed API call should return nil" do
|
101
101
|
movies = Tmdb.api_call('Movie.blarg', 'Transformers')
|
102
|
-
assert_kind_of
|
103
|
-
|
102
|
+
assert_kind_of NilClass, movies
|
103
|
+
assert_nil movies
|
104
|
+
end
|
105
|
+
|
106
|
+
test "API call that finds no results should return nil" do
|
107
|
+
movies = Tmdb.api_call('Search.empty', 'Transformers')
|
108
|
+
assert_kind_of NilClass, movies
|
109
|
+
assert_nil movies
|
104
110
|
end
|
105
111
|
|
106
112
|
test "API call cache should not be changed when data altered in the receiving method" do
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-tmdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 53
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
7
|
+
- 1
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.21
|
9
|
+
version: 0.1.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Aaron Gough
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-07-21 00:00:00 -04:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -52,6 +50,7 @@ files:
|
|
52
50
|
- lib/ruby-tmdb/tmdb_cast.rb
|
53
51
|
- lib/ruby-tmdb/tmdb_movie.rb
|
54
52
|
- ruby-tmdb.gemspec
|
53
|
+
- test/fixtures/blank_result.txt
|
55
54
|
- test/fixtures/example_com.txt
|
56
55
|
- test/fixtures/image.jpg
|
57
56
|
- test/fixtures/incorrect_api_url.txt
|
@@ -85,7 +84,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
84
|
requirements:
|
86
85
|
- - ">="
|
87
86
|
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
87
|
segments:
|
90
88
|
- 0
|
91
89
|
version: "0"
|
@@ -94,7 +92,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
92
|
requirements:
|
95
93
|
- - ">="
|
96
94
|
- !ruby/object:Gem::Version
|
97
|
-
hash: 3
|
98
95
|
segments:
|
99
96
|
- 0
|
100
97
|
version: "0"
|