omdbapi 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f96546e47313f62cae59711b67ad3c44e97a627e
4
- data.tar.gz: a6d69f0a189d0a57c8c9e46334bbb23fdaa973bd
3
+ metadata.gz: 40dd8088ca9737b6860e5fc19e7107459be09dc3
4
+ data.tar.gz: 4d45a4457544555a7105bed0a11c8b0e12853f9d
5
5
  SHA512:
6
- metadata.gz: c9d2645b01291cf785e4e9e810abaa60a09c48c68ec932edbe613564dc49fe4e77bbe66dd9e04cf59f7113288298ca5e7d8d6eca0ac3da35a299783f151cc2ab
7
- data.tar.gz: 599596e06bfe191982051c8a423bb242ef9f72934a225deaf834d4ba0d5bbfe475c8c0a16dcf5e0adf8d8cf3b6bf048b18f6a4aee2b8e8d12366fcc5dc70039e
6
+ metadata.gz: 3daf4e22024a8d57e23da703dde0a28f7157c788541ed66bc844a5bcc2cc62e10bdd40d0676f7e870d0a91a88c5039d53b0415b84a33a56bb3039b835f562e8a
7
+ data.tar.gz: d67b7e3a2e8bcbfb401e49b981e9c0cbb0b95c71a7a148709963aa55f6cd912af318fc9ba7272f10520284cf997d817e81f905f880724d35f3099bbb120afd37
@@ -16,27 +16,31 @@ module OMDB
16
16
  # @option options [String] :plot 'short' (default), 'full'
17
17
  # @option options [Integer] :season The season to retrieve.
18
18
  # @option options [Integer] :episode The episode to retrieve. Requires the season parameter.
19
+ # @option options [Boolean] :tomatoes Include Rotten Tomatoes ratings.
19
20
  # @return [Hash]
20
21
  # @example
21
22
  # OMDB.title('Game of Thrones')
22
- def title(title, options={})
23
+ def title(title, options = {})
23
24
  params = { t: title }
24
25
  params[:y] = options[:year] if options[:year]
25
26
  params[:plot] = options[:plot] if options[:plot]
26
27
  params[:season] = options[:season] if options[:season]
27
28
  params[:episode] = options[:episode] if options[:episode]
29
+ params[:tomatoes] = options[:tomatoes] if options[:tomatoes]
28
30
  get '/', params
29
31
  end
30
32
 
31
-
32
33
  # Retrieves a movie or show based on its IMDb ID.
33
34
  #
34
35
  # @param imdb_id [String] The IMDb ID of the movie or show.
36
+ # @option options [Boolean] :tomatoes Include Rotten Tomatoes ratings.
35
37
  # @return [Hash]
36
38
  # @example
37
39
  # OMDB.id('tt0944947')
38
- def id(imdb_id)
39
- get '/', { i: imdb_id }
40
+ def id(imdb_id, options = {})
41
+ params = { i: imdb_id }
42
+ params[:tomatoes] = options[:tomatoes] if options[:tomatoes]
43
+ get '/', params
40
44
  end
41
45
 
42
46
  # Search for a movie by its title.
@@ -82,7 +86,6 @@ module OMDB
82
86
  # @return [Hash]
83
87
  def build_params(title, options)
84
88
  params = { t: title }
85
-
86
89
  params[:y] = options[:year] if options[:year]
87
90
  params
88
91
  end
@@ -99,4 +102,4 @@ module OMDB
99
102
  convert_hash_keys(request.parsed_response)
100
103
  end
101
104
  end
102
- end
105
+ end
@@ -2,5 +2,5 @@ module OMDB
2
2
  # OMDB current version
3
3
  #
4
4
  # @return [String]
5
- VERSION = "0.2.1"
5
+ VERSION = "0.3.0"
6
6
  end
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_dependency 'httparty', '>= 0.13'
22
+ spec.add_development_dependency "rake", "~> 11.1"
23
+ spec.add_development_dependency "rspec", "~> 3.4"
24
+ spec.add_development_dependency "vcr", "~> 3.0"
25
+ spec.add_development_dependency "webmock", "~> 1.24"
26
+ spec.add_dependency 'httparty', '~> 0.13'
25
27
  end
