imdb_party 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jon Maddox
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.
@@ -0,0 +1,27 @@
1
+ # ImdbParty!
2
+
3
+ ## How To Use
4
+
5
+ ### Create an instance
6
+
7
+ imdb = ImdbParty::Imdb.new
8
+ ### Search for a movie by title
9
+
10
+ imdb.find_movie_by_title("The Dark Knight") => [{:title => "The Dark Knight", :year => "2008", :imdb_id => "tt0468569"}, {:title => "Batman Unmasked", ...}]
11
+
12
+ ### Get a movie by its imdb_id
13
+
14
+ movie = imdb.find_movie_by_id("tt0468569")
15
+
16
+ movie.title => "The Dark Knight"
17
+ movie.rating => 8.1
18
+ movie.certification => "PG-13"
19
+
20
+ ### Find the top 250 movies of all time
21
+
22
+ imdb.top_250 => [{:title => "Shawshank Redemption", :year => "1994", :imdb_id => "tt0111161"}, {:title => "The Godfather", ...}]
23
+
24
+ ### Get the currently popular tv shows
25
+
26
+ imdb.top_shows => [{:title => "Glee", :year => "2009", :imdb_id => "tt1327801"}, {:title => "Dexter", ...}]
27
+
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "imdb_party"
8
+ gem.summary = %Q{IMDB client using the IMDB API that their iPhone app uses}
9
+ gem.description = %Q{IMDB client using the IMDB API that their iPhone app uses}
10
+ gem.email = "jon@mustacheinc.com"
11
+ gem.homepage = "http://github.com/maddox/imdb_party"
12
+ gem.authors = ["Jon Maddox"]
13
+ gem.add_development_dependency "shoulda"
14
+ gem.add_dependency "httparty"
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "imdb_party #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{imdb_party}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jon Maddox"]
12
+ s.date = %q{2010-10-11}
13
+ s.description = %q{IMDB client using the IMDB API that their iPhone app uses}
14
+ s.email = %q{jon@mustacheinc.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "imdb_party.gemspec",
27
+ "lib/imdb_party.rb",
28
+ "lib/imdb_party/httparty_icebox.rb",
29
+ "lib/imdb_party/imdb.rb",
30
+ "lib/imdb_party/movie.rb",
31
+ "lib/imdb_party/person.rb",
32
+ "test/movie_test.rb",
33
+ "test/person_test.rb",
34
+ "test/search_test.rb",
35
+ "test/test_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/maddox/imdb_party}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{IMDB client using the IMDB API that their iPhone app uses}
42
+ s.test_files = [
43
+ "test/movie_test.rb",
44
+ "test/person_test.rb",
45
+ "test/search_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<httparty>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<httparty>, [">= 0"])
63
+ end
64
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ directory = File.expand_path(File.dirname(__FILE__))
5
+ require File.join(directory, 'imdb_party', 'httparty_icebox')
6
+ require File.join(directory, 'imdb_party', 'imdb')
7
+ require File.join(directory, 'imdb_party', 'movie')
8
+ require File.join(directory, 'imdb_party', 'person')
9
+
10
+ # ImdbParty::Imdb.new.find_movie_by_id("tt0100234")
@@ -0,0 +1,259 @@
1
+ # = Icebox : Caching for HTTParty
2
+ #
3
+ # Cache responses in HTTParty models [http://github.com/jnunemaker/httparty]
4
+ #
5
+ # === Usage
6
+ #
7
+ # class Foo
8
+ # include HTTParty
9
+ # include HTTParty::Icebox
10
+ # cache :store => 'file', :timeout => 600, :location => MY_APP_ROOT.join('tmp', 'cache')
11
+ # end
12
+ #
13
+ # Modeled after Martyn Loughran's APICache [http://github.com/newbamboo/api_cache]
14
+ # and Ruby On Rails's caching [http://api.rubyonrails.org/classes/ActiveSupport/Cache.html]
15
+ #
16
+ # Author: Karel Minarik [www.karmi.cz]
17
+ #
18
+ # === Notes
19
+ #
20
+ # Thanks to Amit Chakradeo to point out objects have to be stored marhalled on FS
21
+ # Thanks to Marlin Forbes to point out query parameters have to be include in the cache key
22
+ #
23
+ #
24
+
25
+ require 'logger'
26
+ require 'ftools'
27
+ require 'tmpdir'
28
+ require 'pathname'
29
+ require 'digest/md5'
30
+
31
+ module HTTParty #:nodoc:
32
+ module Icebox
33
+
34
+ module ClassMethods
35
+
36
+ # Enable caching and set cache options
37
+ # Returns memoized cache object
38
+ #
39
+ # Following options are available, default values are in []:
40
+ #
41
+ # +store+:: Storage mechanism for cached data (memory, filesystem, your own) [memory]
42
+ # +timeout+:: Cache expiration in seconds [60]
43
+ # +logger+:: Path to logfile or logger instance [STDOUT]
44
+ #
45
+ # Any additional options are passed to the Cache constructor
46
+ #
47
+ # Usage:
48
+ #
49
+ # # Enable caching in HTTParty, in memory, for 1 minute
50
+ # cache # Use default values
51
+ #
52
+ # # Enable caching in HTTParty, on filesystem (/tmp), for 10 minutes
53
+ # cache :store => 'file', :timeout => 600, :location => '/tmp/'
54
+ #
55
+ # # Use your own cache store (see AbstractStore class below)
56
+ # cache :store => 'memcached', :timeout => 600, :server => '192.168.1.1:1001'
57
+ #
58
+ def cache(options={})
59
+ options[:store] ||= 'memory'
60
+ options[:timeout] ||= 60
61
+ logger = options[:logger]
62
+ @cache ||= Cache.new( options.delete(:store), options )
63
+ end
64
+
65
+ end
66
+
67
+ # When included, extend class with +cache+ method
68
+ # and redefine +get+ method to use cache
69
+ #
70
+ def self.included(receiver) #:nodoc:
71
+ receiver.extend ClassMethods
72
+ receiver.class_eval do
73
+
74
+ # Get reponse from network
75
+ # TODO: Why alias :new :old is not working here? Returns NoMethodError
76
+ #
77
+ def self.get_without_caching(path, options={})
78
+ perform_request Net::HTTP::Get, path, options
79
+ end
80
+
81
+ # Get response from cache, if available
82
+ #
83
+ def self.get_with_caching(path, options={})
84
+ key = path.clone
85
+ key << options[:query].to_s if defined? options[:query]
86
+
87
+ if cache.exists?(key) and not cache.stale?(key)
88
+ Cache.logger.debug "CACHE -- GET #{path}#{options[:query]}"
89
+ return cache.get(key)
90
+ else
91
+ Cache.logger.debug "/!\\ NETWORK -- GET #{path}#{options[:query]}"
92
+ response = get_without_caching(path, options)
93
+ cache.set(key, response) if response.code == 200
94
+ return response
95
+ end
96
+ end
97
+
98
+ # Redefine original HTTParty +get+ method to use cache
99
+ #
100
+ def self.get(path, options={})
101
+ self.get_with_caching(path, options)
102
+ end
103
+
104
+ end
105
+ end
106
+
107
+ # === Cache container
108
+ #
109
+ # Pass a store name ('memory', etc) to initializer
110
+ #
111
+ class Cache
112
+ attr_accessor :store
113
+
114
+ def initialize(store, options={})
115
+ self.class.logger = options[:logger]
116
+ @store = self.class.lookup_store(store).new(options)
117
+ end
118
+
119
+ def get(key); @store.get encode(key) unless stale?(key); end
120
+ def set(key, value); @store.set encode(key), value; end
121
+ def exists?(key); @store.exists? encode(key); end
122
+ def stale?(key); @store.stale? encode(key); end
123
+
124
+ def self.logger; @logger || default_logger; end
125
+ def self.default_logger; logger = ::Logger.new(STDERR); end
126
+
127
+ # Pass a filename (String), IO object, Logger instance or +nil+ to silence the logger
128
+ def self.logger=(device); @logger = device.kind_of?(::Logger) ? device : ::Logger.new(device); end
129
+
130
+ private
131
+
132
+ # Return store class based on passed name
133
+ def self.lookup_store(name)
134
+ store_name = "#{name.capitalize}Store"
135
+ return Store::const_get(store_name)
136
+ rescue NameError => e
137
+ raise Store::StoreNotFound, "The cache store '#{store_name}' was not found. Did you loaded any such class?"
138
+ end
139
+
140
+ def encode(key); Digest::MD5.hexdigest(key); end
141
+ end
142
+
143
+
144
+ # === Cache stores
145
+ #
146
+ module Store
147
+
148
+ class StoreNotFound < StandardError; end #:nodoc:
149
+
150
+ # ==== Abstract Store
151
+ # Inherit your store from this class
152
+ # *IMPORTANT*: Do not forget to call +super+ in your +initialize+ method!
153
+ #
154
+ class AbstractStore
155
+ def initialize(options={})
156
+ raise ArgumentError, "You need to set the :timeout parameter" unless options[:timeout]
157
+ @timeout = options[:timeout]
158
+ message = "Cache: Using #{self.class.to_s.split('::').last}"
159
+ message << " in location: #{options[:location]}" if options[:location]
160
+ message << " with timeout #{options[:timeout]} sec"
161
+ Cache.logger.info message unless options[:logger].nil?
162
+ return self
163
+ end
164
+ %w{set get exists? stale?}.each do |method_name|
165
+ define_method(method_name) { raise NoMethodError, "Please implement method set in your store class" }
166
+ end
167
+ end
168
+
169
+ # ===== Store objects in memory
170
+ #
171
+ Struct.new("TvdbResponse", :code, :body, :headers) { def to_s; self.body; end }
172
+ class MemoryStore < AbstractStore
173
+ def initialize(options={})
174
+ super; @store = {}; self
175
+ end
176
+ def set(key, value)
177
+ Cache.logger.info("Cache: set (#{key})")
178
+ @store[key] = [Time.now, value]; true
179
+ end
180
+ def get(key)
181
+ data = @store[key][1]
182
+ Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
183
+ data
184
+ end
185
+ def exists?(key)
186
+ !@store[key].nil?
187
+ end
188
+ def stale?(key)
189
+ return true unless exists?(key)
190
+ Time.now - created(key) > @timeout
191
+ end
192
+ private
193
+ def created(key)
194
+ @store[key][0]
195
+ end
196
+ end
197
+
198
+ # ===== Store objects on the filesystem
199
+ #
200
+ class FileStore < AbstractStore
201
+ def initialize(options={})
202
+ super
203
+ options[:location] ||= Dir::tmpdir
204
+ @path = Pathname.new( options[:location] )
205
+ FileUtils.mkdir_p( @path )
206
+ self
207
+ end
208
+ def set(key, value)
209
+ Cache.logger.info("Cache: set (#{key})")
210
+ File.open( @path.join(key), 'w' ) { |file| file << Marshal.dump(value) }
211
+ true
212
+ end
213
+ def get(key)
214
+ data = Marshal.load(File.read( @path.join(key)))
215
+ Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
216
+ data
217
+ end
218
+ def exists?(key)
219
+ File.exists?( @path.join(key) )
220
+ end
221
+ def stale?(key)
222
+ return true unless exists?(key)
223
+ Time.now - created(key) > @timeout
224
+ end
225
+ private
226
+ def created(key)
227
+ File.mtime( @path.join(key) )
228
+ end
229
+ end
230
+ end
231
+
232
+ end
233
+ end
234
+
235
+
236
+ # Major parts of this code are based on architecture of ApiCache.
237
+ # Copyright (c) 2008 Martyn Loughran
238
+ #
239
+ # Other parts are inspired by the ActiveSupport::Cache in Ruby On Rails.
240
+ # Copyright (c) 2005-2009 David Heinemeier Hansson
241
+ #
242
+ # Permission is hereby granted, free of charge, to any person obtaining
243
+ # a copy of this software and associated documentation files (the
244
+ # "Software"), to deal in the Software without restriction, including
245
+ # without limitation the rights to use, copy, modify, merge, publish,
246
+ # distribute, sublicense, and/or sell copies of the Software, and to
247
+ # permit persons to whom the Software is furnished to do so, subject to
248
+ # the following conditions:
249
+ #
250
+ # The above copyright notice and this permission notice shall be
251
+ # included in all copies or substantial portions of the Software.
252
+ #
253
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
254
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
255
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
256
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
257
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
258
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
259
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ module ImdbParty
2
+ class Imdb
3
+ include HTTParty
4
+ include HTTParty::Icebox
5
+ cache :store => 'file', :timeout => 120, :location => Dir.tmpdir
6
+
7
+ base_uri 'app.imdb.com'
8
+ default_params = {"api" => "v1", "appid" => "iphone1", "locale" => "en_US", "timestamp" => Time.now.to_i, "sig" => "heres my signature"}
9
+
10
+
11
+ def find_by_title(title)
12
+ movie_results = []
13
+ results = self.class.get('/find', :query => {:q => title}).parsed_response
14
+
15
+ if results["data"]["results"]
16
+ results["data"]["results"].each do |result_section|
17
+ result_section["list"].each do |r|
18
+ h = {:title => r["title"], :year => r["year"], :imdb_id => r["tconst"]}
19
+ h.merge!(:poster_url => r["image"]["url"]) if r["image"] && r["image"]["url"]
20
+ movie_results << h if r["type"] == "feature"
21
+ end
22
+ end
23
+ end
24
+
25
+ movie_results
26
+ end
27
+
28
+ def find_movie_by_id(imdb_id)
29
+ result = self.class.get('/title/maindetails', :query => {:tconst => imdb_id}).parsed_response
30
+ Movie.new(result["data"])
31
+ end
32
+
33
+ def top_250
34
+ results = self.class.get('/chart/top').parsed_response
35
+ results["data"]["list"]["list"].map { |r| {:title => r["title"], :imdb_id => r["tconst"], :year => r["year"], :poster_url => (r["image"] ? r["image"]["url"] : nil)} }
36
+ end
37
+
38
+ def popular_shows
39
+ results = self.class.get('/chart/tv').parsed_response
40
+ results["data"]["list"].map { |r| {:title => r["title"], :imdb_id => r["tconst"], :year => r["year"], :poster_url => (r["image"] ? r["image"]["url"] : nil)} }
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ module ImdbParty
2
+ class Movie
3
+ attr_accessor :imdb_id, :title, :directors, :writers, :tagline, :company, :plot, :runtime, :rating, :poster_url, :release_date, :certification, :genres, :actors, :trailers
4
+
5
+ def initialize(options={})
6
+ @imdb_id = options["tconst"]
7
+ @title = options["title"]
8
+ @tagline = options["tagline"]
9
+ @plot = options["plot"]["outline"] if options["plot"]
10
+ @runtime = "#{(options["runtime"]["time"]/60).to_i} min" if options["runtime"]
11
+ @rating = options["rating"]
12
+ @poster_url = options["image"]["url"] if options["image"]
13
+ @release_date = options["release_date"]["normal"] if options["release_date"] && options["release_date"]["normal"]
14
+ @certification = options["certificate"]["certificate"] if options["certificate"] && options["certificate"]["certificate"]
15
+ @genres = options["genres"] || []
16
+
17
+ # parse directors
18
+ @directors = options["directors_summary"] ? options["directors_summary"].map { |d| Person.new(d) } : []
19
+
20
+ # parse directors
21
+ @writers = []
22
+ @writers = options["writers_summary"] ? options["writers_summary"].map { |w| Person.new(w) } : []
23
+
24
+ # parse actors
25
+ @actors = []
26
+ @actors = options["cast_summary"] ? options["cast_summary"].map { |a| Person.new(a) } : []
27
+
28
+ #parse trailers
29
+ @trailers = {}
30
+ if options["trailer"] && options["trailer"]["encodings"]
31
+ options["trailer"]["encodings"].each_pair do |k,v|
32
+ @trailers[v["format"]] = v["url"]
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ module ImdbParty
2
+ class Person
3
+ attr_accessor :name, :role, :imdb_id
4
+
5
+ def initialize(options={})
6
+ @name = options["name"]["name"]
7
+ @imdb_id = options["name"]["nconst"]
8
+
9
+ @role = options["char"] if options["char"]
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class MovieTest < Test::Unit::TestCase
4
+ context "a movie" do
5
+ setup do
6
+ @imdb = ImdbParty::Imdb.new
7
+ @movie = @imdb.find_movie_by_id("tt0382932")
8
+ end
9
+
10
+ should "have a title" do
11
+ assert_equal "Ratatouille", @movie.title
12
+ end
13
+
14
+ should "have an imdb_id" do
15
+ assert_equal "tt0382932", @movie.imdb_id
16
+ end
17
+
18
+ should "have a tagline" do
19
+ assert_equal "Dinner is served... Summer 2007", @movie.tagline
20
+ end
21
+
22
+ should "have a plot" do
23
+ assert_equal "Remy is a young rat in the French countryside who arrives in Paris, only to find out that his cooking idol is dead. When he makes an unusual alliance with a restaurant's new garbage boy, the culinary and personal adventures begin despite Remy's family's skepticism and the rat-hating world of humans.", @movie.plot
24
+ end
25
+
26
+ should "have a runtime" do
27
+ assert_equal "111 min", @movie.runtime
28
+ end
29
+
30
+ should "have a rating" do
31
+ assert_equal 8.1, @movie.rating
32
+ end
33
+
34
+ should "have a poster_url" do
35
+ assert_equal "http://ia.media-imdb.com/images/M/MV5BMzgwNzY0MDkwOF5BMl5BanBnXkFtZTcwNzMxMDI1MQ@@._V1_.jpg", @movie.poster_url
36
+ end
37
+
38
+ should "have a release date" do
39
+ assert_equal DateTime.parse("2007-06-29"), @movie.release_date
40
+ end
41
+
42
+ should "have a certification" do
43
+ assert_equal "G", @movie.certification
44
+ end
45
+
46
+ should "have trailers" do
47
+ assert_equal Hash, @movie.trailers.class
48
+ assert_equal 4, @movie.trailers.keys.size
49
+ assert_equal "http://www.totaleclips.com/Player/Bounce.aspx?eclipid=e27826&bitrateid=461&vendorid=102&type=.mp4", @movie.trailers[@movie.trailers.keys.first]
50
+ end
51
+
52
+ should "have genres" do
53
+ assert_equal Array, @movie.genres.class
54
+ assert_equal 4, @movie.genres.size
55
+ end
56
+
57
+ should "have actors" do
58
+ assert_equal Array, @movie.actors.class
59
+ assert_equal 4, @movie.actors.size
60
+ end
61
+
62
+ should "have directors" do
63
+ assert_equal Array, @movie.directors.class
64
+ assert_equal 2, @movie.directors.size
65
+ end
66
+
67
+ should "have writers" do
68
+ assert_equal Array, @movie.writers.class
69
+ assert_equal 2, @movie.writers.size
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class PersonTest < Test::Unit::TestCase
4
+ context "a person" do
5
+ setup do
6
+ @imdb = ImdbParty::Imdb.new
7
+ @movie = @imdb.find_movie_by_id("tt0382932")
8
+ end
9
+
10
+ context "actors" do
11
+ should "have a name" do
12
+ assert_equal "Patton Oswalt", @movie.actors.first.name
13
+ end
14
+
15
+ should "have a role" do
16
+ assert_equal "Remy", @movie.actors.first.role
17
+ end
18
+ end
19
+
20
+ context "directors" do
21
+ should "have a name" do
22
+ assert_equal "Brad Bird", @movie.directors.first.name
23
+ end
24
+
25
+ should "have not have a role" do
26
+ assert_equal nil, @movie.directors.first.role
27
+ end
28
+ end
29
+
30
+ context "writers" do
31
+ should "have a name" do
32
+ assert_equal "Brad Bird", @movie.writers.first.name
33
+ end
34
+
35
+ should "have not have a role" do
36
+ assert_equal nil, @movie.writers.first.role
37
+ end
38
+ end
39
+
40
+
41
+ end
42
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class SearchTest < Test::Unit::TestCase
4
+ context "imdb" do
5
+ setup do
6
+ @imdb = ImdbParty::Imdb.new
7
+ end
8
+
9
+ context "search for title" do
10
+ setup do
11
+ @results = @imdb.find_by_title("ratatouille")
12
+ end
13
+
14
+ should "have 15 results" do
15
+ assert_equal 15, @results.size
16
+ end
17
+ end
18
+
19
+ context "find movie by id" do
20
+ setup do
21
+ @movie = @imdb.find_movie_by_id("tt0382932")
22
+ end
23
+
24
+ should "be a ImdbParty::Movie" do
25
+ assert_equal ImdbParty::Movie, @movie.class
26
+ end
27
+ end
28
+
29
+ context "find top 250 movies" do
30
+ setup do
31
+ @movies = @imdb.top_250
32
+ end
33
+
34
+ should "be an Array of Hashes" do
35
+ assert_equal Array, @movies.class
36
+ assert_equal Hash, @movies.first.class
37
+ end
38
+ end
39
+
40
+ context "find popular shows" do
41
+ setup do
42
+ @shows = @imdb.popular_shows
43
+ end
44
+
45
+ should "be an Array of Hashes" do
46
+ assert_equal Array, @shows.class
47
+ assert_equal Hash, @shows.first.class
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'imdb_party'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imdb_party
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jon Maddox
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-11 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: httparty
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: IMDB client using the IMDB API that their iPhone app uses
50
+ email: jon@mustacheinc.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.md
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - VERSION
65
+ - imdb_party.gemspec
66
+ - lib/imdb_party.rb
67
+ - lib/imdb_party/httparty_icebox.rb
68
+ - lib/imdb_party/imdb.rb
69
+ - lib/imdb_party/movie.rb
70
+ - lib/imdb_party/person.rb
71
+ - test/movie_test.rb
72
+ - test/person_test.rb
73
+ - test/search_test.rb
74
+ - test/test_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/maddox/imdb_party
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.3.7
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: IMDB client using the IMDB API that their iPhone app uses
109
+ test_files:
110
+ - test/movie_test.rb
111
+ - test/person_test.rb
112
+ - test/search_test.rb
113
+ - test/test_helper.rb