myimdb 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
data/lib/myimdb/scraper/base.rb
CHANGED
@@ -2,32 +2,37 @@ class UnformattedHtml < Exception; end
|
|
2
2
|
class DocumentNotFound < Exception; end
|
3
3
|
class ScraperNotFound < Exception; end
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
5
|
+
module Myimdb
|
6
|
+
module HandleExceptions
|
7
|
+
EXCEPTIONS_ENABLED = true
|
8
|
+
def self.included(base)
|
9
|
+
base.send(:include, InstanceMethods)
|
10
|
+
base.send(:extend, ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def handle_exceptions_for(*method_names)
|
18
|
+
method_names.each do |method_name|
|
19
|
+
alias_method("_#{method_name}", method_name)
|
20
|
+
define_method(method_name) do
|
21
|
+
begin
|
22
|
+
send("_#{method_name}")
|
23
|
+
rescue
|
24
|
+
if EXCEPTIONS_ENABLED
|
25
|
+
raise UnformattedHtml.new("Unable to find tag: #{method_name}, probably you are parsing the wrong page.")
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
28
|
-
end
|
29
35
|
|
30
|
-
module Myimdb
|
31
36
|
module Scraper
|
32
37
|
class Base
|
33
38
|
include HandleExceptions
|
@@ -69,7 +69,7 @@ module Myimdb
|
|
69
69
|
document['properties'][path]['values'].collect{ |obj| { :name=> obj['text'], :url=> obj['url'] } }
|
70
70
|
end
|
71
71
|
|
72
|
-
handle_exceptions_for :directors, :directors_with_url, :writers, :writers_with_url, :genres, :tagline, :plot, :year, :image
|
72
|
+
handle_exceptions_for :directors, :directors_with_url, :writers, :writers_with_url, :genres, :tagline, :plot, :year, :image, :release_date
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
data/lib/myimdb/search/bing.rb
CHANGED
@@ -6,24 +6,24 @@ module Myimdb
|
|
6
6
|
headers 'Content-Type' => 'application/json'
|
7
7
|
|
8
8
|
AppKey = '36C1CEF363A00C6536C4420D356B5E507C4C2AF1'
|
9
|
-
base_uri 'api.
|
9
|
+
base_uri 'api.bing.net'
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def search_text( text, options={} )
|
13
13
|
text = text + " site:#{options[:restrict_to]}" if !options[:restrict_to].blank?
|
14
|
-
response = get( '/json.aspx', :query=> {:Appid=> AppKey, :query=> text, :sources=> 'web'} )
|
14
|
+
response = get( '/json.aspx', :query=> {:Appid=> AppKey, :query=> text, :sources=> 'web', :Version=> 2.0, :Market=> 'en-us' } )
|
15
15
|
parse_search_result(response, 'Web')
|
16
16
|
end
|
17
17
|
|
18
18
|
def search_images( text, options={} )
|
19
19
|
text = text + " site:#{options[:restrict_to]}" if !options[:restrict_to].blank?
|
20
|
-
response = get( '/json.aspx', :query=> {:Appid=> AppKey, :query=> text, :sources=> 'image'} )
|
20
|
+
response = get( '/json.aspx', :query=> {:Appid=> AppKey, :query=> text, :sources=> 'image', :Version=> 2.0, :Market=> 'en-us' } )
|
21
21
|
parse_search_result(response, 'Image')
|
22
22
|
end
|
23
23
|
|
24
24
|
def spell( text, options={} )
|
25
25
|
text = text + " site:#{options[:restrict_to]}" if !options[:restrict_to].blank?
|
26
|
-
response = get( '/json.aspx', :query=> {:Appid=> AppKey, :query=> text, :
|
26
|
+
response = get( '/json.aspx', :query=> {:Appid=> AppKey, :query=> text, :Sources=> 'spell', :Version=> 2.0, :Market=> 'en-us' } )
|
27
27
|
parse_search_result(response, 'Spell')
|
28
28
|
end
|
29
29
|
|
@@ -31,8 +31,8 @@ module Myimdb
|
|
31
31
|
def parse_search_result( response, type )
|
32
32
|
response['SearchResponse'][type]['Results'].collect do |response_element|
|
33
33
|
{
|
34
|
-
:url => response_element['Url'],
|
35
|
-
:title => response_element['Title']
|
34
|
+
:url => response_element['MediaUrl'] || response_element['Url'],
|
35
|
+
:title => response_element['Value'] || response_element['Title']
|
36
36
|
}
|
37
37
|
end
|
38
38
|
end
|
data/myimdb.gemspec
CHANGED
metadata
CHANGED