@@ -1,172 +1,220 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OMDB::Client do
4
-
5
4
  it 'should include HTTParty' do
6
- OMDB::Client.should include(HTTParty)
5
+ expect(OMDB::Client).to include(HTTParty)
7
6
  end
8
7
 
9
8
  it 'should have the correct API endpoint' do
10
- OMDB::Client.base_uri.should eq(OMDB::Default::API_ENDPOINT)
9
+ expect(OMDB::Client.base_uri).to eq(OMDB::Default::API_ENDPOINT)
11
10
  end
12
11
 
13
12
  describe 'methods' do
14
-
15
13
  describe 'title' do
16
14
  describe 'with a movie that exists' do
17
- let(:title) { OMDB.title('Star Wars') }
15
+ before(:all) do
16
+ VCR.use_cassette('title/valid') do
17
+ @title = OMDB.title('Star Wars')
18
+ end
19
+ end
18
20
 
19
21
  it 'should return a hash of movie attributes' do
20
- title.should be_instance_of Hash
22
+ expect(@title).to be_instance_of Hash
21
23
  end
22
24
 
23
25
  it 'should contain a title' do
24
- title.title.should be_instance_of String
26
+ expect(@title.title).to be_instance_of String
25
27
  end
26
28
  end
27
29
 
28
30
  describe 'with the year parameter' do
29
- let(:title1) { OMDB.title('True Grit') }
30
- let(:title2) { OMDB.title('True Grit', year: '1969') }
31
-
32
31
  it 'should not be the same title' do
33
- title1.should_not eq(title2)
32
+ VCR.use_cassette('title/year') do
33
+ title1 = OMDB.title('True Grit')
34
+ title2 = OMDB.title('True Grit', year: '1969')
35
+ expect(title1).not_to eq(title2)
36
+ end
34
37
  end
35
38
  end
36
39
 
37
40
  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
41
  it 'should have different plots' do
42
- title1.plot.should_not eq(title2.plot)
42
+ VCR.use_cassette('title/plot') do
43
+ title1 = OMDB.title('Game of Thrones')
44
+ title2 = OMDB.title('Game of Thrones', plot: 'full')
45
+ expect(title1.plot).not_to eq(title2.plot)
46
+ end
43
47
  end
44
48
  end
45
49
 
46
50
  describe 'with the season and episode parameters' do
47
- let(:title) { OMDB.title('True Detective', episode: 1, season: 1) }
48
-
49
51
  it 'should include season and episode in the response' do
50
- title.season.should eq("1")
51
- title.episode.should eq("1")
52
+ VCR.use_cassette('title/season_and_episode') do
53
+ title = OMDB.title('True Detective', episode: 1, season: 1)
54
+ expect(title.season).to eq('1')
55
+ expect(title.episode).to eq('1')
56
+ end
52
57
  end
53
58
  end
54
59
 
55
60
  describe 'with only the season parameter, missing the episode parameter' do
56
- let(:title) { OMDB.title('True Detective', season: 1) }
57
-
58
- it 'should not include season and episode in the response' do
59
- expect { title.season }.to raise_error(NoMethodError)
60
- expect { title.episode }.to raise_error(NoMethodError)
61
+ it 'should not include episode in the response' do
62
+ VCR.use_cassette('title/season') do
63
+ title = OMDB.title('True Detective', season: 1)
64
+ expect { title.episode }.to raise_error(NoMethodError)
65
+ end
61
66
  end
62
67
  end
63
68
 
64
69
  describe 'with only the episode parameter, missing the season parameter' do
65
- let(:title) { OMDB.title('True Detective', episode: 1) }
66
-
67
70
  it 'should not include season and episode in the response' do
68
- expect { title.season }.to raise_error(NoMethodError)
69
- expect { title.episode }.to raise_error(NoMethodError)
71
+ VCR.use_cassette('title/episode') do
72
+ title = OMDB.title('True Detective', episode: 1)
73
+ expect { title.season }.to raise_error(NoMethodError)
74
+ expect { title.episode }.to raise_error(NoMethodError)
75
+ end
70
76
  end
71
77
  end
72
78
 
73
- describe 'with a movie that doesn''t exist' do
74
- let(:title) { OMDB.title('lsdfoweirjrpwef323423dsfkip') }
75
-
79
+ describe "with a movie that doesn't exist" do
80
+ before(:all) do
81
+ VCR.use_cassette('title/nonexistent') do
82
+ @title = OMDB.title('lsdfoweirjrpwef323423dsfkip')
83
+ end
84
+ end
85
+
76
86
  it 'should return a hash' do
77
- title.should be_instance_of Hash
87
+ expect(@title).to be_instance_of Hash
78
88
  end
79
89
 
80
90
  it 'should return a hash with a false response' do
81
- title.response.should eq('False')
91
+ expect(@title.response).to eq('False')
82
92
  end
83
93
 
84
94
  it 'should return a hash with an error message' do
85
- title.error.should be_instance_of String
95
+ expect(@title.error).to be_instance_of String
96
+ end
97
+ end
98
+
99
+ describe 'with the tomatoes option' do
100
+ before(:all) do
101
+ VCR.use_cassette('title/tomatoes') do
102
+ @title = OMDB.title('inception', :tomatoes => true)
103
+ end
104
+ end
105
+
106
+ it 'should contain tomato rating' do
107
+ expect(@title.tomato_rating).to be_instance_of String
108
+ end
109
+
110
+ it 'should contain tomato meter' do
111
+ expect(@title.tomato_meter).to be_instance_of String
112
+ end
113
+
114
+ it 'should contain tomato reviews' do
115
+ expect(@title.tomato_reviews).to be_instance_of String
86
116
  end
87
117
  end
88
118
  end
89
119
 
90
120
  describe 'id' do
91
-
92
121
  describe 'with a title that exists' do
93
- let(:title) { OMDB.id('tt0411008') }
122
+ before(:all) do
123
+ VCR.use_cassette('id/existing') do
124
+ @title = OMDB.id('tt0411008')
125
+ end
126
+ end
94
127
 
95
128
  it 'should return a hash of movie attributes' do
96
- title.should be_instance_of Hash
129
+ expect(@title).to be_instance_of Hash
97
130
  end
98
131
 
99
132
  it 'should contain a title' do
100
- title.title.should be_instance_of String
133
+ expect(@title.title).to be_instance_of String
101
134
  end
102
135
  end
103
136
 
104
- describe 'with a movie that doesn''t exist' do
105
- let(:title) { OMDB.id('tt1231230123') }
106
-
137
+ describe "with a movie that doesn't exist" do
138
+ before(:all) do
139
+ VCR.use_cassette('id/nonexistent') do
140
+ @title = OMDB.id('tt1231230123')
141
+ end
142
+ end
143
+
107
144
  it 'should return a hash' do
108
- title.should be_instance_of Hash
145
+ expect(@title).to be_instance_of Hash
109
146
  end
110
147
 
111
148
  it 'should return a hash with a false response' do
112
- title.response.should eq('False')
149
+ expect(@title.response).to eq('False')
113
150
  end
114
151
 
115
152
  it 'should return a hash with an error message' do
116
- title.error.should be_instance_of String
153
+ expect(@title.error).to be_instance_of String
117
154
  end
118
155
  end
119
156
  end
120
157
 
121
158
  describe 'search' do
122
-
123
159
  describe 'with search results' do
124
- let(:results) { OMDB.search('Star Wars') }
160
+ before(:all) do
161
+ VCR.use_cassette('search/results') do
162
+ @results = OMDB.search('Star Wars')
163
+ end
164
+ end
125
165
 
126
166
  it 'should return an array' do
