omdbapi 0.1.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c26bd37809d517fee3add5282bd1c0010e28cf66
4
- data.tar.gz: a060eb969c24d18b1ea70884d8d9fa83e67be255
3
+ metadata.gz: 272ba0afa85cd815166b6a0b2d077f447d3b652e
4
+ data.tar.gz: 112b7114fc02de8a93b491c5e6cbef4f65308419
5
5
  SHA512:
6
- metadata.gz: 876544a128f6edb7170d7e141dffff71a500ae2b108ec4376cbf0108827b883cf773fcab3aad69f3cad5d1716c60420c4f7d4fb8915aa442bfc182aea4e28269
7
- data.tar.gz: db4110cbb81529cc03214376bc11039861b98016f33c6efbd1bbfd2c74588f9eb4b984fa62b7d8a38db05a72f09b503ca3146534f085f60962171a7185dd9814
6
+ metadata.gz: eb65226a4f6ce075f9ff299af4577393e20be45a363ab2cdaba50fd4ca03a05c17a0152c5e84b69212d91b9fc544f05875ef65756a98f97ba5c57d99792ca66f
7
+ data.tar.gz: fbbaad3014a8944a6ddd743e12872f1c3299563c1e004416ce16a166bbee40e37c821784321381b14c2f5a0970ed42ce97f0ae19053cc3bf361d3d37ef8aa1d4
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # omdbapi
2
2
 
