themoviedb 1.0.0 → 1.0.1

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: 166055b6cba5ab74aa7f8959d58f0efd12f908ff
4
- data.tar.gz: bb037509ef8cde00343b786f92cdf3a048669aab
3
+ metadata.gz: 4841a9b8af1e16aca5ce1df17d174ac6d278b7e8
4
+ data.tar.gz: d118439af3bbe6b4452756921704c929ec46832d
5
5
  SHA512:
6
- metadata.gz: ccf100be48cedee1cc87887f05a15747302b1fdd1ea7dde14090542f7cff16521401cec4adecd0e7903ae77722021a90691ac936b79da5b3bce03fc7fefc8444
7
- data.tar.gz: ba5b785ec47a6e9f026377281b2753c450ed425656a63dcdbb23e00e048250875056a6799a48ec80a7ad2f38b1781bd5fdebc5f4c7f68738159df4e8d854c4ee
6
+ metadata.gz: 2c0b53885f021caa05da2eabed934b0f8028c530d55c25e73155835188cc8fdca7ed70f6c9281017bd3d3052de3a4e552ceff4ab655d249b2f06fdf0e88541fa
7
+ data.tar.gz: 13eed0665d2a7091bd49bacf6416382185bed100a63035c6a9d24b0f54b3d1c3f31e3d94208bd7e47b6fcb7bf4523d7602aec06f1b0999b57b944f27160a6792
@@ -1,4 +1,5 @@
1
1
  module Tmdb
2
+ class InvalidApiKeyError < StandardError ; end
2
3
  class Api
3
4
  include HTTParty
4
5
  base_uri 'api.themoviedb.org/3/'
@@ -32,6 +33,8 @@ module Tmdb
32
33
 
33
34
  def self.set_response(hash)
34
35
  @@response = hash
36
+ # Detect 401 Unauthorized error, which indicates invalid API key
37
+ raise Tmdb::InvalidApiKeyError if hash['code'].to_i == 401
35
38
  end
36
39
  end
37
40
  end
@@ -16,7 +16,7 @@ module Tmdb
16
16
  self
17
17
  end
18
18
 
19
- def primary_realease_year(year)
19
+ def primary_release_year(year)
20
20
  @params[:primary_release_year] = year.to_s
21
21
  self
22
22
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Tmdb
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
  end
@@ -0,0 +1,24 @@
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+
4
+ describe 'invalid API key' do
5
+ after(:all) { Tmdb::Api.key($VALID_API_KEY) }
6
+ it 'raises error for nil key' do
7
+ Tmdb::Api.key(nil)
8
+ VCR.use_cassette 'api_key/nil_key' do
9
+ expect { Tmdb::Movie.search('batman') }.to raise_error(Tmdb::InvalidApiKeyError)
10
+ end
11
+ end
12
+ it 'raises error for empty string key' do
13
+ Tmdb::Api.key('')
14
+ VCR.use_cassette 'api_key/empty_string' do
15
+ expect { Tmdb::Movie.search('batman') }.to raise_error(Tmdb::InvalidApiKeyError)
16
+ end
17
+ end
18
+ it 'raises error invalid nonempty key' do
19
+ Tmdb::Api.key('bad-key')
20
+ VCR.use_cassette 'api_key/invalid_key' do
21
+ expect { Tmdb::Movie.search('batman') }.to raise_error(Tmdb::InvalidApiKeyError)
22
+ end
23
+ end
24
+ end
@@ -8,7 +8,8 @@
8
8
  require_relative '../lib/themoviedb.rb'
9
9
  require 'vcr'
10
10
 
11
- Tmdb::Api.key('8a221fc31fcdf12a8af827465574ffc9')
11
+ $VALID_API_KEY = '8a221fc31fcdf12a8af827465574ffc9'
12
+ Tmdb::Api.key($VALID_API_KEY)
12
13
 
13
14
  VCR.configure do |c|
