mbautin-rottentomatoes 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +111 -0
- data/Rakefile +2 -0
- data/lib/rottentomatoes.rb +8 -0
- data/lib/rottentomatoes/rotten_list.rb +27 -0
- data/lib/rottentomatoes/rotten_movie.rb +41 -0
- data/lib/rottentomatoes/rottentomatoes.rb +117 -0
- data/lib/rottentomatoes/version.rb +3 -0
- data/mbautin-rottentomatoes.gemspec +32 -0
- data/spec/rotten_list_spec.rb +34 -0
- data/spec/rotten_movie_spec.rb +99 -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 +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c6427605e41a868cd98e495bee586595052781fb
|
4
|
+
data.tar.gz: 3c4617e56b4c0d6bd0462ddcd28902fa4e707f32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9053c0f4375b5d4e552ab75b017ef900d22c84bb9c8397a08718eb1f61ea3d0ad739a2ac318a9f724f7150ed93d7f1882a608a97e29da94e2ce5f6298fa9e971
|
7
|
+
data.tar.gz: aaf3c50dce8e49c19116e519018a9d479a1b87c6b2f2c020e5b7d8c17fff29ac427e93fd112693f54ef802056026bc34cb588ee97a6eb8a48dd6a40c57556ab9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
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,111 @@
|
|
1
|
+
= rottentomatoes
|
2
|
+
|
3
|
+
{<img src="https://travis-ci.org/mbautin/mbautin-rottentomatoes.png?branch=master" alt="Build Status" />}[https://travis-ci.org/mbautin/mbautin-rottentomatoes]
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
=== Installation
|
8
|
+
|
9
|
+
gem install rottentomatoes
|
10
|
+
|
11
|
+
=== Example
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'rottentomatoes'
|
15
|
+
include RottenTomatoes
|
16
|
+
|
17
|
+
# setup your API key
|
18
|
+
Rotten.api_key = "t478f8de5776c799de5a"
|
19
|
+
|
20
|
+
@movie = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
21
|
+
# => <OpenStruct>
|
22
|
+
|
23
|
+
@movie = RottenMovie.find(:imdb => 137523)
|
24
|
+
# => <OpenStruct>
|
25
|
+
|
26
|
+
@movie.title
|
27
|
+
# => "Fight Club"
|
28
|
+
|
29
|
+
@movie.ratings.critics_score
|
30
|
+
# => 81
|
31
|
+
|
32
|
+
@movie.synopsis
|
33
|
+
# => "An office employee and a soap salesman build a global organization to help vent male aggression."
|
34
|
+
|
35
|
+
=== Usage
|
36
|
+
|
37
|
+
RottenTomatoes provides two main object that you will use to query the API.
|
38
|
+
|
39
|
+
RottenMovie
|
40
|
+
RottenList
|
41
|
+
|
42
|
+
These objects provide access to movies and lists of movies respectively.
|
43
|
+
|
44
|
+
Each object provides a find() method which accepts a number of options:
|
45
|
+
|
46
|
+
RottenMovie.find(:id => 123, :title => "Fight Club", :limit => 10, :expand_results => true)
|
47
|
+
|
48
|
+
|
49
|
+
[:id] specifies an individual movie via it's RottenTomatoes id
|
50
|
+
[:imdb] specifies an individual movie via it's IMDb id
|
51
|
+
[:title] specifies a query string to look for in the movie titles
|
52
|
+
[:limit] specifies the maximum number of results to be returned
|
53
|
+
[: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.
|
54
|
+
|
55
|
+
|
56
|
+
RottenList.find(:type => "upcoming", :limit => 10, :expand_results => true)
|
57
|
+
|
58
|
+
[:type] specifies a list type to retrieve. Valid options are
|
59
|
+
'box_office', 'in_theaters', 'opening' (only valid with the 'movies' section),
|
60
|
+
'upcoming' (valid with both 'movies' and 'dvds' sections),
|
61
|
+
and 'new_releases', 'top_rentals', 'current_releases' (only valid with the 'dvds'
|
62
|
+
section).
|
63
|
+
[:section] 'movies' (default) or 'dvds'.
|
64
|
+
[:limit] see RottenMovie
|
65
|
+
[:expand_results] see RottenMovie
|
66
|
+
|
67
|
+
=== Usage Examples
|
68
|
+
|
69
|
+
Find all movies whose titles match a given string:
|
70
|
+
|
71
|
+
@movies = RottenMovie.find(:title => 'Iron Man')
|
72
|
+
|
73
|
+
Find the movie most likely to be associated with a given title:
|
74
|
+
|
75
|
+
@movie = RottenMovie.find(:title => 'Sin City', :limit => 1)
|
76
|
+
|
77
|
+
Find a single movie by its RottenTomatoes ID:
|
78
|
+
|
79
|
+
@movie = RottenMovie.find(:id => 13153)
|
80
|
+
|
81
|
+
Find a single movie by its IMDb ID:
|
82
|
+
|
83
|
+
@movie = RottenMovie.find(:imdb => 137523)
|
84
|
+
|
85
|
+
Find a single movie and all associated information
|
86
|
+
|
87
|
+
@movie = RottenMovie.find(:title => 'Fight Club', :expand_results => true, :limit => 1)
|
88
|
+
|
89
|
+
Find movies that are playing in theatres
|
90
|
+
|
91
|
+
@movie = RottenList.find(:type => 'in_theaters')
|
92
|
+
|
93
|
+
=== Item information
|
94
|
+
|
95
|
+
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
|
96
|
+
|
97
|
+
=== Note on Patches/Pull Requests
|
98
|
+
|
99
|
+
* Fork the project.
|
100
|
+
* Make your feature addition or bug fix.
|
101
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
102
|
+
* Commit, do not mess with rakefile, version, or history.
|
103
|
+
* Send me a pull request.
|
104
|
+
|
105
|
+
=== Author & Credits
|
106
|
+
|
107
|
+
Author:: {Nicholas Munson}[mailto:nmunson@gmail.com]
|
108
|
+
Credits:: {Aaron Gough}[http://thingsaaronmade.com]
|
109
|
+
Improvements:: {Mikhail Bautin}
|
110
|
+
|
111
|
+
Copyright (c) 2011 {Nicholas Munson}[http://nmunson.com/] ({nmunson.com}[http://nmunson.com/]), released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
+
|
8
|
+
if !["box_office", "in_theaters", "opening", "upcoming", "new_releases",
|
9
|
+
"top_rentals", "current_releases"].include?(options[:type])
|
10
|
+
raise ArgumentError, ":type must be a recognized format, found #{options[:type].inspect}"
|
11
|
+
end
|
12
|
+
|
13
|
+
section = options[:section]
|
14
|
+
unless section.nil? || ['movies', 'dvds'].include?(section)
|
15
|
+
raise ArgumentError,
|
16
|
+
":section must be either 'movies' (default) or 'dvds', found #{section.inspect}"
|
17
|
+
end
|
18
|
+
|
19
|
+
results = []
|
20
|
+
results << Rotten.api_call("lists", options)
|
21
|
+
|
22
|
+
return Rotten.process_results(results, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
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, id or imdb id" if (options[:title].nil? && options[:id].nil? && options[:imdb].nil?)
|
7
|
+
|
8
|
+
results = []
|
9
|
+
results << Rotten.api_call(options[:imdb].nil? ? "movies" : "movie_alias", 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,117 @@
|
|
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
|
+
REQUEST_SLEEP_SEC = ENV['ROTTENTOMATOES_REQUEST_SLEEP_SEC'].to_f || 0
|
15
|
+
|
16
|
+
TYPE_TO_SECTION = {
|
17
|
+
:box_office => 'movies',
|
18
|
+
:in_theaters => 'movies',
|
19
|
+
:opening => 'movies',
|
20
|
+
:top_rentals => 'dvds',
|
21
|
+
:current_releases => 'dvds',
|
22
|
+
:new_releases => 'dvds'
|
23
|
+
}
|
24
|
+
|
25
|
+
def self.api_key
|
26
|
+
@@api_key
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.api_key=(key)
|
30
|
+
@@api_key = key
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.base_api_url
|
34
|
+
"http://api.rottentomatoes.com/api/public/v1.0/"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.api_call(method, options)
|
38
|
+
raise ArgumentError, "Rotten.api_key must be set before you can use the API" if(@@api_key.nil? || @@api_key.empty?)
|
39
|
+
raise ArgumentError, "You must specify 'movies', 'movie_alias', 'lists' or 'direct' as the method" if (method != "movies" && method != "direct" && method != "lists" && method != "movie_alias")
|
40
|
+
|
41
|
+
url = (method == "direct") ? options : base_api_url + method
|
42
|
+
|
43
|
+
if (method == "movies" && !options[:id].nil?)
|
44
|
+
url += "/" + options[:id].to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
if (method == "lists")
|
48
|
+
type = options[:type]
|
49
|
+
section = options[:section] || TYPE_TO_SECTION[type] || 'movies'
|
50
|
+
url += "/#{section}/#{type}"
|
51
|
+
end
|
52
|
+
|
53
|
+
url += ".json" if (url[-5, 5] != ".json")
|
54
|
+
url += "?apikey=" + @@api_key
|
55
|
+
url += "&q=" + CGI::escape(options[:title].to_s) if (method == "movies" && !options[:title].nil? && options[:id].nil?)
|
56
|
+
url += "&type=imdb&id=%07d" % options[:imdb].to_i if (method == "movie_alias")
|
57
|
+
|
58
|
+
response = get_url(url)
|
59
|
+
return nil if(response.code.to_i != 200)
|
60
|
+
body = JSON(response.body)
|
61
|
+
|
62
|
+
if (body["total"] == 0 && body["title"].nil?)
|
63
|
+
return nil
|
64
|
+
else
|
65
|
+
return body["movies"] if !body["movies"].nil?
|
66
|
+
return body
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.process_results(results, options)
|
71
|
+
results.flatten!
|
72
|
+
results.compact!
|
73
|
+
|
74
|
+
unless (options[:limit].nil?)
|
75
|
+
raise ArgumentError, "Limit must be an integer greater than 0" if (!options[:limit].is_a?(Fixnum) || !(options[:limit] > 0))
|
76
|
+
results = results.slice(0, options[:limit])
|
77
|
+
end
|
78
|
+
|
79
|
+
results.map!{|m| RottenMovie.new(m, options[:expand_results])}
|
80
|
+
|
81
|
+
if (results.length == 1)
|
82
|
+
return results[0]
|
83
|
+
else
|
84
|
+
return results
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.get_url(uri_str, limit = 10)
|
89
|
+
return false if limit == 0
|
90
|
+
uri = URI.parse(uri_str)
|
91
|
+
begin
|
92
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
93
|
+
http.get((uri.path.empty? ? '/' : uri.path) + (uri.query ? '?' + uri.query : ''))
|
94
|
+
end
|
95
|
+
sleep(REQUEST_SLEEP_SEC) if REQUEST_SLEEP_SEC != 0
|
96
|
+
rescue SocketError, Errno::ENETDOWN
|
97
|
+
response = Net::HTTPBadRequest.new( '404', 404, "Not Found" )
|
98
|
+
return response
|
99
|
+
end
|
100
|
+
case response
|
101
|
+
when Net::HTTPSuccess then response
|
102
|
+
when Net::HTTPRedirection then get_url(response['location'], limit - 1)
|
103
|
+
when Net::HTTPForbidden then get_url(uri_str, limit - 1)
|
104
|
+
else
|
105
|
+
Net::HTTPBadRequest.new( '404', 404, "Not Found" )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.data_to_object(data)
|
110
|
+
object = DeepOpenStruct.load(data)
|
111
|
+
object.raw_data = data
|
112
|
+
return object
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/rottentomatoes/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "mbautin-rottentomatoes"
|
6
|
+
s.version = RottenTomatoes::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Nicholas Munson"]
|
9
|
+
|
10
|
+
# Disable email
|
11
|
+
s.email = []
|
12
|
+
# s.email = ["nmunson@gmail.com"]
|
13
|
+
|
14
|
+
s.homepage = "http://rubygems.org/gems/mbautin-rottentomatoes"
|
15
|
+
s.summary = "An ActiveRecord-style API wrapper for RottenTomatoes.com"
|
16
|
+
s.description = "An ActiveRecord-style API wrapper for RottenTomatoes.com"
|
17
|
+
|
18
|
+
s.required_rubygems_version = ">= 1.3.6"
|
19
|
+
s.rubyforge_project = "mbautin-rottentomatoes"
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
22
|
+
s.add_development_dependency "rspec", "~> 2.14.1"
|
23
|
+
s.add_development_dependency "webmock", ">= 1.6.2"
|
24
|
+
|
25
|
+
s.add_dependency "addressable", ">= 2.3.5", "< 3.0"
|
26
|
+
s.add_dependency "deepopenstruct", ">= 0.1.2"
|
27
|
+
s.add_dependency "json"
|
28
|
+
|
29
|
+
s.files = `git ls-files`.split("\n")
|
30
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
31
|
+
s.require_path = 'lib'
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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 look up a movie list with section specified and return an array" do
|
14
|
+
{
|
15
|
+
'movies' => ['box_office', 'in_theaters', 'opening', 'upcoming'],
|
16
|
+
'dvds' => ['top_rentals', 'current_releases', 'new_releases', 'upcoming']
|
17
|
+
}.each do |section, types|
|
18
|
+
types.each do |type|
|
19
|
+
results = RottenList.find(:section => section, :type => type, :limit => 3)
|
20
|
+
expect(results.length).to eq(3)
|
21
|
+
results.each do |movie|
|
22
|
+
expect(movie).to be_a_kind_of(OpenStruct)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should raise an error when a lookup type that is not recognized is used" do
|
29
|
+
lambda {
|
30
|
+
movies = RottenList.find(:type => "unknown", :limit => 3)
|
31
|
+
}.should raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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
|
+
# The results returned by rottentomatoes for this query seem to have changed.
|
15
|
+
|
16
|
+
#it "should create an empty array for searches with no results" do
|
17
|
+
# movie = RottenMovie.find(:title => "xxxxxx")
|
18
|
+
# movie.should == []
|
19
|
+
#end
|
20
|
+
|
21
|
+
it "should require a search term" do
|
22
|
+
lambda {
|
23
|
+
RottenMovie.find()
|
24
|
+
}.should raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return an array of movies when searching by title" do
|
28
|
+
movies = RottenMovie.find(:title => "Fight Club")
|
29
|
+
movies.should be_a_kind_of Array
|
30
|
+
movies.each do |movie|
|
31
|
+
movie.should be_a_kind_of OpenStruct
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return a single movie when limit=1 and searching by title" do
|
36
|
+
movie = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
37
|
+
movie.should be_a_kind_of OpenStruct
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return a single movie when searching by id" do
|
41
|
+
movie = RottenMovie.find(:id => 13153)
|
42
|
+
movie.should be_a_kind_of OpenStruct
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a single movie when searching by imdb id" do
|
46
|
+
movie = RottenMovie.find(:imdb => 137523)
|
47
|
+
movie.should be_a_kind_of OpenStruct
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return the full movie data when searching by id" do
|
51
|
+
movie = RottenMovie.find(:id => 13153)
|
52
|
+
movie.mpaa_rating.should == "R"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return the full movie data when searching by imdb id" do
|
56
|
+
movie = RottenMovie.find(:imdb => 137523)
|
57
|
+
movie.mpaa_rating.should == "R"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the full movie data when expand_results set to true and searching by title" do
|
61
|
+
movie = RottenMovie.find(:title => "Fight Club", :limit => 1, :expand_results => true)
|
62
|
+
movie.mpaa_rating.should == "R"
|
63
|
+
movie.abridged_cast.should_not be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should show movies found with the same data as equal" do
|
67
|
+
movie1 = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
68
|
+
movie2 = RottenMovie.find(:title => "Fight Club", :limit => 1)
|
69
|
+
movie1.should == movie2
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return an array of X movies when limit=X" do
|
73
|
+
movies = RottenMovie.find(:title => "Fight Club", :limit => 3)
|
74
|
+
movies.should be_a_kind_of Array
|
75
|
+
movies.length.should == 3
|
76
|
+
movies.each do |movie|
|
77
|
+
movie.should be_a_kind_of OpenStruct
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise an exception if limit is smaller than 1" do
|
82
|
+
[-100, 0].each do |limit|
|
83
|
+
lambda {
|
84
|
+
RottenMovie.find(:title => "Fight Club", :limit => limit)
|
85
|
+
}.should raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should raise an exception if limit is not a integer" do
|
90
|
+
[1.1, "1.1", [1], "one"].each do |limit|
|
91
|
+
lambda {
|
92
|
+
RottenMovie.find(:title => "Fight Club", :limit => limit)
|
93
|
+
}.should raise_error(ArgumentError)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
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(3).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,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mbautin-rottentomatoes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicholas Munson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.14.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.14.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.6.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: addressable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.3.5
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3.0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.3.5
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: deepopenstruct
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.1.2
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.1.2
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: json
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: An ActiveRecord-style API wrapper for RottenTomatoes.com
|
104
|
+
email: []
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- ".travis.yml"
|
111
|
+
- Gemfile
|
112
|
+
- MIT-LICENSE
|
113
|
+
- README.rdoc
|
114
|
+
- Rakefile
|
115
|
+
- lib/rottentomatoes.rb
|
116
|
+
- lib/rottentomatoes/rotten_list.rb
|
117
|
+
- lib/rottentomatoes/rotten_movie.rb
|
118
|
+
- lib/rottentomatoes/rottentomatoes.rb
|
119
|
+
- lib/rottentomatoes/version.rb
|
120
|
+
- mbautin-rottentomatoes.gemspec
|
121
|
+
- spec/rotten_list_spec.rb
|
122
|
+
- spec/rotten_movie_spec.rb
|
123
|
+
- spec/rottentomatoes_spec.rb
|
124
|
+
- spec/setup/.gitignore
|
125
|
+
- spec/setup/rottentomatoes_api_key.txt
|
126
|
+
- spec/setup/setup_api_key.rb
|
127
|
+
- spec/setup/spec_helper.rb
|
128
|
+
homepage: http://rubygems.org/gems/mbautin-rottentomatoes
|
129
|
+
licenses: []
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 1.3.6
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project: mbautin-rottentomatoes
|
147
|
+
rubygems_version: 2.2.1
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: An ActiveRecord-style API wrapper for RottenTomatoes.com
|
151
|
+
test_files: []
|