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 CHANGED
@@ -1 +1 @@
1
- 0.0.21
1
+ 0.1.0
@@ -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
@@ -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.21"
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-05-26}
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.
@@ -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|
@@ -97,10 +97,16 @@ class TmdbTest < Test::Unit::TestCase
97
97
  end
98
98
  end
99
99
 
100
- test "failed API call should return empty array" do
100
+ test "failed API call should return nil" do
101
101
  movies = Tmdb.api_call('Movie.blarg', 'Transformers')
102
- assert_kind_of Array, movies
103
- assert movies.empty?
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
- - 21
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-05-26 00:00:00 -04:00
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"