imdb_party 0.6.1 → 0.7.0

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 CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -3,23 +3,24 @@ module ImdbParty
3
3
  include HTTParty
4
4
  include HTTParty::Icebox
5
5
  cache :store => 'file', :timeout => 120, :location => Dir.tmpdir
6
-
6
+
7
7
  base_uri 'app.imdb.com'
8
+ format :json
8
9
 
9
10
  def initialize(options={})
10
- self.class.base_uri 'anonymouse.org/cgi-bin/anon-www.cgi/http://app.imdb.com' if options[:anonymize]
11
+ self.class.base_uri 'anonymouse.org/cgi-bin/anon-www.cgi/https://app.imdb.com' if options[:anonymize]
11
12
  end
12
-
13
+
13
14
  def build_url(path, params={})
14
15
  default_params = {"api" => "v1", "appid" => "iphone1_1", "apiPolicy" => "app1_1", "apiKey" => "2wex6aeu6a8q9e49k7sfvufd6rhh0n", "locale" => "en_US", "timestamp" => Time.now.to_i}
15
16
 
16
17
  query_params = default_params.merge(params)
17
18
  query_param_array = []
18
-
19
+
19
20
  base_uri = URI.parse(self.class.base_uri)
20
21
  base_host = base_uri.host
21
22
  the_path = base_uri.path + path
22
-
23
+
23
24
  query_params.each_pair{|key, value| query_param_array << "#{key}=#{URI.escape(value.to_s)}" }
24
25
  uri = URI::HTTP.build(:scheme => 'https', :host => base_host, :path => the_path, :query => query_param_array.join("&"))
25
26
 
@@ -28,34 +29,40 @@ module ImdbParty
28
29
  uri = URI::HTTP.build(:scheme => 'https', :host => base_host, :path => the_path, :query => query_param_array.join("&"))
29
30
  uri.to_s
30
31
  end
31
-
32
+
32
33
  def find_by_title(title)
34
+ default_find_by_title_params = {"json" => "1", "nr" => 1, "tt" => "on", "q" => title}
35
+
33
36
  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"]
37
+
38
+ results = self.class.get("http://www.imdb.com/xml/find", :query => default_find_by_title_params).parsed_response
39
+ puts results.inspect
40
+
41
+ keys = ["title_exact", "title_popular", "title_approx", "title_substring"]
42
+
43
+ keys.each do |key|
44
+ if results[key]
45
+ results[key].each do |r|
46
+ next unless r["id"] && r["title"]
47
+ year = r["title_description"].match(/^(\d\d\d\d)/)
48
+ h = {:title => r["title"], :year => year, :imdb_id => r["id"], :kind => r["key"]}
44
49
  movie_results << h
45
50
  end
46
- end
47
51
  end
48
-
52
+
53
+
54
+ end
55
+
49
56
  movie_results
50
57
  end
51
58
 
52
59
  def find_movie_by_id(imdb_id)
53
60
  url = build_url('/title/maindetails', :tconst => imdb_id)
54
-
61
+
55
62
  result = self.class.get(url).parsed_response
56
63
  Movie.new(result["data"])
57
64
  end
58
-
65
+
59
66
  def top_250
60
67
  url = build_url('/chart/top')
61
68
 
@@ -69,6 +76,6 @@ module ImdbParty
69
76
  results = self.class.get(url).parsed_response
70
77
  results["data"]["list"].map { |r| {:title => r["title"], :imdb_id => r["tconst"], :year => r["year"], :poster_url => (r["image"] ? r["image"]["url"] : nil)} }
71
78
  end
72
-
79
+
73
80
  end
74
81
  end
data/test/search_test.rb CHANGED
@@ -2,84 +2,84 @@ require 'test_helper'
2
2
 
3
3
  class SearchTest < Test::Unit::TestCase
4
4
  context "imdb" do
5
- setup do
5
+ setup do
6
6
  @imdb = ImdbParty::Imdb.new
7
7
  end
8
-
8
+
9
9
  context "search for title" do
10
10
  setup do
11
11
  @results = @imdb.find_by_title("ratatouille")
12
12
  end
13
-
13
+
14
14
  should "have at least 15 results" do
15
15
  assert (@results.size >= 15)
16
16
  end
17
17
  end
18
-
18
+
19
19
  context "search for title with spaces in the name" do
20
20
  setup do
21
21
  @results = @imdb.find_by_title("the truman show")
22
22
  end
23
-
23
+
24
24
  should "have at least 1 result" do
25
25
  assert (@results.size >= 1)
26
26
  end
27
27
  end
28
-
28
+
29
29
  context "search for bad title with no results" do
30
30
  setup do
31
31
  @results = @imdb.find_by_title("sdkljlkkl123j4lk23kl3")
32
32
  end
33
-
33
+
34
34
  should "have 0 results" do
35
35
  assert_equal 0, @results.size
36
36
  end
37
37
  end
38
-
38
+
39
39
  context "find movie by id" do
40
40
  setup do
41
41
  @movie = @imdb.find_movie_by_id("tt0382932")
42
42
  end
43
-
43
+
44
44
  should "be a ImdbParty::Movie" do
45
45
  assert_equal ImdbParty::Movie, @movie.class
46
46
  end
47
47
  end
48
-
48
+
49
49
  context "find top 250 movies" do
50
50
  setup do
51
51
  @movies = @imdb.top_250
52
52
  end
53
-
53
+
54
54
  should "be an Array of Hashes" do
55
55
  assert_equal Array, @movies.class
56
56
  assert_equal Hash, @movies.first.class
57
57
  end
58
58
  end
59
-
59
+
60
60
  context "find popular shows" do
61
61
  setup do
62
62
  @shows = @imdb.popular_shows
63
63
  end
64
-
64
+
65
65
  should "be an Array of Hashes" do
66
66
  assert_equal Array, @shows.class
67
67
  assert_equal Hash, @shows.first.class
68
68
  end
69
69
  end
70
-
70
+
71
71
  end
72
72
 
73
73
  context "anonymous imdb" do
74
- setup do
74
+ setup do
75
75
  @imdb = ImdbParty::Imdb.new(:anonymize => true)
76
76
  end
77
-
77
+
78
78
  context "find popular shows" do
79
79
  setup do
80
80
  @shows = @imdb.popular_shows
81
81
  end
82
-
82
+
83
83
  should "be an Array of Hashes" do
84
84
  assert_equal Array, @shows.class
85
85
  assert_equal Hash, @shows.first.class
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imdb_party
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease:
4
+ hash: 3
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 1
10
- version: 0.6.1
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jon Maddox
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-04 00:00:00 -04:00
18
+ date: 2012-06-25 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -57,7 +57,6 @@ extra_rdoc_files:
57
57
  - README.md
58
58
  files:
59
59
  - .document
60
- - .gitignore
61
60
  - LICENSE
62
61
  - README.md
63
62
  - Rakefile
@@ -77,8 +76,8 @@ homepage: http://github.com/maddox/imdb_party
77
76
  licenses: []
78
77
 
79
78
  post_install_message:
80
- rdoc_options:
81
- - --charset=UTF-8
79
+ rdoc_options: []
80
+
82
81
  require_paths:
83
82
  - lib
84
83
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -102,12 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
101
  requirements: []
103
102
 
104
103
  rubyforge_project:
105
- rubygems_version: 1.4.2
104
+ rubygems_version: 1.3.7
106
105
  signing_key:
107
106
  specification_version: 3
108
107
  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
108
+ test_files: []
109
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg