filmbuff 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0835d52418eba19073d416952ffa7a71319f22b9
4
+ data.tar.gz: 60bec3177b930f361f2748b6f34c78d4a6b74fa2
5
+ SHA512:
6
+ metadata.gz: 6d7acb437fa288d558443c67427a379c7aab193d92e1ed30b948dd49e6ed68106d07d2f8b8c9a6072cef7accb3ed94bf19b1aac69b2f03cc586009f5ffe8f1be
7
+ data.tar.gz: b24b15228ee313ee8bce26f111305796b459563030c9a4494fc1181a91069641d3084916c747271e495645f67640b873a582b190ff9e45db509fda08b3c483c3
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .DS_Store
6
- .rvmrc
7
- .rspec
8
6
  vendor
7
+ .yardoc
8
+ doc
9
+ coverage
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ script: rake test
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.0
7
+ - ruby-head
8
+ - jruby-9.0.0.0
9
+ - jruby-head
10
+ - rbx-2.5.8
@@ -1,3 +1,21 @@
1
+ === 1.0.0 / 2015-08-25
2
+
3
+ * 1 major enhancement
4
+
5
+ * Incompatible with older versions of Film Buff!
6
+ * Now requires Ruby 2.0.0 or newer because of the use of keyword arguments.
7
+ * Film Buff is no longer a module, but a class. Use it by creating an
8
+ instance with `imdb = FilmBuff.new`
9
+ * `find_by_id` is now called `look_up_id`
10
+ * `find_by_title` is now called `search_for_title`
11
+ * `search_for_title` now returns an array with results.
12
+
13
+ * 1 minor enhancement
14
+
15
+ * http.rb has replaced HTTParty
16
+ * Implemented YARD documentation. It can be found at
17
+ http://rubydoc.info/gems/filmbuff/frames
18
+
1
19
  === 0.1.6 / 2012-07-24
2
20
 