127
- results.should be_instance_of Array
167
+ expect(@results).to be_instance_of Array
128
168
  end
129
169
 
130
170
  it 'should return an array with hash contents' do
131
- results[0].should be_instance_of Hash
171
+ expect(@results.first).to be_instance_of Hash
132
172
  end
133
173
  end
134
174
 
135
175
  describe 'with a single search result' do
136
- let(:result) { OMDB.search('Star Wars: Episode IV - A New Hope') }
176
+ before(:all) do
177
+ VCR.use_cassette('search/result') do
178
+ @result = OMDB.search('Star Wars Episode IV A New Hope')
179
+ end
180
+ end
137
181
 
138
182
  it 'should return a hash of the title' do
139
- result.should be_instance_of Hash
183
+ expect(@result).to be_instance_of Hash
140
184
  end
141
185
 
142
186
  it 'should have a title' do
143
- result.title.should eq('Star Wars: Episode IV - A New Hope')
187
+ expect(@result.title).to eq('Star Wars: Episode IV - A New Hope')
144
188
  end
145
189
  end
146
190
 
147
191
  describe 'with no search results' do
148
- let(:results) { OMDB.search('lsdfoweirjrpwef323423dsfkip') }
192
+ before(:all) do
193
+ VCR.use_cassette('search/empty') do
194
+ @results = OMDB.search('lsdfoweirjrpwef323423dsfkip')
195
+ end
196
+ end
149
197
 
150
198
  it 'should return a hash' do
151
- results.should be_instance_of Hash
199
+ expect(@results).to be_instance_of Hash
152
200
  end
153
201
 
154
202
  it 'should return a hash with a false response' do
155
- results.response.should eq('False')
203
+ expect(@results.response).to eq('False')
156
204
  end
157
205
 
158
206
  it 'should return a hash with an error message' do
159
- results.error.should be_instance_of String
207
+ expect(@results.error).to be_instance_of String
160
208
  end
161
209
  end
162
210
 
163
211
  describe 'should be aliased to find' do
164
212
  it 'should be the same method' do
165
- OMDB.search('Star Wars').should eq(OMDB.find('Star Wars'))
213
+ VCR.use_cassette('search/find') do
214
+ expect(OMDB.search('Star Wars')).to eq(OMDB.find('Star Wars'))
215
+ end
166
216
  end
167
217
  end
168
218
  end
169
-
170
219
  end
171
-
172
- end
220
+ end
@@ -1,19 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OMDB::Default do
4
-
5
4
  describe 'Hash#method_missing' do
6
- let(:hash) { { a: 'a', b: 'b', c: 'c' } }
5
+ let(:hash) { { a: 'a', b: 'b', c: 'c' } }
7
6
 
8
7
  it 'should allow value access through dot notation' do
9
- hash.a.should eq('a')
8
+ expect(hash.a).to eq('a')
10
9
  end
11
10
  end
12
11
 
13
12
  describe 'String#to_snake_case' do
14
13
  it 'should convert strings to snake case' do
15
- "CamelCasedString".to_snake_case.should eq('camel_cased_string')
14
+ expect('CamelCasedString'.to_snake_case).to eq('camel_cased_string')
16
15
  end
17
16
  end
18
-
19
- end
17
+ end
@@ -1,13 +1,12 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
1
  require 'omdbapi'
2
+ require 'vcr'
8
3
 
9
4
  RSpec.configure do |config|
10
- config.treat_symbols_as_metadata_keys_with_true_values = true
11
5
  config.run_all_when_everything_filtered = true
12
6
  config.filter_run :focus
13
7
  end
