myimdb 0.4.7 → 0.4.8

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.
@@ -2,32 +2,37 @@ class UnformattedHtml < Exception; end
2
2
  class DocumentNotFound < Exception; end
3
3
  class ScraperNotFound < Exception; end
4
4
 
5
- module HandleExceptions
6
- def self.included(base)
7
- base.send(:include, InstanceMethods)
8
- base.send(:extend, ClassMethods)
9
- end
10
-
11
- module InstanceMethods
12
- end
13
-
14
- module ClassMethods
15
- def handle_exceptions_for(*method_names)
16
- method_names.each do |method_name|
17
- alias_method("_#{method_name}", method_name)
18
- define_method(method_name) do
19
- begin
20
- send("_#{method_name}")
21
- rescue
22
- raise UnformattedHtml.new("Unable to find tag: #{method_name}, probably you are parsing the wrong page.")
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
@@ -30,7 +30,7 @@ module Myimdb
30
30
  @document ||= Nokogiri::HTML(open(@url))
31
31
  end
32
32
 
33
- handle_exceptions_for :rating, :votes, :genres, :plot
33
+ handle_exceptions_for :rating, :votes, :genres, :plot, :image
34
34
  end
35
35
  end
36
36
  end
@@ -30,7 +30,7 @@ module Myimdb
30
30
  @document ||= Nokogiri::HTML(open(@url))
31
31
  end
32
32
 
33
- handle_exceptions_for :rating, :votes, :genres, :plot
33
+ handle_exceptions_for :rating, :votes, :genres, :plot, :image
34
34
  end
35
35
  end
36
36
  end
@@ -6,24 +6,24 @@ module Myimdb
6
6
  headers 'Content-Type' => 'application/json'
7
7
 
8
8
  AppKey = '36C1CEF363A00C6536C4420D356B5E507C4C2AF1'
9
- base_uri 'api.search.live.net'
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, :sources=> 'spell'} )
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{myimdb}
8
- s.version = "0.4.7"
8
+ s.version = "0.4.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaurav"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myimdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 7
10
- version: 0.4.7
9
+ - 8
10
+ version: 0.4.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gaurav