3
21
  * 1 minor enhancement
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-minitest'
8
+ end
@@ -0,0 +1,6 @@
1
+ guard :minitest do
2
+ # with Minitest::Unit
3
+ watch(%r{^test/(.*)\/?test_(.*)\.rb})
4
+ watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
5
+ watch(%r{^test/test_helper\.rb}) { 'test' }
6
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Kristoffer Sachse
1
+ Copyright (c) 2015 Kristoffer Sachse
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,26 +1,35 @@
1
1
  # Film Buff - A Ruby wrapper for IMDb's JSON API
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/filmbuff.svg)](https://rubygems.org/gems/filmbuff)
4
+ [![Build Status](https://img.shields.io/travis/sachse/filmbuff.svg)](https://travis-ci.org/sachse/filmbuff)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/sachse/filmbuff.svg)](https://gemnasium.com/sachse/filmbuff)
6
+ [![Coverage Status](https://img.shields.io/coveralls/sachse/filmbuff/master.svg)](https://coveralls.io/r/sachse/filmbuff)
7
+ [![Inline docs](https://inch-ci.org/github/sachse/filmbuff.svg?branch=master)](https://inch-ci.org/github/sachse/filmbuff/)
8
+
3
9
  ## Description
4
10
 
5
11
  Film Buff provides a Ruby wrapper for IMDb's JSON API, which is the fastest and easiest way to get information from IMDb.
6
12
 
7
- ## Installation
13
+ Film Buff supports IMDb's different locales, so information can be retrieved in different languages. See [Locales](#locales) for more information.
8
14
 
9
- ### RubyGems
15
+ ## Usage
10
16
 
11
- You can install the latest Film Buff gem using RubyGems
17
+ Film Buff 1.0.x provides two ways to return information on a movie or TV show. First, set up an IMDb instance:
12
18
 
13
- gem install filmbuff
19
+ require 'filmbuff'
20
+ imdb = FilmBuff.new
14
21
 
15
- ### GitHub
22
+ ### look_up_id
16
23
 
17
- Alternatively you can check out the latest code directly from Github
24
+ If you know the movie or TV show's IMDb ID you can return an object with the IMDb information:
18
25
 
19
- git clone http://github.com/sachse/filmbuff.git
26
+ movie = imdb.look_up_id('tt0032138')
20
27
 
21
- ## Usage
28
+ movie.title => "The Wizard of Oz"
29
+ movie.rating => 8.2
30
+ movie.genres => ["Adventure", Family", "Fantasy", "Musical"]
22
31
 
23
- Accessible title information is:
32
+ Accessible information for an object returned by `look_up_id` is:
24
33
 
25
34
  - Title
26
35
  - Tagline
@@ -33,37 +42,100 @@ Accessible title information is:
33
42
  - Release date
34
43
  - IMDb ID
35
44
 
36
- ### Examples
45
+ ### search_for_title
37
46
 
38
- Film Buff 0.1.x provides two easy ways to return an object with information on a movie or TV show. First, set up an IMDb instance:
47
+ You can also search for a movie or TV show by its title. This will return an array with results from IMDb's search feature:
39
48
 
40
- require 'filmbuff'
41
- imdb = FilmBuff::IMDb.new
49
+ results = imdb.search_for_title('The Wizard of Oz')
42
50
 
43
- You can then find a movie by its title. This will return the first result from IMDb's search feature:
51
+ results => [
52
+ {
53
+ :type => "title_popular",
54
+ :imdb_id => "tt0032138",
55
+ :title => "The Wizard of Oz",
56
+ :release_year => "1939"
57
+ },
44
58
 
45
- movie = imdb.find_by_title("The Wizard of Oz")
46
-
47
- movie.title => "The Wizard of Oz"
48
- movie.rating => 8.3
49
- movie.genres => ["Adventure", "Comedy", "Family", "Fantasy", "Musical"]
59
+ {
60
+ :type => "title_exact",
61
+ :imdb_id => "tt0016544",
62
+ :title => "The Wizard of Oz",
63
+ :release_year => "1925"
64
+ },
50
65
 
51
- If you know the movie's IMDb ID you can get the information as well:
66
+ {
67
+ :type=>"title_exact",
68
+ :imdb_id=>"tt0001463",
69
+ :title=>"The Wonderful Wizard of Oz",
70
+ :release_year=>"1910"
71
+ },
52
72
 
53
- movie = imdb.find_by_id("tt0032138")
54
-
55
- movie.title => "The Wizard of Oz"
56
- movie.rating => 8.3
57
- movie.genres => ["Adventure", "Comedy", "Family", "Fantasy", "Musical"]
73
+ etc.
74
+
75
+ ]
76
+
77
+ ### Configuration
78
+
79
+ When initializing a new `FilmBuff` instance keyword arguments can passed to change default behaviours:
80
+
81
+ - SSL is used by default when communicating with IMDb but it can be turned off by setting `ssl` to false.
82
+ - Locale defaults to `en_US` but this behaviour can be changed by passing `locale` with a different value. Locale can also be changed as necessary during runtime. See [Locales](#locales) for more information.
83
+
84
+ `search_for_title` also takes keyword arguments that can be used to change the default behaviours on a per search basis.
85
+
86
+ - `limit` limits the amount of results returned.
87
+ - `types` decides the types of titles IMDb will search. Valid settings are:
88
+ - title_popular
89
+ - title_exact
90
+ - title_approx
91
+ - title_substring
58
92
 
59
- To retrieve information in a different language, set the instance variable locale to your wanted locale:
93
+ #### Examples
60
94
 
61
- imdb.locale = "de_DE"
62
- movie = imdb.find_by_id("tt0032138")
63
-
64
- movie.title => "Das zauberhafte Land"
65
- movie.rating => 8.3
66
- movie.genres => ["Abenteuer", "Komödie", "Familie", "Fantasy", "Musical"]
95
+ Return only 2 results:
96
+
97
+ results = imdb.search_for_title('The Wizard of Oz', limit: 2)
98
+
99
+ results => [
100
+ {
101
+ :type => "title_popular",
102
+ :imdb_id => "tt0032138",
103
+ :title => "The Wizard of Oz",
104
+ :release_year => "1939"
105
+ },
106
+
107
+ {
108
+ :type => "title_exact",
109
+ :imdb_id => "tt0016544",
110
+ :title => "The Wizard of Oz",
111
+ :release_year => "1925"
112
+ }
113
+ ]
114
+
115
+
116
+ Only return popular results related to the title provided:
117
+
118
+ result = imdb.search_for_title('The Wizard of Oz', types: %w(title_popular))
119
+
120
+ result => [
121
+ {
122
+ :type => "title_popular",
123
+ :imdb_id => "tt0032138",
124
+ :title => "The Wizard of Oz",
125
+ :release_year => "1939"
126
+ }
127
+ ]
128
+
129
+ #### Locales
130
+
131
+ To retrieve information in a different language, either pass locale as as keyword argument when setting up an instance of `imdb` or set the instance variable `locale` to your wanted locale once the instance has already been created:
132
+
133
+ imdb.locale = 'fr_FR'
134
+ movie = imdb.look_up_id('tt0032138')
135
+
136
+ movie.title => "Le magicien d'Oz"
137
+ movie.rating => 8.2
138
+ movie.genres => ["Aventure", "Famille", "Fantasy", "Musical"]
67
139
 
68
140
  Supported locales are
69
141
 
@@ -74,14 +146,20 @@ Supported locales are
74
146
  - it_IT (Italian)
75
147
  - pt_PT (Portuguese)
76
148
 
149
+ ## Links
150
+
151
+ - [Public git repository](https://github.com/sachse/filmbuff)
152
+ - [Online documentation](http://rubydoc.info/gems/filmbuff/frames)
153
+ - [Issue tracker](https://github.com/sachse/filmbuff/issues)
154
+ - [Film Buff on RubyGems](https://rubygems.org/gems/filmbuff)
155
+
77
156
  ## Authors
78
157
 
79
- * [Kristoffer Sachse](https://github.com/sachse)
158
+ - [Kristoffer Sachse](https://github.com/sachse)
80
159
 
81
160
  ## Contribute
82
161
 
83
- Fork the project, implement your changes in it's own branch, and send
84
- a pull request to me. I'll gladly consider any help or ideas.
162
+ You can contribute either with code by forking the project, implementing your changes in its own branch, and sending a pull request, or you can report issues and ideas for changes [on the issues page](https://github.com/sachse/filmbuff/issues).
85
163
 
86
164
  ### Contributors
87
- - Jon Maddox (https://github.com/maddox) inspired the 0.1.0 rewrite through the imdb_party gem.
165
+ - [Jon Maddox](https://github.com/maddox) inspired the 0.1.0 rewrite through his imdb_party gem.
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :test
5
+
6
+ require 'rake/testtask'
7
+ Rake::TestTask.new do |t|
8
+ t.libs = ['test', 'fixtures']
9
+ t.test_files = ['test/test_filmbuff.rb',
10
+ 'test/filmbuff/test_filmbuff_title.rb'
11
+ ]
12
+ end
@@ -1,24 +1,31 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "filmbuff/version"
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'filmbuff/version'
4
3
 
5
4
  Gem::Specification.new do |s|
6
- s.name = "filmbuff"
7
- s.version = Filmbuff::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Kristoffer Sachse"]
10
- s.email = ["kristoffer@sachse.nu"]
11
- s.homepage = "https://github.com/sachse/filmbuff"
12
- s.summary = %q{A Ruby wrapper for IMDb's JSON API}
13
- s.description = %q{Film Buff provides a Ruby wrapper for IMDb's JSON API, which is the fastest and easiest way to get information from IMDb.}
5
+ s.name = 'filmbuff'
6
+ s.version = FilmBuff::VERSION
7
+ s.authors = ['Kristoffer Sachse']
8
+ s.email = ['hello@kristoffer.is']
9
+ s.homepage = 'https://github.com/sachse/filmbuff'
10
+ s.summary = 'A Ruby wrapper for IMDb\'s JSON API'
11
+ s.description = 'Film Buff provides a Ruby wrapper for IMDb\'s JSON API, ' <<
12
+ 'which is the fastest and easiest way to get information ' <<
13
+ 'from IMDb.'
14
+ s.license = 'MIT'
14
15
 
15
- s.rubyforge_project = "filmbuff"
16
+ s.required_ruby_version = '>= 2.0.0'
16
17
 
17
- s.add_dependency("httparty", "~> 0.8.3")
18
- s.add_dependency("httparty-icebox", "~> 0.0.4")
19
- s.add_development_dependency("rspec", ">= 2.5.0")
18
+ s.add_dependency('http', '~> 0.9.3')
19
+
20
+ s.add_development_dependency('minitest', '>= 1.4.0')
21
+ s.add_development_dependency('vcr', '>= 2.4')
22
+ s.add_development_dependency('webmock')
23
+ s.add_development_dependency('yard', '>= 0.8.5.2')
24
+ s.add_development_dependency('kramdown')
25
+ s.add_development_dependency('rake')
26
+ s.add_development_dependency('coveralls')
20
27
 
21
28
  s.files = `git ls-files`.split("\n")
22
- s.test_files = `git ls-files -- {spec}/*`.split("\n")
23
- s.require_paths = ["lib"]
29
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
30
+ s.require_paths = ['lib']
24
31
  end
@@ -1,6 +1,109 @@
1
- require 'httparty'
2
- require 'httparty-icebox'
1
+ require 'filmbuff/title'
3
2
 
4
- dir = File.expand_path(File.dirname(__FILE__))
5
- require File.join(dir, 'filmbuff', 'imdb')
6
- require File.join(dir, 'filmbuff', 'title')
3
+ require 'http'
4
+ require 'json'
5
+
6
+ # Interacts with IMDb and is used to look up titles
7
+ class FilmBuff
8
+ class NotFound < StandardError; end
9
+
10
+ # @return [String] The locale currently used by the IMDb instance
11
+ attr_accessor :locale
12
+
13
+ # Create a new FilmBuff instance
14
+ #
15
+ # @param [String] locale
16
+ # The locale to search with. The FilmBuff instance will also return
17
+ # results in the language matching the given locale. Defaults to `en_US`
18
+ #
19
+ # @param [Boolean] ssl
20
+ # Whether or not to use SSL when searching by IMDb ID (IMDb does not
21
+ # currently support SSL when searching by title). Defaults to `true`
22
+ def initialize(locale = 'en_US', ssl: true)
23
+ @locale = locale
24
+ @protocol = ssl ? 'https' : 'http'
25
+ end
26
+
27
+ private
28
+
29
+ def build_hash(type, value)
30
+ {
31
+ type: type,
32
+ imdb_id: value['id'],
33
+ title: value['title'],
34
+ release_year: value['description'][/\A\d{4}/]
35
+ }
36
+ end
37
+
38
+ public
39
+
40
+ # Looks up the title with the IMDb ID imdb_id and returns a
41
+ # FilmBuff::Title object with information on that title
42
+ #
43
+ # @param [String] imdb_id
44
+ # The IMDb ID for the title to look up
45
+ #
46
+ # @return [Title]
47
+ # The FilmBuff::Title object containing information on the title
48
+ #
49
+ # @example Basic usage
50
+ # movie = imdb_instance.look_up_id('tt0032138')
51
+ def look_up_id(imdb_id)
52
+ response = HTTP.get("#{@protocol}://app.imdb.com/title/maindetails", params: {
53
+ tconst: imdb_id, locale: @locale
54
+ })
55
+
56
+ if response.status != 200
57
+ fail NotFound
58
+ else
59
+ Title.new(response.parse['data'])
60
+ end
61
+ end
62
+
63
+ # Searches IMDb for the title provided and returns an array with results
64
+ #
65
+ # @param [String] title The title to search for
66
+ #
67
+ # @param [Integer] limit The maximum number of results to return
68
+ #
69
+ # @param [Array] types The types of matches to search for.
70
+ # These types will be searched in the provided order. Can be
71
+ # `title_popular`, `title_exact`, `title_approx`, and `title_substring`
72
+ #
73
+ # @return [Array<Hash>] An array of hashes, each representing a search result
74
+ #
75
+ # @example Basic usage
76
+ # movie = imdb_instance.search_for_title('The Wizard of Oz')
77
+ #
78
+ # @example Return only 2 results
79
+ # movie = imdb_instance.search_for_title('The Wizard of Oz', limit: 2)
80
+ #
81
+ # @example Only return results containing the exact title provided
82
+ # movie = imdb_instance.search_for_title('The Wizard of Oz',
83
+ # types: %w(title_exact))
84
+ def search_for_title(title, limit: nil, types: %w(title_popular
85
+ title_exact
86
+ title_approx
87
+ title_substring))
88
+ response = JSON.parse(HTTP.get('http://www.imdb.com/xml/find', params: {
89
+ q: title,
90
+ json: '1'
91
+ }).to_s)
92
+
93
+ output = []
94
+ results = response.select { |type| types.include? type }
95
+
96
+ results.each_key do |type|
97
+ response[type].each do |hash|
98
+ break unless output.size < limit if limit
99
+ next unless hash['id'] && hash['title'] && hash['description']
100
+
101
+ output << build_hash(type, hash)
102
+ end
103
+ end
104
+
105
+ fail NotFound if output.empty?
106
+
107
+ output
108
+ end
109
+ end
@@ -1,20 +1,63 @@
1
- module FilmBuff
1
+ require 'date'
2
+
3
+ class FilmBuff
4
+ # Represents a single title from IMDb and contains all available data on it
2
5
  class Title
3
- attr_reader :imdb_id, :title, :tagline, :plot, :runtime, :rating, :votes,
4
- :poster_url, :genres, :release_date
5
-
6
- def initialize(options = {})
7
- @imdb_id = options["tconst"]
8
- @title = options["title"]
9
- @tagline = options["tagline"]
10
- @plot = options["plot"]["outline"] if options["plot"]
11
- @runtime = options["runtime"]["time"] if options["runtime"]
12
- @rating = options["rating"]
13
- @votes = options["num_votes"]
14
- @poster_url = options["image"]["url"] if options["image"]
15
- @genres = options["genres"] || []
16
- @release_date = Date.strptime(options["release_date"]["normal"]) if
17
- options["release_date"]
6
+ # @return [String] The IMDb ID of Title
7
+ attr_reader :imdb_id
8
+
9
+ # @return [String] The title of Title
10
+ attr_reader :title
11
+
12
+ # @return [String] The tagline of Title
13
+ attr_reader :tagline
14
+
15
+ # @return [String] The plot summary of Title
16
+ attr_reader :plot
17
+
18
+ # @return [Integer] The runtime of Title in seconds
19
+ attr_reader :runtime
20
+
21
+ # @return [Float] The IMDb rating of Title
22
+ attr_reader :rating
23
+
24
+ # @return [Integer] The amount of votes that have been used to determine
25
+ # the rating of Title
26
+ attr_reader :votes
27
+
28
+ # @return [String] The URL for the poster of Title
29
+ attr_reader :poster_url
30
+
31
+ # @return [Array<String>] The genres of Title
32
+ attr_reader :genres
33
+
34
+ # @return [Date, String] The release date of Title. Returns a Date when
35
+ # possible, otherwise a String
36
+ attr_reader :release_date
37
+
38
+ # Create a new Title instance from an IMDb hash
39
+ #
40
+ # @param [Hash] imdb_hash
41
+ # The hash with IMDb information to create a Title instance from
42
+ def initialize(imdb_hash)
43
+ @imdb_id = imdb_hash['tconst']
44
+ @title = imdb_hash['title']
45
+ @tagline = imdb_hash['tagline'] if imdb_hash['tagline']
46
+ @plot = imdb_hash['plot']['outline'] if imdb_hash['plot']
47
+ @runtime = imdb_hash['runtime']['time'] if imdb_hash['runtime']
48
+ @rating = imdb_hash['rating']
49
+ @votes = imdb_hash['num_votes']
50
+ @poster_url = imdb_hash['image']['url'] if imdb_hash['image']
51
+ @genres = imdb_hash['genres'] || []
52
+
53
+ if imdb_hash['release_date']
54
+ begin
55
+ @release_date = Date.strptime(imdb_hash['release_date']['normal'],
56
+ '%Y-%m-%d')
57
+ rescue
58
+ @release_date = imdb_hash['release_date']['normal']
59
+ end
60
+ end
18
61
  end
19
62
  end
20
63
  end
@@ -1,3 +1,4 @@
1
- module Filmbuff
2
- VERSION = "0.1.6"
1
+ class FilmBuff
2
+ # Version number of the latest gem release of Film Buff
3
+ VERSION = '1.0.0'
3
4
  end
@@ -0,0 +1,65 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe FilmBuff::Title do
4
+ before do
5
+ @imdb = FilmBuff.new
6
+
7
+ VCR.use_cassette('The Wizard of Oz by ID') do
8
+ @title = @imdb.look_up_id('tt0032138')
9
+ end
10
+ end
11
+
12
+ it 'has an IMDb ID' do
13
+ assert_equal 'tt0032138', @title.imdb_id
14
+ end
15
+
16
+ it 'has a title' do
17
+ assert_equal 'The Wizard of Oz', @title.title
18
+ end
19
+
20
+ it 'has a tagline' do
21
+ assert_equal 'Mighty Miracle Show Of 1000 Delights !', @title.tagline
22
+ end
23
+
24
+ it 'has a plot' do
25
+ assert_equal 'Dorothy Gale is swept away to a magical land in ' <<
26
+ 'a tornado and embarks on a quest to see the Wizard who can help her ' <<
27
+ 'return home.', @title.plot
28
+ end
29
+
30
+ it 'has a runtime' do
31
+ assert_equal 6120, @title.runtime
32
+ end
33
+
34
+ it 'has a rating' do
35
+ assert_instance_of Float, @title.rating
36
+ end
37
+
38
+ it 'has an amount of votes' do
39
+ assert_instance_of Fixnum, @title.votes
40
+ end
41
+
42
+ it 'has a poster URL' do
43
+ assert_match %r{\Ahttp://ia.media-imdb.com/images/.*/}, @title.poster_url
44
+ end
45
+
46
+ it 'has genres' do
47
+ assert_equal %w(Adventure Family Fantasy Musical), @title.genres
48
+ end
49
+
50
+ it 'has a release date' do
51
+ assert_equal Date.strptime('1939-08-25', '%Y-%m-%d'), @title.release_date
52
+ end
53
+
54
+ describe 'when looking up titles without a specific release date' do
55
+ before do
56
+ VCR.use_cassette('Rear Window by ID') do
57
+ @title = @imdb.look_up_id('tt0047396')
58
+ end
59
+ end
60
+
61
+ it 'falls back to the IMDb provided date' do
62
+ assert_equal '1954', @title.release_date
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,179 @@
1
+ require_relative 'test_helper'
2
+
3
+ VCR.configure do |config|
4
+ config.cassette_library_dir = 'fixtures/vcr_cassettes'
5
+ config.hook_into :webmock
6
+ end
7
+
8
+ describe FilmBuff do
9
+ before do
10
+ @imdb = FilmBuff.new
11
+ end
12
+
13
+ describe '#look_up_id' do
14
+ it 'returns a Title' do
15
+ VCR.use_cassette('The Wizard of Oz by ID') do
16
+ @title = @imdb.look_up_id('tt0032138')
17
+ end
18
+
19
+ assert_instance_of FilmBuff::Title, @title
20
+ end
21
+
22
+ describe 'given a non-existent ID' do
23
+ it 'throws an exception' do
24
+ VCR.use_cassette('non-existent ID') do
25
+ assert_raises(FilmBuff::NotFound) do
26
+ @title = @imdb.look_up_id('tt9999999')
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'given locale' do
33
+ describe 'de_DE' do
34
+ before do
35
+ @imdb.locale = 'de_DE'
36
+
37
+ VCR.use_cassette('The Wizard of Oz German') do
38
+ @title = @imdb.look_up_id('tt0032138')
39
+ end
40
+ end
41
+
42
+ it 'returns German information' do
43
+ assert_equal 'Der Zauberer von Oz', @title.title
44
+ end
45
+ end
46
+
47
+ describe 'en_US' do
48
+ before do
49
+ @imdb.locale = 'en_US'
50
+
51
+ VCR.use_cassette('The Wizard of Oz by ID') do
52
+ @title = @imdb.look_up_id('tt0032138')
53
+ end
54
+ end
55
+
56
+ it 'returns English information' do
57
+ assert_equal 'The Wizard of Oz', @title.title
58
+ end
59
+ end
60
+
61
+ describe 'es_ES' do
62
+ before do
63
+ @imdb.locale = 'es_ES'
64
+
65
+ VCR.use_cassette('The Wizard of Oz Spanish') do
66
+ @title = @imdb.look_up_id('tt0032138')
67
+ end
68
+ end
69
+
70
+ it 'returns Spanish information' do
71
+ assert_equal 'El mago de Oz', @title.title
72
+ end
73
+ end
74
+
75
+ describe 'fr_FR' do
76
+ before do
77
+ @imdb.locale = 'fr_FR'
78
+
79
+ VCR.use_cassette('The Wizard of Oz French') do
80
+ @title = @imdb.look_up_id('tt0032138')
81
+ end
82
+ end
83
+
84
+ it 'returns French information' do
85
+ assert_equal 'Le magicien d\'Oz', @title.title
86
+ end
87
+ end
88
+
89
+ describe 'it_IT' do
90
+ before do
91
+ @imdb.locale = 'it_IT'
92
+
93
+ VCR.use_cassette('The Wizard of Oz Italian') do
94
+ @title = @imdb.look_up_id('tt0032138')
95
+ end
96
+ end
97
+
98
+ it 'returns Italian information' do
99
+ assert_equal 'Il mago di Oz', @title.title
100
+ end
101
+ end
102
+
103
+ describe 'pt_PT' do
104
+ before do
105
+ @imdb.locale = 'pt_PT'
106
+
107
+ VCR.use_cassette('The Wizard of Oz Portugese') do
108
+ @title = @imdb.look_up_id('tt0032138')
109
+ end
110
+ end
111
+
112
+ it 'returns Portugese information' do
113
+ assert_equal 'O Feiticeiro de Oz', @title.title
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ describe '#search_for_title' do
120
+ describe 'with default options' do
121
+ before do
122
+ VCR.use_cassette('The Wizard of Oz by title') do
123
+ @titles = @imdb.search_for_title('The Wizard of Oz')
124
+ end
125
+ end
126
+
127
+ it 'returns an array of titles' do
128
+ assert_instance_of Array, @titles
129
+ end
130
+
131
+ describe 'given a non-existent title' do
132
+ it 'throws an exception' do
133
+ VCR.use_cassette('non-existent title') do
134
+ assert_raises(FilmBuff::NotFound) do
135
+ @title = @imdb.search_for_title('123456789012345678901234567890')
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ # describe 'given a title that redirects' do
142
+ # it 'follows the redirect and returns a Title object' do
143
+ # skip 'this still needs a title to test against'
144
+
145
+ # VCR.use_cassette('Redirecting title') do
146
+ # @title = @imdb.search_for_title('')
147
+ # end
148
+
149
+ # assert_instance_of FilmBuff::Title, @title
150
+ # end
151
+ # end
152
+ end
153
+
154
+ describe 'given a limit of 3' do
155
+ before do
156
+ VCR.use_cassette('The Wizard of Oz by title') do
157
+ @titles = @imdb.search_for_title('The Wizard of Oz', limit: 3)
158
+ end
159
+ end
160
+
161
+ it 'returns 3 results' do
162
+ assert_equal 3, @titles.size
163
+ end
164
+ end
165
+
166
+ describe 'when only returning popular titles' do
167
+ before do
168
+ VCR.use_cassette('The Wizard of Oz by title') do
169
+ @title = @imdb.search_for_title('The Wizard of Oz',
170
+ types: %w(title_popular))
171
+ end
172
+ end
173
+
174
+ it 'returns the 1939 version' do
175
+ assert_equal '1939', @title.first[:release_year]
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+
4
+ if ENV['TRAVIS'] == 'true'
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ end
8
+
9
+ require 'vcr'
10
+
11
+ require_relative '../lib/filmbuff'
metadata CHANGED
@@ -1,109 +1,172 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filmbuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kristoffer Sachse
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-24 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: httparty
14
+ name: http
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 0.8.3
19
+ version: 0.9.3
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 0.8.3
26
+ version: 0.9.3
30
27
  - !ruby/object:Gem::Dependency
31
- name: httparty-icebox
28
+ name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: 0.0.4
38
- type: :runtime
33
+ version: 1.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.5.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.5.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: kramdown
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
39
105
  prerelease: false
40
106
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
107
  requirements:
43
- - - ~>
108
+ - - ">="
44
109
  - !ruby/object:Gem::Version
45
- version: 0.0.4
110
+ version: '0'
46
111
  - !ruby/object:Gem::Dependency
47
- name: rspec
112
+ name: coveralls
48
113
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
114
  requirements:
51
- - - ! '>='
115
+ - - ">="
52
116
  - !ruby/object:Gem::Version
53
- version: 2.5.0
117
+ version: '0'
54
118
  type: :development
55
119
  prerelease: false
56
120
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
121
  requirements:
59
- - - ! '>='
122
+ - - ">="
60
123
  - !ruby/object:Gem::Version
61
- version: 2.5.0
124
+ version: '0'
62
125
  description: Film Buff provides a Ruby wrapper for IMDb's JSON API, which is the fastest
63
126
  and easiest way to get information from IMDb.
64
127
  email:
65
- - kristoffer@sachse.nu
128
+ - hello@kristoffer.is
66
129
  executables: []
67
130
  extensions: []
68
131
  extra_rdoc_files: []
69
132
  files:
70
- - .gitignore
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - CHANGES
71
136
  - Gemfile
72
- - History
137
+ - Guardfile
73
138
  - LICENSE
74
139
  - README.md
75
140
  - Rakefile
76
141
  - filmbuff.gemspec
77
142
  - lib/filmbuff.rb
78
- - lib/filmbuff/imdb.rb
79
143
  - lib/filmbuff/title.rb
80
144
  - lib/filmbuff/version.rb
81
- - spec/filmbuff/imdb_spec.rb
82
- - spec/filmbuff/title_spec.rb
83
- - spec/filmbuff_spec.rb
84
- - spec/spec_helper.rb
145
+ - test/filmbuff/test_filmbuff_title.rb
146
+ - test/test_filmbuff.rb
147
+ - test/test_helper.rb
85
148
  homepage: https://github.com/sachse/filmbuff
86
- licenses: []
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
87
152
  post_install_message:
88
153
  rdoc_options: []
89
154
  require_paths:
90
155
  - lib
91
156
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
157
  requirements:
94
- - - ! '>='
158
+ - - ">="
95
159
  - !ruby/object:Gem::Version
96
- version: '0'
160
+ version: 2.0.0
97
161
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
162
  requirements:
100
- - - ! '>='
163
+ - - ">="
101
164
  - !ruby/object:Gem::Version
102
165
  version: '0'
103
166
  requirements: []
104
- rubyforge_project: filmbuff
105
- rubygems_version: 1.8.24
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.5
106
169
  signing_key:
107
- specification_version: 3
170
+ specification_version: 4
108
171
  summary: A Ruby wrapper for IMDb's JSON API
109
172
  test_files: []
@@ -1,42 +0,0 @@
1
- module FilmBuff
2
- class IMDb
3
- attr_accessor :locale
4
-
5
- include HTTParty
6
- include HTTParty::Icebox
7
- cache :store => 'memory', :timeout => 120
8
-
9
- base_uri 'app.imdb.com'
10
- format :json
11
-
12
- def initialize
13
- @locale = "en_US"
14
- end
15
-
16
- public
17
- def find_by_id(imdb_id)
18
- result = self.class.get('/title/maindetails', :query => {
19
- :tconst => imdb_id, :locale => @locale
20
- }).parsed_response
21
- Title.new(result["data"])
22
- end
23
-
24
- def find_by_title(title)
25
- result = self.class.get('http://www.imdb.com/xml/find', :query => {
26
- :q => title,
27
- :json => '1',
28
- :tt => 'on'
29
- }).parsed_response
30
-
31
- %w(title_popular title_exact title_approx title_substring).each do |key|
32
- if result[key]
33
- result[key].each do |row|
34
- next unless row['id'] && row['title'] && row['description']
35
-
36
- return self.find_by_id(row['id'])
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,27 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
-
3
- describe FilmBuff::IMDb do
4
- before(:all) do
5
- @imdb = FilmBuff::IMDb.new
6
- end
7
-
8
- describe "#find_by_id" do
9
- before(:all) do
10
- @title = @imdb.find_by_id("tt0032138")
11
- end
12
-
13
- it "returns a Title" do
14
- @title.instance_of?(FilmBuff::Title).should be_true
15
- end
16
- end
17
-
18
- describe "#find_by_title" do
19
- before(:all) do
20
- @title = @imdb.find_by_title("The Wizard of Oz")
21
- end
22
-
23
- it "returns a Title" do
24
- @title.instance_of?(FilmBuff::Title).should be_true
25
- end
26
- end
27
- end
@@ -1,114 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
3
-
4
- describe FilmBuff::Title do
5
- context "given no locale" do
6
- before(:all) do
7
- @imdb = FilmBuff::IMDb.new
8
- @title = @imdb.find_by_id("tt0032138")
9
- end
10
-
11
- it "has an IMDb ID" do
12
- @title.imdb_id.should == "tt0032138"
13
- end
14
-
15
- it "has a title" do
16
- @title.title.should == "The Wizard of Oz"
17
- end
18
-
19
- it "has a tagline" do
20
- @title.tagline.should == "Mighty Miracle Show Of 1000 Delights !"
21
- end
22
-
23
- it "has a plot" do
24
- @title.plot.should == "Dorothy Gale is swept away to a magical land in" <<
25
- " a tornado and embarks on a quest to see the Wizard who can help her " <<
26
- "return home."
27
- end
28
-
29
- it "has a runtime" do
30
- @title.runtime.should == 6060
31
- end
32
-
33
- it "has a rating" do
34
- @title.rating.should be_a(Float)
35
- end
36
-
37
- it "has an amount of votes" do
38
- @title.votes.should be_a(Integer)
39
- end
40
-
41
- it "has a poster URL" do
42
- @title.poster_url.should match /http:\/\/ia.media-imdb.com\/images\/.*/
43
- end
44
-
45
- it "has genres" do
46
- @title.genres.should == %w[ Adventure Family Fantasy Musical ]
47
- end
48
-
49
- it "has a release date" do
50
- @title.release_date.should == Date.parse("1939-08-25")
51
- end
52
- end
53
-
54
- context "given locale" do
55
- before(:all) do
56
- @imdb = FilmBuff::IMDb.new
57
- end
58
-
59
- context "\"de_DE\"" do
60
- before(:all) do
61
- @imdb.locale = "de_DE"
62
- @title = @imdb.find_by_id("tt0032138")
63
- end
64
-
65
- it "returns German information" do
66
- @title.title.should == "Das zauberhafte Land"
67
- end
68
- end
69
-
70
- context "\"es_ES\"" do
71
- before(:all) do
72
- @imdb.locale = "es_ES"
73
- @title = @imdb.find_by_id("tt0032138")
74
- end
75
-
76
- it "returns Spanish information" do
77
- @title.title.should == "El mago de Oz"
78
- end
79
- end
80
-
81
- context "\"fr_FR\"" do
82
- before(:all) do
83
- @imdb.locale = "fr_FR"
84
- @title = @imdb.find_by_id("tt0032138")
85
- end
86
-
87
- it "returns French information" do
88
- @title.title.should == "Le magicien d'Oz"
89
- end
90
- end
91
-
92
- context "\"it_IT\"" do
93
- before(:all) do
94
- @imdb.locale = "it_IT"
95
- @title = @imdb.find_by_id("tt0032138")
96
- end
97
-
98
- it "returns Italian information" do
99
- @title.title.should == "Il mago di Oz"
100
- end
101
- end
102
-
103
- context "\"pt_PT\"" do
104
- before(:all) do
105
- @imdb.locale = "pt_PT"
106
- @title = @imdb.find_by_id("tt0032138")
107
- end
108
-
109
- it "returns Spanish information" do
110
- @title.title.should == "O Feiticeiro de Oz"
111
- end
112
- end
113
- end
114
- end
File without changes
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'filmbuff')