royw-tmdb 0.1.1 → 0.1.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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :minor: 1
@@ -4,8 +4,8 @@ class TmdbImage
4
4
  # imdb_id => String IMDB ID either with or without the 'tt' prefix
5
5
  # api_key => String containing the themovieDb.com API key
6
6
  # logger => nil or logger instance
7
- def initialize(imdb_id, api_key, logger)
8
- @imdb_id = imdb_id
7
+ def initialize(ident, api_key, logger)
8
+ @imdb_id = 'tt' + ident.gsub(/^tt/, '') unless ident.blank?
9
9
  @api_key = api_key
10
10
  @logger = OptionalLogger.new(logger)
11
11
  end
@@ -10,7 +10,7 @@ class TmdbMovie
10
10
  end
11
11
 
12
12
  def image
13
- TmdbImage.new(@imdb_id, @api_key, @logger)
13
+ TmdbImage.new(@imdb_id.gsub(/^tt/, ''), @api_key, @logger) rescue nil
14
14
  end
15
15
 
16
16
  def fanarts
@@ -37,7 +37,7 @@ class TmdbProfile
37
37
  end
38
38
 
39
39
  def initialize(ident, key, filespec, logger)
40
- @imdb_id = ident
40
+ @imdb_id = 'tt' + ident.gsub(/^tt/, '') unless ident.blank?
41
41
  @api_key = key
42
42
  @filespec = filespec
43
43
  @logger = OptionalLogger.new(logger)
@@ -62,7 +62,7 @@ class TmdbProfile
62
62
 
63
63
  # return the TmdbImage for this profile
64
64
  def image
65
- TmdbImage.new(@imdb_id.gsub(/^tt/, ''), @api_key, @logger)
65
+ TmdbImage.new(@imdb_id.gsub(/^tt/, ''), @api_key, @logger) rescue nil
66
66
  end
67
67
 
68
68
  protected
@@ -3,7 +3,7 @@
3
3
  # override the classes' read_page method and replace with one
4
4
  # that will cache pages in spec/samples/{url}
5
5
 
6
- class ImdbMovie
6
+ class TmdbMovie
7
7
  private
8
8
  def read_page(page)
9
9
  html = nil
@@ -32,7 +32,7 @@ class ImdbMovie
32
32
  end
33
33
  end
34
34
 
35
- class ImdbSearch
35
+ class TmdbSearch
36
36
  private
37
37
  def read_page(page)
38
38
  html = nil
@@ -61,11 +61,11 @@ class ImdbSearch
61
61
  end
62
62
  end
63
63
 
64
- class ImdbImage
64
+ class TmdbImage
65
65
  private
66
66
  def read_page(page)
67
67
  html = nil
68
- filespec = page.gsub(/^http:\//, 'spec/samples').gsub(/\/$/, '.html')
68
+ filespec = page.gsub(/^http:\//, 'spec/samples')
69
69
  if File.exist?(filespec)
70
70
  html = open(filespec).read
71
71
  else
@@ -78,7 +78,7 @@ class ImdbImage
78
78
  # this is used to save imdb pages so they may be used by rspec
79
79
  def cache_html_files(page, html)
80
80
  begin
81
- filespec = page.gsub(/^http:\//, 'spec/samples').gsub(/\/$/, '.html')
81
+ filespec = page.gsub(/^http:\//, 'spec/samples')
82
82
  unless File.exist?(filespec)
83
83
  puts "caching #{filespec}"
84
84
  File.mkdirs(File.dirname(filespec))
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <results for="tt0060934" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
3
+ <opensearch:Query searchTerms="tt0060934"/>
4
+ <opensearch:totalResults>0</opensearch:totalResults>
5
+ <moviematches>
6
+ <movie>Your query didn't return any results.</movie>
7
+ </moviematches>
8
+ </results>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <results for="tt0465234" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
3
+ <opensearch:Query searchTerms="tt0465234"/>
4
+ <opensearch:totalResults>1</opensearch:totalResults>
5
+ <moviematches>
6
+ <movie>
7
+ <score>1.0</score>
8
+ <popularity>4</popularity>
9
+ <title>National Treasure: Book of Secrets</title>
10
+ <alternative_title>National Treasure 2</alternative_title>
11
+ <type>movie</type>
12
+ <id>6637</id>
13
+ <imdb>tt0465234</imdb>
14
+ <url>http://www.themoviedb.org/movie/6637</url>
15
+ <short_overview>Treasure hunter Benjamin Franklin Gates looks to discover the truth behind the assassination of Abraham Lincoln, by uncovering the mystery within the 18 pages missing from assassin John Wilkes Booth&apos;s diary.</short_overview>
16
+ <release>2007-12-13</release>
17
+ <poster size="original">http://www.themoviedb.org/image/posters/6577/National_Treasure_Book_Of_Secrets_-_Poster_1__2007_.jpg</poster>
18
+ <poster size="mid">http://www.themoviedb.org/image/posters/6577/National_Treasure_Book_Of_Secrets_-_Poster_1__2007__mid.jpg</poster>
19
+ <poster size="cover">http://www.themoviedb.org/image/posters/6577/National_Treasure_Book_Of_Secrets_-_Poster_1__2007__cover.jpg</poster>
20
+ <poster size="thumb">http://www.themoviedb.org/image/posters/6577/National_Treasure_Book_Of_Secrets_-_Poster_1__2007__thumb.jpg</poster>
21
+ <backdrop size="original">http://www.themoviedb.org/image/backdrops/14621/National_Treasure_-_Book_Of_Secrets__XVID___2007_-fanart.jpg</backdrop>
22
+ <backdrop size="mid">http://www.themoviedb.org/image/backdrops/14621/National_Treasure_-_Book_Of_Secrets__XVID___2007_-fanart_poster.jpg</backdrop>
23
+ <backdrop size="thumb">http://www.themoviedb.org/image/backdrops/14621/National_Treasure_-_Book_Of_Secrets__XVID___2007_-fanart_thumb.jpg</backdrop>
24
+ </movie>
25
+ </moviematches>
26
+ </results>
@@ -30,11 +30,11 @@ describe "TmdbImage" do
30
30
 
31
31
  it "should find image via profile" do
32
32
  profile = TmdbProfile.first(:imdb_id => 'tt0465234', :api_key => TMDB_API_KEY, :logger => @logger)
33
- profile.image.imdb_id.should == '0465234'
33
+ profile.image.imdb_id.should == 'tt0465234'
34
34
  end
35
35
 
36
36
  it "should find image via movie" do
37
- profile = TmdbMovie.new('tt0465234', TMDB_API_KEY, @logger)
37
+ profile = TmdbMovie.new('0465234', TMDB_API_KEY, @logger)
38
38
  profile.image.imdb_id.should == 'tt0465234'
39
39
  end
40
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: royw-tmdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Wright
@@ -37,6 +37,9 @@ files:
37
37
  - lib/tmdb/tmdb_movie.rb
38
38
  - lib/tmdb/tmdb_profile.rb
39
39
  - spec/cache_extensions.rb
40
+ - spec/samples/api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=tt0060934&api_key=7a2f6eb9b6aa01651000f0a9324db835
41
+ - spec/samples/api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=tt0465234&api_key=7a2f6eb9b6aa01651000f0a9324db835
42
+ - spec/samples/www.themoviedb.org/image/backdrops/14621/National_Treasure_-_Book_Of_Secrets__XVID___2007_-fanart.jpg
40
43
  - spec/spec_helper.rb
41
44
  - spec/tmdb_image_spec.rb
42
45
  - spec/tmdb_movie_spec.rb