maksar-imdb_party 0.6.2

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ImdbParty!
2
+
3
+ ## How To Use
4
+
5
+ ### Create an instance
6
+
7
+ imdb = ImdbParty::Imdb.new
8
+ imdb = ImdbParty::Imdb.new(:anonymize => true) # this will anonymize your requests to prevent getting your ip banned
9
+
10
+
11
+ ### Search for a movie by title
12
+
13
+ imdb.find_by_title("The Dark Knight") => [{:title => "The Dark Knight", :year => "2008", :imdb_id => "tt0468569"}, {:title => "Batman Unmasked", ...}]
14
+
15
+ ### Get a movie by its imdb_id
16
+
17
+ movie = imdb.find_movie_by_id("tt0468569")
18
+
19
+ movie.title => "The Dark Knight"
20
+ movie.rating => 8.1
21
+ movie.certification => "PG-13"
22
+
23
+ ### Find the top 250 movies of all time
24
+
25
+ imdb.top_250 => [{:title => "Shawshank Redemption", :year => "1994", :imdb_id => "tt0111161"}, {:title => "The Godfather", ...}]
26
+
27
+ ### Get the currently popular tv shows
28
+
29
+ imdb.popular_shows => [{:title => "Glee", :year => "2009", :imdb_id => "tt1327801"}, {:title => "Dexter", ...}]
data/Rakefile ADDED
@@ -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 = "maksar-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.6.2
@@ -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 'fileutils'
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| Marshal.dump(value, file) }
211
+ true
212
+ end
213
+ def get(key)
214
+ data = Marshal.load(File.new(@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,74 @@
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
+
9
+ def initialize(options={})
10
+ self.class.base_uri 'anonymouse.org/cgi-bin/anon-www.cgi/http://app.imdb.com' if options[:anonymize]
11
+ end
12
+
13
+ def build_url(path, params={})
14
+ default_params = {"api" => "v1", "appid" => "iphone1_1", "apiPolicy" => "app1_1", "apiKey" => "2wex6aeu6a8q9e49k7sfvufd6rhh0n", "locale" => "en_US", "timestamp" => Time.now.to_i}
15
+
16
+ query_params = default_params.merge(params)
17
+ query_param_array = []
18
+
19
+ base_uri = URI.parse(self.class.base_uri)
20
+ base_host = base_uri.host
21
+ the_path = base_uri.path + path
22
+
23
+ query_params.each_pair{|key, value| query_param_array << "#{key}=#{URI.escape(value.to_s)}" }
24
+ uri = URI::HTTP.build(:scheme => 'https', :host => base_host, :path => the_path, :query => query_param_array.join("&"))
25
+
26
+ query_param_array << "sig=app1-#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), default_params["apiKey"], uri.to_s)}"
27
+
28
+ uri = URI::HTTP.build(:scheme => 'https', :host => base_host, :path => the_path, :query => query_param_array.join("&"))
29
+ uri.to_s
30
+ end
31
+
32
+ def find_by_title(title)
33
+ movie_results = []
34
+ url = build_url('/find', :q => title)
35
+
36
+ results = self.class.get(url).parsed_response
37
+
38
+ if results["data"] && results["data"]["results"]
39
+ results["data"]["results"].each do |result_section|
40
+ result_section["list"].each do |r|
41
+ next unless r["tconst"] && r["title"]
42
+ h = {:title => r["title"], :year => r["year"], :imdb_id => r["tconst"], :kind => r["type"]}
43
+ h.merge!(:poster_url => r["image"]["url"]) if r["image"] && r["image"]["url"]
44
+ movie_results << h
45
+ end
46
+ end
47
+ end
48
+
49
+ movie_results
50
+ end
51
+
52
+ def find_movie_by_id(imdb_id)
53
+ url = build_url('/title/maindetails', :tconst => imdb_id)
54
+
55
+ result = self.class.get(url).parsed_response
56
+ Movie.new(result["data"])
57
+ end
58
+
59
+ def top_250
60
+ url = build_url('/chart/top')
61
+
62
+ results = self.class.get(url).parsed_response
63
+ results["data"]["list"]["list"].map { |r| {:title => r["title"], :imdb_id => r["tconst"], :year => r["year"], :poster_url => (r["image"] ? r["image"]["url"] : nil)} }
64
+ end
65
+
66
+ def popular_shows
67
+ url = build_url('/chart/tv')
68
+
69
+ results = self.class.get(url).parsed_response
70
+ results["data"]["list"].map { |r| {:title => r["title"], :imdb_id => r["tconst"], :year => r["year"], :poster_url => (r["image"] ? r["image"]["url"] : nil)} }
71
+ end
72
+
73
+ end
74
+ 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
data/lib/imdb_party.rb ADDED
@@ -0,0 +1,8 @@
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')
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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{maksar-imdb_party}
8
+ s.version = "0.6.2"
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{2011-06-01}
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
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/imdb_party.rb",
26
+ "lib/imdb_party/httparty_icebox.rb",
27
+ "lib/imdb_party/imdb.rb",
28
+ "lib/imdb_party/movie.rb",
29
+ "lib/imdb_party/person.rb",
30
+ "maksar-imdb_party.gemspec",
31
+ "test/movie_test.rb",
32
+ "test/person_test.rb",
33
+ "test/search_test.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/maddox/imdb_party}
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.6.2}
39
+ s.summary = %q{IMDB client using the IMDB API that their iPhone app uses}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
46
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_dependency(%q<httparty>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<httparty>, [">= 0"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,85 @@
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_match /http:\/\/ia.media-imdb.com\/images\/.*/, @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 2, @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
+
74
+ context "a movie while anonymized" do
75
+ setup do
76
+ @imdb = ImdbParty::Imdb.new(:anonymize => true)
77
+ @movie = @imdb.find_movie_by_id("tt0382932")
78
+ end
79
+
80
+ should "have a title" do
81
+ assert_equal "Ratatouille", @movie.title
82
+ end
83
+ end
84
+
85
+ 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 "Brad Garrett", @movie.actors.first.name
13
+ end
14
+
15
+ should "have a role" do
16
+ assert_equal "Gusteau", @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 "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 "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,91 @@
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 at least 15 results" do
15
+ assert (@results.size >= 15)
16
+ end
17
+ end
18
+
19
+ context "search for title with spaces in the name" do
20
+ setup do
21
+ @results = @imdb.find_by_title("the truman show")
22
+ end
23
+
24
+ should "have at least 1 result" do
25
+ assert (@results.size >= 1)
26
+ end
27
+ end
28
+
29
+ context "search for bad title with no results" do
30
+ setup do
31
+ @results = @imdb.find_by_title("sdkljlkkl123j4lk23kl3")
32
+ end
33
+
34
+ should "have 0 results" do
35
+ assert_equal 0, @results.size
36
+ end
37
+ end
38
+
39
+ context "find movie by id" do
40
+ setup do
41
+ @movie = @imdb.find_movie_by_id("tt0382932")
42
+ end
43
+
44
+ should "be a ImdbParty::Movie" do
45
+ assert_equal ImdbParty::Movie, @movie.class
46
+ end
47
+ end
48
+
49
+ context "find top 250 movies" do
50
+ setup do
51
+ @movies = @imdb.top_250
52
+ end
53
+
54
+ should "be an Array of Hashes" do
55
+ assert_equal Array, @movies.class
56
+ assert_equal Hash, @movies.first.class
57
+ end
58
+ end
59
+
60
+ context "find popular shows" do
61
+ setup do
62
+ @shows = @imdb.popular_shows
63
+ end
64
+
65
+ should "be an Array of Hashes" do
66
+ assert_equal Array, @shows.class
67
+ assert_equal Hash, @shows.first.class
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ context "anonymous imdb" do
74
+ setup do
75
+ @imdb = ImdbParty::Imdb.new(:anonymize => true)
76
+ end
77
+
78
+ context "find popular shows" do
79
+ setup do
80
+ @shows = @imdb.popular_shows
81
+ end
82
+
83
+ should "be an Array of Hashes" do
84
+ assert_equal Array, @shows.class
85
+ assert_equal Hash, @shows.first.class
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ 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,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maksar-imdb_party
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.6.2
6
+ platform: ruby
7
+ authors:
8
+ - Jon Maddox
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-01 00:00:00 +03:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: shoulda
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: IMDB client using the IMDB API that their iPhone app uses
39
+ email: jon@mustacheinc.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - LICENSE
46
+ - README.md
47
+ files:
48
+ - .document
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/imdb_party.rb
54
+ - lib/imdb_party/httparty_icebox.rb
55
+ - lib/imdb_party/imdb.rb
56
+ - lib/imdb_party/movie.rb
57
+ - lib/imdb_party/person.rb
58
+ - maksar-imdb_party.gemspec
59
+ - test/movie_test.rb
60
+ - test/person_test.rb
61
+ - test/search_test.rb
62
+ - test/test_helper.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/maddox/imdb_party
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.6.2
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: IMDB client using the IMDB API that their iPhone app uses
91
+ test_files: []
92
+