14
15
  # the directory where your cassettes will be saved
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.themoviedb.org/3/search/movie?api_key=&query=batman
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 401
17
+ message: Unauthorized
18
+ headers:
19
+ Content-Type:
20
+ - application/json;charset=utf-8
21
+ Date:
22
+ - Sun, 07 Feb 2016 19:36:58 GMT
23
+ Server:
24
+ - openresty
25
+ X-Ratelimit-Limit:
26
+ - '40'
27
+ X-Ratelimit-Remaining:
28
+ - '38'
29
+ X-Ratelimit-Reset:
30
+ - '1454873828'
31
+ Content-Length:
32
+ - '86'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"status_code":7,"status_message":"Invalid API key: You must be granted
38
+ a valid key."}'
39
+ http_version:
40
+ recorded_at: Sun, 07 Feb 2016 19:37:00 GMT
41
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.themoviedb.org/3/search/movie?api_key=bad-key&query=batman
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 401
17
+ message: Unauthorized
18
+ headers:
19
+ Content-Type:
20
+ - application/json;charset=utf-8
21
+ Date:
22
+ - Sun, 07 Feb 2016 19:36:58 GMT
23
+ Server:
24
+ - openresty
25
+ X-Ratelimit-Limit:
26
+ - '40'
27
+ X-Ratelimit-Remaining:
28
+ - '37'
29
+ X-Ratelimit-Reset:
30
+ - '1454873828'
31
+ Content-Length:
32
+ - '86'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"status_code":7,"status_message":"Invalid API key: You must be granted
38
+ a valid key."}'
39
+ http_version:
40
+ recorded_at: Sun, 07 Feb 2016 19:37:00 GMT
41
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.themoviedb.org/3/search/movie?api_key=&query=batman
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 401
17
+ message: Unauthorized
18
+ headers:
19
+ Content-Type:
20
+ - application/json;charset=utf-8
21
+ Date:
22
+ - Sun, 07 Feb 2016 19:36:58 GMT
23
+ Server:
24
+ - openresty
25
+ X-Ratelimit-Limit:
26
+ - '40'
27
+ X-Ratelimit-Remaining:
28
+ - '39'
29
+ X-Ratelimit-Reset:
30
+ - '1454873828'
31
+ Content-Length:
32
+ - '86'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"status_code":7,"status_message":"Invalid API key: You must be granted
38
+ a valid key."}'
39
+ http_version:
40
+ recorded_at: Sun, 07 Feb 2016 19:37:00 GMT
41
+ recorded_with: VCR 3.0.1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themoviedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmet Abdi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2016-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -106,11 +106,15 @@ files:
106
106
  - lib/themoviedb/version.rb
107
107
  - spec/company_spec.rb
108
108
  - spec/find_spec.rb
109
+ - spec/invalid_api_key_spec.rb
109
110
  - spec/movie_spec.rb
110
111
  - spec/person_spec.rb
111
112
  - spec/spec/vcr/find/search_imdb.yml
112
113
  - spec/spec_helper.rb
113
114
  - spec/tv_spec.rb
115
+ - spec/vcr/api_key/empty_string.yml
116
+ - spec/vcr/api_key/invalid_key.yml
117
+ - spec/vcr/api_key/nil_key.yml
114
118
  - spec/vcr/company/detail.yml
115
119
  - spec/vcr/company/movies.yml
116
120
  - spec/vcr/find/search_imdb.yml
@@ -176,6 +180,7 @@ signing_key:
176
180
  specification_version: 4
177
181
  summary: A Ruby wrapper for the The Movie Database API.
178
182
  test_files:
183
+ - spec/invalid_api_key_spec.rb
179
184
  - spec/company_spec.rb
180
185
  - spec/spec_helper.rb
181
186
  - spec/tv_spec.rb
@@ -205,6 +210,9 @@ test_files:
205
210
  - spec/vcr/movie/trailers_for_id.yml
206
211
  - spec/vcr/company/movies.yml
207
212
  - spec/vcr/company/detail.yml
213
+ - spec/vcr/api_key/nil_key.yml
214
+ - spec/vcr/api_key/invalid_key.yml
215
+ - spec/vcr/api_key/empty_string.yml
208
216
  - spec/vcr/find/search_imdb.yml
209
217
  - spec/vcr/find/search_tvdb.yml
210
218
  - spec/vcr/tv/crew.yml