8
+
9
+ VCR.configure do |config|
10
+ config.cassette_library_dir = 'spec/vcr'
11
+ config.hook_into :webmock
12
+ end
@@ -0,0 +1,73 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://omdbapi.com/?i=tt0411008
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Sat, 16 Apr 2016 17:33:40 GMT
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ Set-Cookie:
30
+ - __cfduid=d86fa77388fd45e0f6873017c9fbf61b41460828020; expires=Sun, 16-Apr-17
31
+ 17:33:40 GMT; path=/; domain=.omdbapi.com; HttpOnly
32
+ Cache-Control:
33
+ - public, max-age=3600
34
+ Expires:
35
+ - Sat, 16 Apr 2016 18:34:06 GMT
36
+ Last-Modified:
37
+ - Sat, 16 Apr 2016 17:34:06 GMT
38
+ Vary:
39
+ - "*"
40
+ X-Aspnet-Version:
41
+ - 4.0.30319
42
+ X-Powered-By:
43
+ - ASP.NET
44
+ Access-Control-Allow-Origin:
45
+ - "*"
46
+ Server:
47
+ - cloudflare-nginx
48
+ Cf-Ray:
49
+ - 2949623630d616be-ARN
50
+ body:
51
+ encoding: ASCII-8BIT
52
+ string: !binary |-
53
+ eyJUaXRsZSI6Ikxvc3QiLCJZZWFyIjoiMjAwNOKAkzIwMTAiLCJSYXRlZCI6
54
+ IlRWLTE0IiwiUmVsZWFzZWQiOiIyMiBTZXAgMjAwNCIsIlJ1bnRpbWUiOiI0
55
+ NCBtaW4iLCJHZW5yZSI6IkFkdmVudHVyZSwgRHJhbWEsIEZhbnRhc3kiLCJE
56
+ aXJlY3RvciI6Ik4vQSIsIldyaXRlciI6IkouSi4gQWJyYW1zLCBKZWZmcmV5
57
+ IExpZWJlciwgRGFtb24gTGluZGVsb2YiLCJBY3RvcnMiOiJOYXZlZW4gQW5k
58
+ cmV3cywgTWF0dGhldyBGb3gsIEpvcmdlIEdhcmNpYSwgSm9zaCBIb2xsb3dh
59
+ eSIsIlBsb3QiOiJUaGUgc3Vydml2b3JzIG9mIGEgcGxhbmUgY3Jhc2ggYXJl
60
+ IGZvcmNlZCB0byB3b3JrIHRvZ2V0aGVyIGluIG9yZGVyIHRvIHN1cnZpdmUg
61
+ b24gYSBzZWVtaW5nbHkgZGVzZXJ0ZWQgdHJvcGljYWwgaXNsYW5kLiIsIkxh
62
+ bmd1YWdlIjoiRW5nbGlzaCwgUG9ydHVndWVzZSwgU3BhbmlzaCwgQXJhYmlj
63
+ LCBGcmVuY2gsIEtvcmVhbiwgR2VybWFuLCBMYXRpbiwgUnVzc2lhbiwgSmFw
64
+ YW5lc2UiLCJDb3VudHJ5IjoiVVNBIiwiQXdhcmRzIjoiV29uIDEgR29sZGVu
65
+ IEdsb2JlLiBBbm90aGVyIDg0IHdpbnMgJiAzMzYgbm9taW5hdGlvbnMuIiwi
66
+ UG9zdGVyIjoiaHR0cDovL2lhLm1lZGlhLWltZGIuY29tL2ltYWdlcy9NL01W
67
+ NUJNakEzTnpNeU16VTFNVjVCTWw1QmFuQm5Ya0Z0WlRjd05qYzFPRFV3TWdA
68
+ QC5fVjFfU1gzMDAuanBnIiwiTWV0YXNjb3JlIjoiTi9BIiwiaW1kYlJhdGlu
69
+ ZyI6IjguNSIsImltZGJWb3RlcyI6IjM2MywwODUiLCJpbWRiSUQiOiJ0dDA0
70
+ MTEwMDgiLCJUeXBlIjoic2VyaWVzIiwiUmVzcG9uc2UiOiJUcnVlIn0=
71
+ http_version:
72
+ recorded_at: Sat, 16 Apr 2016 17:33:40 GMT
73
+ recorded_with: VCR 3.0.1