rottentomatoes 1.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 +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +95 -0
- data/Rakefile +2 -0
- data/lib/rottentomatoes.rb +8 -0
- data/lib/rottentomatoes/rotten_list.rb +19 -0
- data/lib/rottentomatoes/rotten_movie.rb +41 -0
- data/lib/rottentomatoes/rottentomatoes.rb +100 -0
- data/lib/rottentomatoes/version.rb +3 -0
- data/rottentomatoes.gemspec +26 -0
- data/spec/rotten_list_spec.rb +19 -0
- data/spec/rotten_movie_spec.rb +88 -0
- data/spec/rottentomatoes_spec.rb +85 -0
- data/spec/setup/.gitignore +1 -0
- data/spec/setup/setup_api_key.rb +3 -0
- data/spec/setup/spec_helper.rb +11 -0
- metadata +166 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
rottentomatoes (0.0.1)
|
|
5
|
+
deepopenstruct (>= 0.1.2)
|
|
6
|
+
json
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: http://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
addressable (2.2.4)
|
|
12
|
+
crack (0.1.8)
|
|
13
|
+
deepopenstruct (0.1.2)
|
|
14
|
+
diff-lcs (1.1.2)
|
|
15
|
+
json (1.5.1)
|
|
16
|
+
rspec (2.0.1)
|
|
17
|
+
rspec-core (~> 2.0.1)
|
|
18
|
+
rspec-expectations (~> 2.0.1)
|
|
19
|
+
rspec-mocks (~> 2.0.1)
|
|
20
|
+
rspec-core (2.0.1)
|
|
21
|
+
rspec-expectations (2.0.1)
|
|
22
|
+
diff-lcs (>= 1.1.2)
|
|
23
|
+
rspec-mocks (2.0.1)
|
|
24
|
+
rspec-core (~> 2.0.1)
|
|
25
|
+
rspec-expectations (~> 2.0.1)
|
|
26
|
+
webmock (1.6.2)
|
|
27
|
+
addressable (>= 2.2.2)
|
|
28
|
+
crack (>= 0.1.7)
|
|
29
|
+
|
|
30
|
+
PLATFORMS
|
|
31
|
+
ruby
|
|
32
|
+
|
|
33
|
+
DEPENDENCIES
|
|
34
|
+
bundler (>= 1.0.0)
|
|
35
|
+
deepopenstruct (>= 0.1.2)
|
|
36
|
+
json
|
|
37
|
+
rottentomatoes!
|
|
38
|
+
rspec (~> 2.0.0.beta.22)
|
|
39
|
+
webmock (>= 1.6.2)
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Nicholas Munson (http://nmunson.com/)
|
|
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.rdoc
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
= rottentomatoes
|
|
2
|
+
|
|
3
|
+
rottentomatoes is an ActiveRecord-style API wrapper for {RottenTomatoes.com}[http://www.rottentomatoes.com/]. rottentomatoes is designed to make common tasks much easier than they would be if dealing directly with the URL based API.
|
|
4
|
+
|
|
5
|
+
=== Installation
|
|
6
|
+
|
|
7
|
+
gem install rottentomatoes
|
|
8
|
+
|
|
9
|
+
=== Example
|
|
10
|
+
|
|
11
|
+
require 'rubygems'
|
|
12
|
+
require 'rottentomatoes'
|
|
13
|
+
include RottenTomatoes
|
|
14
|
+
|
|
15
|
+
# setup your API key
|
|
16
|
+
Rotten.api_key = "t478f8de5776c799de5a"
|
|
17
|
+
|
|
18
|
+
@movie = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
|
19
|
+
# => <OpenStruct>
|
|
20
|
+
|
|
21
|
+
@movie.name
|
|
22
|
+
# => "Fight Club"
|
|
23
|
+
|
|
24
|
+
@movie.ratings.critics_score
|
|
25
|
+
# => 81
|
|
26
|
+
|
|
27
|
+
@movie.synopsis
|
|
28
|
+
# => "An office employee and a soap salesman build a global organization to help vent male aggression."
|
|
29
|
+
|
|
30
|
+
=== Usage
|
|
31
|
+
|
|
32
|
+
RottenTomatoes provides two main object that you will use to query the API.
|
|
33
|
+
|
|
34
|
+
RottenMovie
|
|
35
|
+
RottenList
|
|
36
|
+
|
|
37
|
+
These objects provide access to movies and lists of movies respectively.
|
|
38
|
+
|
|
39
|
+
Each object provides a find() method which accepts a number of options:
|
|
40
|
+
|
|
41
|
+
RottenMovie.find(:id => 123, :title => "Fight Club", :limit => 10, :expand_results => true)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
[:id] specifies an individual movie via it's RottenTomatoes id
|
|
45
|
+
[:title] specifies a query string to look for in the movie titles
|
|
46
|
+
[:limit] specifies the maximum number of results to be returned
|
|
47
|
+
[:expand_results] The RottenTomatoes API by default returns only partial info for any API method that can return multiple results, or single movie lookups. When :expand_results is set to true rottentomatoes automatically makes extra API calls to fetch the full information for each item, such as the full cast and reviews. This can result in *very* slow requests though. If you need extra information for a search listing then set this to true. Defaults to 'false'. On average the overhead of the extra lookups takes 4x longer to return info.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
RottenList.find(:type => "upcoming", :limit => 10, :expand_results => true)
|
|
51
|
+
|
|
52
|
+
[:type] specifies a list type to retrieve. Valid options are 'box_office', 'in_theaters', 'opening', 'upcoming', 'new_releases'.
|
|
53
|
+
[:limit] see RottenMovie
|
|
54
|
+
[:expand_results] see RottenMovie
|
|
55
|
+
|
|
56
|
+
=== Usage Examples
|
|
57
|
+
|
|
58
|
+
Find all movies whose titles match a given string:
|
|
59
|
+
|
|
60
|
+
@movies = RottenMovie.find(:title => 'Iron Man')
|
|
61
|
+
|
|
62
|
+
Find the movie most likely to be associated with a given title:
|
|
63
|
+
|
|
64
|
+
@movie = RottenMovie.find(:title => 'Sin City', :limit => 1)
|
|
65
|
+
|
|
66
|
+
Find a single movie by its RottenTomatoes ID:
|
|
67
|
+
|
|
68
|
+
@movie = RottenMovie.find(:id => 13153)
|
|
69
|
+
|
|
70
|
+
Find a single movie and all associated information
|
|
71
|
+
|
|
72
|
+
@movie = RottenMovie.find(:title => 'Fight Club', :expand_results => true, :limit => 1)
|
|
73
|
+
|
|
74
|
+
Find movies that are playing in theatres
|
|
75
|
+
|
|
76
|
+
@movie = RottenList.find(:type => 'in_theaters')
|
|
77
|
+
|
|
78
|
+
=== Item information
|
|
79
|
+
|
|
80
|
+
To find out more about the information each object offers on retrieved items have a look at the {RottenTomatoes API Docs}[http://developer.rottentomatoes.com/docs]. For the most accurate information about the information available have a look at the data directly through rottentomatoes by calling @item.raw_data.inspect
|
|
81
|
+
|
|
82
|
+
=== Note on Patches/Pull Requests
|
|
83
|
+
|
|
84
|
+
* Fork the project.
|
|
85
|
+
* Make your feature addition or bug fix.
|
|
86
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
87
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
88
|
+
* Send me a pull request.
|
|
89
|
+
|
|
90
|
+
=== Author & Credits
|
|
91
|
+
|
|
92
|
+
Author:: {Nicholas Munson}[mailto:nmunson@gmail.com]
|
|
93
|
+
Credits:: {Aaron Gough}[http://thingsaaronmade.com]
|
|
94
|
+
|
|
95
|
+
Copyright (c) 2011 {Nicholas Munson}[http://nmunson.com/] ({nmunson.com}[http://nmunson.com/]), released under the MIT license
|
data/Rakefile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module RottenTomatoes
|
|
2
|
+
|
|
3
|
+
class RottenList
|
|
4
|
+
|
|
5
|
+
def self.find(options)
|
|
6
|
+
raise ArgumentError, ":type must be set" if (options[:type].nil?)
|
|
7
|
+
if !["box_office", "in_theaters", "opening", "upcoming", "new_releases"].include?(options[:type])
|
|
8
|
+
raise ArgumentError, ":type must be a recognized format"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
results = []
|
|
12
|
+
results << Rotten.api_call("lists", options)
|
|
13
|
+
|
|
14
|
+
return Rotten.process_results(results, options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module RottenTomatoes
|
|
2
|
+
|
|
3
|
+
class RottenMovie
|
|
4
|
+
|
|
5
|
+
def self.find(options)
|
|
6
|
+
raise ArgumentError, "You must search by title or id" if (options[:title].nil? && options[:id].nil?)
|
|
7
|
+
|
|
8
|
+
results = []
|
|
9
|
+
results << Rotten.api_call("movies", options)
|
|
10
|
+
|
|
11
|
+
return Rotten.process_results(results, options)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.new(raw_data, expand_results = false)
|
|
15
|
+
if (expand_results && !has_expanded_data?(raw_data))
|
|
16
|
+
raw_data = Rotten.api_call("movies", :id => raw_data["id"])
|
|
17
|
+
if !raw_data["links"].nil?
|
|
18
|
+
reviews = Rotten.api_call("direct", raw_data["links"]["reviews"]) if (!raw_data["links"]["reviews"].nil?)
|
|
19
|
+
cast = Rotten.api_call("direct", raw_data["links"]["cast"]) if (!raw_data["links"]["cast"].nil?)
|
|
20
|
+
|
|
21
|
+
raw_data = raw_data.merge(reviews) if (!reviews.nil?)
|
|
22
|
+
raw_data = raw_data.merge(cast) if (!cast.nil?)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
return Rotten.data_to_object(raw_data)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def ==(other)
|
|
29
|
+
return false unless (other.is_a?(RottenMovie))
|
|
30
|
+
return @raw_data == other.raw_data
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def self.has_expanded_data?(raw_data)
|
|
36
|
+
raw_data.has_key?("mpaa_rating")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
module RottenTomatoes
|
|
2
|
+
|
|
3
|
+
class Rotten
|
|
4
|
+
|
|
5
|
+
require 'net/http'
|
|
6
|
+
require 'uri'
|
|
7
|
+
require 'cgi'
|
|
8
|
+
require 'json'
|
|
9
|
+
require 'deepopenstruct'
|
|
10
|
+
|
|
11
|
+
@@api_key = ""
|
|
12
|
+
@@api_response = {}
|
|
13
|
+
|
|
14
|
+
def self.api_key
|
|
15
|
+
@@api_key
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.api_key=(key)
|
|
19
|
+
@@api_key = key
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.base_api_url
|
|
23
|
+
"http://api.rottentomatoes.com/api/public/v1.0/"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.api_call(method, options)
|
|
27
|
+
raise ArgumentError, "Rotten.api_key must be set before you can use the API" if(@@api_key.nil? || @@api_key.empty?)
|
|
28
|
+
raise ArgumentError, "You must specify 'movies', 'lists', or 'direct' as the method" if (method != "movies" && method != "direct" && method != "lists")
|
|
29
|
+
|
|
30
|
+
url = (method == "direct") ? options : base_api_url + method
|
|
31
|
+
|
|
32
|
+
if (method == "movies" && !options[:id].nil?)
|
|
33
|
+
url += "/" + options[:id].to_s
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if (method == "lists")
|
|
37
|
+
url += (options[:type] == "new_releases") ? "/dvds/" : "/movies/"
|
|
38
|
+
url += options[:type]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
url += ".json" if (url[-5, 5] != ".json")
|
|
42
|
+
url += "?apikey=" + @@api_key
|
|
43
|
+
url += "&q=" + CGI::escape(options[:title].to_s) if (method == "movies" && !options[:title].nil? && options[:id].nil?)
|
|
44
|
+
|
|
45
|
+
response = get_url(url)
|
|
46
|
+
return nil if(response.code.to_i != 200)
|
|
47
|
+
body = JSON(response.body)
|
|
48
|
+
|
|
49
|
+
if (body["total"] == 0 && body["title"].nil?)
|
|
50
|
+
return nil
|
|
51
|
+
else
|
|
52
|
+
return body["movies"] if !body["movies"].nil?
|
|
53
|
+
return body
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.process_results(results, options)
|
|
58
|
+
results.flatten!
|
|
59
|
+
results.compact!
|
|
60
|
+
|
|
61
|
+
unless (options[:limit].nil?)
|
|
62
|
+
raise ArgumentError, "Limit must be an integer greater than 0" if (!options[:limit].is_a?(Fixnum) || !(options[:limit] > 0))
|
|
63
|
+
results = results.slice(0, options[:limit])
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
results.map!{|m| RottenMovie.new(m, options[:expand_results])}
|
|
67
|
+
|
|
68
|
+
if (results.length == 1)
|
|
69
|
+
return results[0]
|
|
70
|
+
else
|
|
71
|
+
return results
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.get_url(uri_str, limit = 10)
|
|
76
|
+
return false if limit == 0
|
|
77
|
+
begin
|
|
78
|
+
response = Net::HTTP.get_response(URI.parse(uri_str))
|
|
79
|
+
rescue SocketError, Errno::ENETDOWN
|
|
80
|
+
response = Net::HTTPBadRequest.new( '404', 404, "Not Found" )
|
|
81
|
+
return response
|
|
82
|
+
end
|
|
83
|
+
case response
|
|
84
|
+
when Net::HTTPSuccess then response
|
|
85
|
+
when Net::HTTPRedirection then get_url(response['location'], limit - 1)
|
|
86
|
+
when Net::HTTPForbidden then get_url(uri_str, limit - 1)
|
|
87
|
+
else
|
|
88
|
+
Net::HTTPBadRequest.new( '404', 404, "Not Found" )
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def self.data_to_object(data)
|
|
93
|
+
object = DeepOpenStruct.load(data)
|
|
94
|
+
object.raw_data = data
|
|
95
|
+
return object
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path("../lib/rottentomatoes/version", __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = "rottentomatoes"
|
|
6
|
+
s.version = RottenTomatoes::VERSION
|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
|
8
|
+
s.authors = ["Nicholas Munson"]
|
|
9
|
+
s.email = ["nmunson@gmail.com"]
|
|
10
|
+
s.homepage = "http://rubygems.org/gems/rottentomatoes"
|
|
11
|
+
s.summary = "An ActiveRecord-style API wrapper for RottenTomatoes.com"
|
|
12
|
+
s.description = "An ActiveRecord-style API wrapper for RottenTomatoes.com"
|
|
13
|
+
|
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
|
15
|
+
s.rubyforge_project = "rottentomatoes"
|
|
16
|
+
|
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
|
18
|
+
s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
|
|
19
|
+
s.add_development_dependency "webmock", ">= 1.6.2"
|
|
20
|
+
s.add_dependency "deepopenstruct", ">= 0.1.2"
|
|
21
|
+
s.add_dependency "json"
|
|
22
|
+
|
|
23
|
+
s.files = `git ls-files`.split("\n")
|
|
24
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
|
25
|
+
s.require_path = 'lib'
|
|
26
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'setup', 'spec_helper.rb'))
|
|
2
|
+
|
|
3
|
+
describe RottenList do
|
|
4
|
+
|
|
5
|
+
it "should lookup a movie list and return an array" do
|
|
6
|
+
movies = RottenList.find(:type => "upcoming", :limit => 3)
|
|
7
|
+
movies.should be_a_kind_of Array
|
|
8
|
+
movies.each do |movie|
|
|
9
|
+
movie.should be_a_kind_of OpenStruct
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should raise an error when a lookup type that is not recognized is used" do
|
|
14
|
+
lambda {
|
|
15
|
+
movies = RottenList.find(:type => "unknown", :limit => 3)
|
|
16
|
+
}.should raise_error(ArgumentError)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'setup', 'spec_helper.rb'))
|
|
2
|
+
|
|
3
|
+
describe RottenMovie do
|
|
4
|
+
|
|
5
|
+
it "should allow movies to be reloaded by their raw_data" do
|
|
6
|
+
lambda {
|
|
7
|
+
movie = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
|
8
|
+
RottenMovie.new(movie.raw_data)
|
|
9
|
+
}.should_not raise_error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "searching" do
|
|
13
|
+
|
|
14
|
+
it "should create an empty array for searches with no results" do
|
|
15
|
+
movie = RottenMovie.find(:title => "xxxxxx")
|
|
16
|
+
movie.should == []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should require a search term" do
|
|
20
|
+
lambda {
|
|
21
|
+
RottenMovie.find()
|
|
22
|
+
}.should raise_error(ArgumentError)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should return an array of movies when searching by title" do
|
|
26
|
+
movies = RottenMovie.find(:title => "Fight Club")
|
|
27
|
+
movies.should be_a_kind_of Array
|
|
28
|
+
movies.each do |movie|
|
|
29
|
+
movie.should be_a_kind_of OpenStruct
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should return a single movie when limit=1 and searching by title" do
|
|
34
|
+
movie = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
|
35
|
+
movie.should be_a_kind_of OpenStruct
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should return a single movie when searching by id" do
|
|
39
|
+
movie = RottenMovie.find(:id => 13153)
|
|
40
|
+
movie.should be_a_kind_of OpenStruct
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should return the full movie data when searching by id" do
|
|
44
|
+
movie = RottenMovie.find(:id => 13153)
|
|
45
|
+
movie.mpaa_rating.should == "R"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should return the full movie data when expand_results set to true and searching by title" do
|
|
49
|
+
movie = RottenMovie.find(:title => "Fight Club", :limit => 1, :expand_results => true)
|
|
50
|
+
movie.mpaa_rating.should == "R"
|
|
51
|
+
movie.cast.should_not be_nil
|
|
52
|
+
movie.reviews.first.should_not be_nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should show movies found with the same data as equal" do
|
|
56
|
+
movie1 = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
|
57
|
+
movie2 = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
|
58
|
+
movie1.should == movie2
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should return an array of X movies when limit=X" do
|
|
62
|
+
movies = RottenMovie.find(:title => "Fight Club", :limit => 3)
|
|
63
|
+
movies.should be_a_kind_of Array
|
|
64
|
+
movies.length.should == 3
|
|
65
|
+
movies.each do |movie|
|
|
66
|
+
movie.should be_a_kind_of OpenStruct
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should raise an exception if limit is smaller than 1" do
|
|
71
|
+
[-100, 0].each do |limit|
|
|
72
|
+
lambda {
|
|
73
|
+
RottenMovie.find(:title => "Fight Club", :limit => limit)
|
|
74
|
+
}.should raise_error(ArgumentError)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should raise an exception if limit is not a integer" do
|
|
79
|
+
[1.1, "1.1", [1], "one"].each do |limit|
|
|
80
|
+
lambda {
|
|
81
|
+
RottenMovie.find(:title => "Fight Club", :limit => limit)
|
|
82
|
+
}.should raise_error(ArgumentError)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'setup', 'spec_helper.rb'))
|
|
2
|
+
|
|
3
|
+
describe Rotten do
|
|
4
|
+
|
|
5
|
+
it "set a specified API key" do
|
|
6
|
+
old_key = Rotten.api_key
|
|
7
|
+
key = "000000000"
|
|
8
|
+
Rotten.api_key = key
|
|
9
|
+
Rotten.api_key.should == key
|
|
10
|
+
Rotten.api_key = old_key
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should return a base API url" do
|
|
14
|
+
Rotten.base_api_url.should == "http://api.rottentomatoes.com/api/public/v1.0/"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should return a URL as a successful response object" do
|
|
18
|
+
response = Rotten.get_url("http://example.com")
|
|
19
|
+
response.code.to_i.should == 200
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should return a website URL that doesn't exist as a 404" do
|
|
23
|
+
response = Rotten.get_url("http://fakeurlisfakeforsure.com")
|
|
24
|
+
response.code.to_i.should == 404
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should raise an exception if the API key is not set" do
|
|
28
|
+
old_key = Rotten.api_key
|
|
29
|
+
lambda {
|
|
30
|
+
Rotten.api_key = ""
|
|
31
|
+
Rotten.api_call("movies", :title => "Fight Club")
|
|
32
|
+
}.should raise_error(ArgumentError)
|
|
33
|
+
Rotten.api_key = old_key
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should return an array of results when searching by title" do
|
|
37
|
+
movies = Rotten.api_call("movies", :title => "Fight Club")
|
|
38
|
+
movies.should be_a_kind_of Array
|
|
39
|
+
movies.length.should have_at_least(5).things
|
|
40
|
+
movies.each do |movie|
|
|
41
|
+
movie.should be_a_kind_of Hash
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should return a hash when searching by id" do
|
|
46
|
+
movies = Rotten.api_call("movies", :id => 12132)
|
|
47
|
+
movies.should be_a_kind_of Hash
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should raise an exception for a failed API call" do
|
|
51
|
+
lambda {
|
|
52
|
+
movies = Rotten.api_call("unknown", :title => "Fight Club")
|
|
53
|
+
}.should raise_error(ArgumentError)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should return nil for a search that returns no results when searching by title" do
|
|
57
|
+
movies = Rotten.api_call("movies", :title => "xxxxxxx")
|
|
58
|
+
movies.should == nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "data_to_object" do
|
|
62
|
+
|
|
63
|
+
it "should create an object from a nested data structure" do
|
|
64
|
+
data = {
|
|
65
|
+
:one => [
|
|
66
|
+
'a', 'b', 'c'
|
|
67
|
+
],
|
|
68
|
+
:two => 'd'
|
|
69
|
+
}
|
|
70
|
+
test_object = Rotten.data_to_object(data)
|
|
71
|
+
test_object.one.should == ['a', 'b', 'c']
|
|
72
|
+
test_object.two.should == 'd'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should include raw_data that returns the original data" do
|
|
76
|
+
data = {
|
|
77
|
+
:one => ['a', 'b', 'c']
|
|
78
|
+
}
|
|
79
|
+
test_object = Rotten.data_to_object(data)
|
|
80
|
+
test_object.raw_data.should == data
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rottentomatoes_api_key.txt
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
require_files = []
|
|
4
|
+
require_files << File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rottentomatoes.rb')
|
|
5
|
+
require_files.concat Dir[File.join(File.dirname(__FILE__), '*.rb')]
|
|
6
|
+
|
|
7
|
+
require_files.each do |file|
|
|
8
|
+
require File.expand_path(file)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
include RottenTomatoes
|
metadata
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rottentomatoes
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 21
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 1
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 1.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Nicholas Munson
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2011-03-29 00:00:00 -04:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: bundler
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 23
|
|
30
|
+
segments:
|
|
31
|
+
- 1
|
|
32
|
+
- 0
|
|
33
|
+
- 0
|
|
34
|
+
version: 1.0.0
|
|
35
|
+
type: :development
|
|
36
|
+
version_requirements: *id001
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: rspec
|
|
39
|
+
prerelease: false
|
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
hash: 62196431
|
|
46
|
+
segments:
|
|
47
|
+
- 2
|
|
48
|
+
- 0
|
|
49
|
+
- 0
|
|
50
|
+
- beta
|
|
51
|
+
- 22
|
|
52
|
+
version: 2.0.0.beta.22
|
|
53
|
+
type: :development
|
|
54
|
+
version_requirements: *id002
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
prerelease: false
|
|
58
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
59
|
+
none: false
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
hash: 11
|
|
64
|
+
segments:
|
|
65
|
+
- 1
|
|
66
|
+
- 6
|
|
67
|
+
- 2
|
|
68
|
+
version: 1.6.2
|
|
69
|
+
type: :development
|
|
70
|
+
version_requirements: *id003
|
|
71
|
+
- !ruby/object:Gem::Dependency
|
|
72
|
+
name: deepopenstruct
|
|
73
|
+
prerelease: false
|
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
hash: 31
|
|
80
|
+
segments:
|
|
81
|
+
- 0
|
|
82
|
+
- 1
|
|
83
|
+
- 2
|
|
84
|
+
version: 0.1.2
|
|
85
|
+
type: :runtime
|
|
86
|
+
version_requirements: *id004
|
|
87
|
+
- !ruby/object:Gem::Dependency
|
|
88
|
+
name: json
|
|
89
|
+
prerelease: false
|
|
90
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
91
|
+
none: false
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
hash: 3
|
|
96
|
+
segments:
|
|
97
|
+
- 0
|
|
98
|
+
version: "0"
|
|
99
|
+
type: :runtime
|
|
100
|
+
version_requirements: *id005
|
|
101
|
+
description: An ActiveRecord-style API wrapper for RottenTomatoes.com
|
|
102
|
+
email:
|
|
103
|
+
- nmunson@gmail.com
|
|
104
|
+
executables: []
|
|
105
|
+
|
|
106
|
+
extensions: []
|
|
107
|
+
|
|
108
|
+
extra_rdoc_files: []
|
|
109
|
+
|
|
110
|
+
files:
|
|
111
|
+
- .gitignore
|
|
112
|
+
- Gemfile
|
|
113
|
+
- Gemfile.lock
|
|
114
|
+
- MIT-LICENSE
|
|
115
|
+
- README.rdoc
|
|
116
|
+
- Rakefile
|
|
117
|
+
- lib/rottentomatoes.rb
|
|
118
|
+
- lib/rottentomatoes/rotten_list.rb
|
|
119
|
+
- lib/rottentomatoes/rotten_movie.rb
|
|
120
|
+
- lib/rottentomatoes/rottentomatoes.rb
|
|
121
|
+
- lib/rottentomatoes/version.rb
|
|
122
|
+
- rottentomatoes.gemspec
|
|
123
|
+
- spec/rotten_list_spec.rb
|
|
124
|
+
- spec/rotten_movie_spec.rb
|
|
125
|
+
- spec/rottentomatoes_spec.rb
|
|
126
|
+
- spec/setup/.gitignore
|
|
127
|
+
- spec/setup/setup_api_key.rb
|
|
128
|
+
- spec/setup/spec_helper.rb
|
|
129
|
+
has_rdoc: true
|
|
130
|
+
homepage: http://rubygems.org/gems/rottentomatoes
|
|
131
|
+
licenses: []
|
|
132
|
+
|
|
133
|
+
post_install_message:
|
|
134
|
+
rdoc_options: []
|
|
135
|
+
|
|
136
|
+
require_paths:
|
|
137
|
+
- lib
|
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
|
+
none: false
|
|
140
|
+
requirements:
|
|
141
|
+
- - ">="
|
|
142
|
+
- !ruby/object:Gem::Version
|
|
143
|
+
hash: 3
|
|
144
|
+
segments:
|
|
145
|
+
- 0
|
|
146
|
+
version: "0"
|
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
|
+
none: false
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
hash: 23
|
|
153
|
+
segments:
|
|
154
|
+
- 1
|
|
155
|
+
- 3
|
|
156
|
+
- 6
|
|
157
|
+
version: 1.3.6
|
|
158
|
+
requirements: []
|
|
159
|
+
|
|
160
|
+
rubyforge_project: rottentomatoes
|
|
161
|
+
rubygems_version: 1.3.7
|
|
162
|
+
signing_key:
|
|
163
|
+
specification_version: 3
|
|
164
|
+
summary: An ActiveRecord-style API wrapper for RottenTomatoes.com
|
|
165
|
+
test_files: []
|
|
166
|
+
|