3
- This gem is (will be) a simple and easy to use wrapper for the [omdbapi.com](http://omdbapi.com/) API.
3
+ [![Gem Version](https://badge.fury.io/rb/omdbapi.png)](http://badge.fury.io/rb/omdbapi)
4
+
5
+ This gem is a simple and easy to use wrapper for the [omdbapi.com](http://omdbapi.com/) API. This API allows you to pull almost any type of information about a show or movie, and uses information from IMDb.
6
+
7
+ ## Documentation
8
+
9
+ The complete documentation for the gem can be viewed at [rdoc.info/gems/omdbapi/frames](http://rdoc.info/gems/omdbapi/frames).
4
10
 
5
11
  ## Installation
6
12
 
@@ -53,12 +59,39 @@ This function will return a Hash with the following information about the title:
53
59
  :actors, :plot, :poster, :imdb_rating, :imdb_votes, :imdb_id, :type
54
60
  ```
55
61
 
62
+ You can also pass in the optional parameters for year or plot. Plot defaults to 'short', so the only other option is 'full'.
63
+
64
+ ```ruby
65
+ OMDB.title('True Grit')
66
+ # => {:title=>"True Grit", :year=>"2010", :rated=>"PG-13"...
67
+ OMDB.title('True Grit', year: '1969')
68
+ # => {:title=>"True Grit", :year=>"1969", :rated=>"G"...
69
+
70
+ # Get the title with the full plot
71
+ OMDB.title('Breaking Bad', plot: 'full')
72
+
73
+ # Get the original Italian Job with the full plot
74
+ OMDB.title('The Italian Job', year: '1969', plot: 'full')
75
+ ```
76
+
77
+ ### IMDb ID
78
+
79
+ You can find a title by it's IMDb ID using the id method:
80
+
81
+ ```ruby
82
+ lost = OMDB.id('tt0411008')
83
+ # => {:title=>"Lost", :year=>"2004", :rated=>"TV-14", :released=>"22 Sep 2004", :runtime=>"42 min", :genre=>"Adventure, Drama, Fantasy, Mystery, Sci-Fi, Thriller", :director=>"N/A", :writer=>"J.J. Abrams, Jeffrey Lieber", :actors=>"Matthew Fox, Jorge Garcia, Evangeline Lilly, Naveen Andrews", :plot=>"The survivors of a plane crash are forced to live with each other on a remote island, a dangerous new world that poses unique threats of its own.", :poster=>"http://ia.media-imdb.com/images/M/MV5BMjA3NzMyMzU1MV5BMl5BanBnXkFtZTcwNjc1ODUwMg@@._V1_SX300.jpg", :imdb_rating=>"8.3", :imdb_votes=>"160,182", :imdb_id=>"tt0411008", :type=>"series", :response=>"True"}
84
+ lost.released # => "22 Sep 2004"
85
+ lost.imdb_rating # => "8.3"
86
+ # etc...
87
+ ```
88
+
56
89
  ### Search
57
90
 
58
- You can find a title by using the find method:
91
+ You can find a title by using the search method:
59
92
 
60
93
  ```ruby
61
- results = OMDB.find('Star Wars')
94
+ results = OMDB.search('Star Wars')
62
95
  # => [{:title=>"Star Wars", :year=>"1977", :imdb_id=>"tt0076759", :type=>"movie"}, {:title=>"Star Wars: Episode V - The Empire Strikes Back", :year=>"1980", :imdb_id=>"tt0080684", :type=>"movie"}, {:title=>"Star Wars: Episode VI - Return of the Jedi", :year=>"1983", :imdb_id=>"tt0086190", :type=>"movie"}, {:title=>"Star Wars: Episode I - The Phantom Menace", :year=>"1999", :imdb_id=>"tt0120915", :type=>"movie"}, {:title=>"Star Wars: Episode III - Revenge of the Sith", :year=>"2005", :imdb_id=>"tt0121766", :type=>"movie"}, {:title=>"Star Wars: Episode II - Attack of the Clones", :year=>"2002", :imdb_id=>"tt0121765", :type=>"movie"}, {:title=>"Star Wars: The Clone Wars", :year=>"2008", :imdb_id=>"tt1185834", :type=>"movie"}, {:title=>"Star Wars: Clone Wars", :year=>"2003", :imdb_id=>"tt0361243", :type=>"series"}, {:title=>"Star Wars: The Clone Wars", :year=>"2008", :imdb_id=>"tt0458290", :type=>"series"}, {:title=>"The Star Wars Holiday Special", :year=>"1978", :imdb_id=>"tt0193524", :type=>"movie"}]
63
96
  results.each { |r| puts r.title }
64
97
  # etc...
@@ -70,22 +103,23 @@ This method returns an Array of search results. Each search result is a Hash wit
70
103
  :title, :year, :imdb_id, :type
71
104
  ```
72
105
 
73
- ### Find by IMDb ID
106
+ If there is only a single search result, the title will be returned as a Hash with the full information, instead of the Array of shortened search results.
74
107
 
75
- You can find a title by it's IMDb id using the id method:
76
-
77
- ```ruby
78
- lost = OMDB.id('tt0411008')
79
- # => {:title=>"Lost", :year=>"2004", :rated=>"TV-14", :released=>"22 Sep 2004", :runtime=>"42 min", :genre=>"Adventure, Drama, Fantasy, Mystery, Sci-Fi, Thriller", :director=>"N/A", :writer=>"J.J. Abrams, Jeffrey Lieber", :actors=>"Matthew Fox, Jorge Garcia, Evangeline Lilly, Naveen Andrews", :plot=>"The survivors of a plane crash are forced to live with each other on a remote island, a dangerous new world that poses unique threats of its own.", :poster=>"http://ia.media-imdb.com/images/M/MV5BMjA3NzMyMzU1MV5BMl5BanBnXkFtZTcwNjc1ODUwMg@@._V1_SX300.jpg", :imdb_rating=>"8.3", :imdb_votes=>"160,182", :imdb_id=>"tt0411008", :type=>"series", :response=>"True"}
80
- lost.released # => "22 Sep 2004"
81
- lost.imdb_rating # => "8.3"
82
- # etc...
83
- ```
84
108
 
85
109
  This method will return a Hash of the title's properties, exactly as the title method.
86
110
 
111
+ ## Running the Tests
112
+
113
+ The test suite is written using RSpec, and can be run by issuing the following command from the root of the repository:
114
+
115
+ ```bash
116
+ $ rspec spec
117
+ ```
118
+
87
119
  ## Contributing
88
120
 
121
+ Please feel free to contribute to the project by following the options below.
122
+
89
123
  1. Fork it
90
124
  2. Create your feature branch (`git checkout -b my-new-feature`)
91
125
  3. Commit your changes (`git commit -am 'Add some feature'`)
@@ -11,11 +11,13 @@ module OMDB
11
11
  # Retrieves a movie or show based on its title.
12
12
  #
13
13
  # @param title [String] The title of the movie or show.
14
+ # @param options [Hash] Options for the title, plot or year.
14
15
  # @return [Hash]
15
16
  # @example
16
17
  # OMDB.title('Game of Thrones')
17
- def title(title, year=nil)
18
- get '/', { t: title }
18
+ def title(title, options={})
19
+ params = build_params(title, options)
20
+ get '/', params
19
21
  end
20
22
 
21
23
 
@@ -29,17 +31,25 @@ module OMDB
29
31
  return get '/', { i: imdb_id }
30
32
  end
31
33
 
32
- # Find a movie by its title.
34
+ # Search for a movie by its title.
33
35
  #
34
- # @param title [String] The title of the movie or show to find.
36
+ # @param title [String] The title of the movie or show to search for.
35
37
  # @return [Array, Hash]
36
38
  # @example
37
39
  # OMDB.find('Star Wars')
38
- def find(title)
40
+ def search(title)
39
41
  results = get '/', { s: title }
40
- results[:search] ? results[:search] : results
42
+ if results[:search]
43
+ # Return the title if there is only one result, otherwise return the seach results
44
+ search = results.search
45
+ search.size == 1 ? title(search[0].title) : search
46
+ else
47
+ results
48
+ end
41
49
  end
42
50
 
51
+ alias_method :find, :search
52
+
43
53
  private
44
54
 
45
55
  # Performs a method on all hash keys.
@@ -57,6 +67,18 @@ module OMDB
57
67
  end
58
68
  end
59
69
 
70
+ # Build parameters for a request.
71
+ #
72
+ # @param title [String] The title of the show.
73
+ # @param options [Hash] The optional parameters.
74
+ # @return [Hash]
75
+ def build_params(title, options)
76
+ params = { t: title }
77
+ params[:plot] = options[:plot] if options[:plot]
78
+ params[:y] = options[:year] if options[:year]
79
+ params
80
+ end
81
+
60
82
  # Performs a get request.
61
83
  #
62
84
  # @param url [String] The url to perform the get request to.
@@ -2,5 +2,5 @@ module OMDB
2
2
  # OMDB current version
3
3
  #
4
4
  # @return [String]
5
- VERSION = "0.1.2"
5
+ VERSION = "0.2.0"
6
6
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["caseyscarborough@gmail.com"]
11
11
  spec.description = '[In Progress] A wrapper for the omdbapi.com movie API.'
12
12
  spec.summary = 'This gem provides easy access for information retrieval from omdbapi.com.'
13
- spec.homepage = "https://github.com/caseyscarborough/omdbapi"
13
+ spec.homepage = "http://caseyscarborough.github.io/omdbapi"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -25,6 +25,24 @@ describe OMDB::Client do
25
25
  end
26
26
  end
27
27
 
28
+ describe 'with the year parameter' do
29
+ let(:title1) { OMDB.title('True Grit') }
30
+ let(:title2) { OMDB.title('True Grit', year: '1969') }
31
+
32
+ it 'should not be the same title' do
33
+ title1.should_not eq(title2)
34
+ end
35
+ end
36
+
37
+ describe 'with the plot parameter' do
38
+ let(:title1) { OMDB.title('Game of Thrones') }
39
+ let(:title2) { OMDB.title('Game of Thrones', plot: 'full') }
40
+
41
+ it 'should have different plots' do
42
+ title1.plot.should_not eq(title2.plot)
43
+ end
44
+ end
45
+
28
46
  describe 'with a movie that doesn''t exist' do
29
47
  let(:title) { OMDB.title('lsdfoweirjrpwef323423dsfkip') }
30
48
 
@@ -73,10 +91,10 @@ describe OMDB::Client do
73
91
  end
74
92
  end
75
93
 
76
- describe 'find' do
94
+ describe 'search' do
77
95
 
78
96
  describe 'with search results' do
79
- let(:results) { OMDB.find('Star Wars') }
97
+ let(:results) { OMDB.search('Star Wars') }
80
98
 
81
99
  it 'should return an array' do
82
100
  results.should be_instance_of Array
@@ -87,8 +105,20 @@ describe OMDB::Client do
87
105
  end
88
106
  end
89
107
 
108
+ describe 'with a single search result' do
109
+ let(:result) { OMDB.search('The Star Wars Holiday Special') }
110
+
111
+ it 'should return a hash of the title' do
112
+ result.should be_instance_of Hash
113
+ end
114
+
115
+ it 'should have a title' do
116
+ result.title.should eq('The Star Wars Holiday Special')
117
+ end
118
+ end
119
+
90
120
  describe 'with no search results' do
91
- let(:results) { OMDB.find('lsdfoweirjrpwef323423dsfkip') }
121
+ let(:results) { OMDB.search('lsdfoweirjrpwef323423dsfkip') }
92
122
 
93
123
  it 'should return a hash' do
94
124
  results.should be_instance_of Hash
@@ -102,6 +132,12 @@ describe OMDB::Client do
102
132
  results.error.should be_instance_of String
103
133
  end
104
134
  end
135
+
136
+ describe 'should be aliased to find' do
137
+ it 'should be the same method' do
138
+ OMDB.search('Star Wars').should eq(OMDB.find('Star Wars'))
139
+ end
140
+ end
105
141
  end
106
142
 
107
143
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omdbapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey Scarborough
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-12 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,7 +87,7 @@ files:
87
87
  - spec/omdbapi/client_spec.rb
88
88
  - spec/omdbapi/default_spec.rb
89
89
  - spec/spec_helper.rb
90
- homepage: https://github.com/caseyscarborough/omdbapi
90
+ homepage: http://caseyscarborough.github.io/omdbapi
91
91
  licenses:
92
92
  - MIT
93
93
  metadata: {}
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.0.6
110
+ rubygems_version: 2.0.5
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: This gem provides easy access for information retrieval from omdbapi.com.