thetvdb_api 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +72 -1
  3. data/lib/thetvdb_api.rb +4 -1
  4. data/lib/thetvdb_api/actor.rb +2 -2
  5. data/lib/thetvdb_api/banner.rb +2 -2
  6. data/lib/thetvdb_api/base.rb +30 -9
  7. data/lib/thetvdb_api/episode.rb +10 -10
  8. data/lib/thetvdb_api/mappers/actor.rb +17 -0
  9. data/lib/thetvdb_api/mappers/actors.rb +10 -0
  10. data/lib/thetvdb_api/mappers/banner.rb +32 -0
  11. data/lib/thetvdb_api/mappers/banners.rb +10 -0
  12. data/lib/thetvdb_api/mappers/base.rb +13 -0
  13. data/lib/thetvdb_api/mappers/episode.rb +32 -0
  14. data/lib/thetvdb_api/mappers/full_series.rb +12 -0
  15. data/lib/thetvdb_api/mappers/search_episode.rb +10 -0
  16. data/lib/thetvdb_api/mappers/search_series.rb +10 -0
  17. data/lib/thetvdb_api/mappers/search_series/series.rb +25 -0
  18. data/lib/thetvdb_api/mappers/series.rb +37 -0
  19. data/lib/thetvdb_api/mappers/update.rb +14 -0
  20. data/lib/thetvdb_api/mappers/update/banner.rb +19 -0
  21. data/lib/thetvdb_api/mappers/update/element.rb +10 -0
  22. data/lib/thetvdb_api/mappers/update/episode.rb +8 -0
  23. data/lib/thetvdb_api/mappers/update/series.rb +8 -0
  24. data/lib/thetvdb_api/response.rb +30 -0
  25. data/lib/thetvdb_api/search.rb +8 -8
  26. data/lib/thetvdb_api/series.rb +4 -4
  27. data/lib/thetvdb_api/update.rb +42 -8
  28. data/lib/thetvdb_api/version.rb +1 -1
  29. data/spec/integrations/actor_spec.rb +1 -1
  30. data/spec/integrations/banner_spec.rb +1 -1
  31. data/spec/integrations/client_spec.rb +16 -16
  32. data/spec/integrations/episode_spec.rb +4 -4
  33. data/spec/integrations/search_spec.rb +5 -5
  34. data/spec/integrations/series_spec.rb +2 -2
  35. data/spec/integrations/update_spec.rb +10 -4
  36. data/spec/spec_helper.rb +4 -0
  37. data/spec/thetvdb_api/base_spec.rb +39 -7
  38. data/spec/thetvdb_api/episode_spec.rb +4 -4
  39. data/spec/thetvdb_api/mappers/actor_spec.rb +15 -0
  40. data/spec/thetvdb_api/mappers/banner_spec.rb +31 -0
  41. data/spec/thetvdb_api/mappers/search_series/series_spec.rb +15 -0
  42. data/spec/thetvdb_api/mappers/series_spec.rb +31 -0
  43. data/spec/thetvdb_api/mappers/update/banner_spec.rb +15 -0
  44. data/spec/thetvdb_api/response_spec.rb +60 -0
  45. data/spec/thetvdb_api/search_spec.rb +13 -13
  46. data/spec/thetvdb_api/series_spec.rb +6 -6
  47. data/spec/thetvdb_api/update_spec.rb +24 -0
  48. data/thetvdb_api.gemspec +2 -1
  49. metadata +48 -5
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,10 @@ class SampleModel
17
17
  self
18
18
  end
19
19
 
20
+ def mapper(mapper)
21
+ self
22
+ end
23
+
20
24
  def params(options = {})
21
25
  self
22
26
  end
@@ -7,6 +7,14 @@ describe ThetvdbApi::Base do
7
7
  let(:klass) { ExampleClass }
8
8
  let(:model) { klass.new(ThetvdbApi::Client.new) }
9
9
 
10
+ describe '.connection' do
11
+ it 'should create instance of Faraday' do
12
+ Faraday.should_receive(:new).with(url: 'http://thetvdb.com/api/')
13
+
14
+ model.connection
15
+ end
16
+ end
17
+
10
18
  describe '.get' do
11
19
  it 'should set @uri_template' do
12
20
  model.get('http://example.com')
@@ -23,7 +31,7 @@ describe ThetvdbApi::Base do
23
31
  it 'should set @params' do
24
32
  model.params(sample: 'test')
25
33
 
26
- model.instance_variable_get('@params').should == { sample: 'test' }
34
+ model.instance_variable_get('@params').should == { language: 'en', sample: 'test' }
27
35
  end
28
36
 
29
37
  it 'should return self' do
@@ -32,9 +40,14 @@ describe ThetvdbApi::Base do
32
40
  end
33
41
 
34
42
  describe '.response' do
43
+ it 'should raise error when @uri_template is not filled' do
44
+ -> { model.response }.should raise_error
45
+ end
46
+
35
47
  it 'should call get klass method' do
36
48
  model.instance_variable_set('@uri_template', URITemplate.new('{api_key}/series/{id}'))
37
- klass.should_receive(:get)
49
+ model.stub(:connection).and_return(double(get: true))
50
+ model.connection.should_receive(:get)
38
51
 
39
52
  model.response
40
53
  end
@@ -44,7 +57,16 @@ describe ThetvdbApi::Base do
44
57
  it 'should receive correct uri string' do
45
58
  model.instance_variable_set('@uri_template', URITemplate.new('{api_key}/series/{id}'))
46
59
 
47
- model.prepare_uri.should == "#{ThetvdbApi::Configuration.api_key}/series/"
60
+ model.prepare_uri.should == "#{model.api_key}/series/"
61
+ end
62
+ end
63
+
64
+ describe '.url' do
65
+ it 'should receive correct string' do
66
+ model.stub(:base_url).and_return('BASE_URL/')
67
+ model.stub(:uri).and_return('URI')
68
+
69
+ model.url.should == 'BASE_URL/URI'
48
70
  end
49
71
  end
50
72
 
@@ -53,7 +75,7 @@ describe ThetvdbApi::Base do
53
75
  model.instance_variable_set('@uri_template', URITemplate.new('{api_key}/series/{id}'))
54
76
  model.instance_variable_set('@params', id: '1234')
55
77
 
56
- model.uri.should == "#{ThetvdbApi::Configuration.api_key}/series/1234"
78
+ model.uri.should == "#{model.api_key}/series/1234"
57
79
  end
58
80
  end
59
81
 
@@ -72,13 +94,23 @@ describe ThetvdbApi::Base do
72
94
  end
73
95
  end
74
96
 
75
- describe '.langauge' do
76
- it 'should use default langauge' do
97
+ describe '.language' do
98
+ it 'should use default language' do
77
99
  klass.new(ThetvdbApi::Client.new).language.should == 'en'
78
100
  end
79
101
 
80
- it 'should set langauge' do
102
+ it 'should set language' do
81
103
  klass.new(ThetvdbApi::Client.new(language: 'LANGUAGE')).language.should == 'LANGUAGE'
82
104
  end
83
105
  end
106
+
107
+ describe '.api_key' do
108
+ it 'should use default api_key' do
109
+ klass.new(ThetvdbApi::Client.new).api_key.should == ThetvdbApi::Configuration.api_key
110
+ end
111
+
112
+ it 'should set api_Key' do
113
+ klass.new(ThetvdbApi::Client.new(api_key: 'API_KEY')).api_key.should == 'API_KEY'
114
+ end
115
+ end
84
116
  end
@@ -13,7 +13,7 @@ describe ThetvdbApi::Episode do
13
13
  end
14
14
 
15
15
  it 'should call params with specific params' do
16
- model.should_receive(:params).with(series_id: '1234', season: '1', episode: '1', language: 'en', order: 'default').and_return(mock_model)
16
+ model.should_receive(:params).with(series_id: '1234', season: '1', episode: '1', order: 'default').and_return(mock_model)
17
17
 
18
18
  model.find_by_default_order('1234', '1', '1')
19
19
  end
@@ -27,7 +27,7 @@ describe ThetvdbApi::Episode do
27
27
  end
28
28
 
29
29
  it 'should call params with specific params' do
30
- model.should_receive(:params).with(series_id: '1234', season: '1', episode: '1', language: 'en', order: 'dvd').and_return(mock_model)
30
+ model.should_receive(:params).with(series_id: '1234', season: '1', episode: '1', order: 'dvd').and_return(mock_model)
31
31
 
32
32
  model.find_by_dvd_order('1234', '1', '1')
33
33
  end
@@ -41,7 +41,7 @@ describe ThetvdbApi::Episode do
41
41
  end
42
42
 
43
43
  it 'should call params with specific params' do
44
- model.should_receive(:params).with(series_id: '1234', absolute: '1', language: 'en').and_return(mock_model)
44
+ model.should_receive(:params).with(series_id: '1234', absolute: '1').and_return(mock_model)
45
45
 
46
46
  model.find_by_absolute_order('1234', '1')
47
47
  end
@@ -55,7 +55,7 @@ describe ThetvdbApi::Episode do
55
55
  end
56
56
 
57
57
  it 'should call params with specific params' do
58
- model.should_receive(:params).with(episode_id: '1234', language: 'en').and_return(mock_model)
58
+ model.should_receive(:params).with(episode_id: '1234').and_return(mock_model)
59
59
 
60
60
  model.find('1234')
61
61
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'thetvdb_api/mappers/actor'
3
+
4
+ describe ThetvdbApi::Mappers::Actor do
5
+ let(:klass) { ThetvdbApi::Mappers::Actor }
6
+ let(:model) { klass.new }
7
+
8
+ describe '.image_url' do
9
+ it 'should return correct string' do
10
+ model.stub(:image_path).and_return('PATH')
11
+
12
+ model.image_url.should == 'http://thetvdb.com/banners/PATH'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'thetvdb_api/mappers/banner'
3
+
4
+ describe ThetvdbApi::Mappers::Banner do
5
+ let(:klass) { ThetvdbApi::Mappers::Banner }
6
+ let(:model) { klass.new }
7
+
8
+ describe '.url' do
9
+ it 'should return correct string' do
10
+ model.stub(:path).and_return('PATH')
11
+
12
+ model.url.should == 'http://thetvdb.com/banners/PATH'
13
+ end
14
+ end
15
+
16
+ describe '.thumbnail_url' do
17
+ it 'should return correct string' do
18
+ model.stub(:thumbnail_path).and_return('PATH')
19
+
20
+ model.thumbnail_url.should == 'http://thetvdb.com/banners/PATH'
21
+ end
22
+ end
23
+
24
+ describe '.vignette_url' do
25
+ it 'should return correct string' do
26
+ model.stub(:vignette_path).and_return('PATH')
27
+
28
+ model.vignette_url.should == 'http://thetvdb.com/banners/PATH'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'thetvdb_api/mappers/search_series/series'
3
+
4
+ describe ThetvdbApi::Mappers::SearchSeries::Series do
5
+ let(:klass) { ThetvdbApi::Mappers::SearchSeries::Series }
6
+ let(:model) { klass.new }
7
+
8
+ describe '.banner_url' do
9
+ it 'should return correct string' do
10
+ model.stub(:banner_path).and_return('PATH')
11
+
12
+ model.banner_url.should == 'http://thetvdb.com/banners/PATH'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'thetvdb_api/mappers/series'
3
+
4
+ describe ThetvdbApi::Mappers::Series do
5
+ let(:klass) { ThetvdbApi::Mappers::Series }
6
+ let(:model) { klass.new }
7
+
8
+ describe '.banner_url' do
9
+ it 'should return correct string' do
10
+ model.stub(:banner_path).and_return('PATH')
11
+
12
+ model.banner_url.should == 'http://thetvdb.com/banners/PATH'
13
+ end
14
+ end
15
+
16
+ describe '.fanart_url' do
17
+ it 'should return correct string' do
18
+ model.stub(:fanart_path).and_return('PATH')
19
+
20
+ model.fanart_url.should == 'http://thetvdb.com/banners/PATH'
21
+ end
22
+ end
23
+
24
+ describe '.poster_url' do
25
+ it 'should return correct string' do
26
+ model.stub(:poster_path).and_return('PATH')
27
+
28
+ model.poster_url.should == 'http://thetvdb.com/banners/PATH'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'thetvdb_api/mappers/update/banner'
3
+
4
+ describe ThetvdbApi::Mappers::Update::Banner do
5
+ let(:klass) { ThetvdbApi::Mappers::Update::Banner }
6
+ let(:model) { klass.new }
7
+
8
+ describe '.url' do
9
+ it 'should return correct string' do
10
+ model.stub(:path).and_return('PATH')
11
+
12
+ model.url.should == 'http://thetvdb.com/banners/PATH'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbApi::Search do
4
+ let(:klass) { ThetvdbApi::Response }
5
+ let(:model) { klass.new(faraday_response) }
6
+ let(:faraday_response) { double(env: true, status: true, headers: true, body: 'TEST') }
7
+
8
+ describe '.mapper' do
9
+ it 'should set mapper' do
10
+ model = klass.new(faraday_response, 'MAPPER')
11
+ model.mapper.should == 'MAPPER'
12
+ end
13
+ end
14
+
15
+ describe '.env' do
16
+ it 'should call env in faraday_response' do
17
+ faraday_response.should_receive(:env)
18
+
19
+ model.env
20
+ end
21
+ end
22
+
23
+ describe '.status' do
24
+ it 'should call status in faraday_response' do
25
+ faraday_response.should_receive(:status)
26
+
27
+ model.status
28
+ end
29
+ end
30
+
31
+ describe '.headers' do
32
+ it 'should call headers in faraday_response' do
33
+ faraday_response.should_receive(:headers)
34
+
35
+ model.headers
36
+ end
37
+ end
38
+
39
+ describe '.body' do
40
+ it 'should map response when give mapper' do
41
+ mapper = double(parse: true)
42
+ model = klass.new(faraday_response, mapper)
43
+ mapper.should_receive(:parse)
44
+
45
+ model.body
46
+ end
47
+
48
+ it 'should return string' do
49
+ model.body.class.should == String
50
+ end
51
+ end
52
+
53
+ describe '.inspect' do
54
+ it 'should return correct string' do
55
+ model.stub(:body).and_return('BODY')
56
+ model.stub(:mapper).and_return('MAPPER')
57
+ model.inspect.should == '<ThetvdbApi::Response body="BODY", mapper="MAPPER">'
58
+ end
59
+ end
60
+ end
@@ -9,13 +9,13 @@ describe ThetvdbApi::Search do
9
9
  it 'should call get with specific params' do
10
10
  model.should_receive(:get).with('GetSeries.php').and_return(mock_model)
11
11
 
12
- model.get_series('buffy', 'en')
12
+ model.get_series('buffy')
13
13
  end
14
14
 
15
15
  it 'should call params with specific params' do
16
- model.should_receive(:params).with(seriesname: 'buffy', language: 'en').and_return(mock_model)
16
+ model.should_receive(:params).with(seriesname: 'buffy').and_return(mock_model)
17
17
 
18
- model.get_series('buffy', 'en')
18
+ model.get_series('buffy')
19
19
  end
20
20
  end
21
21
 
@@ -23,13 +23,13 @@ describe ThetvdbApi::Search do
23
23
  it 'should call get with specific params' do
24
24
  model.should_receive(:get).with('GetSeriesByRemoteID.php').and_return(mock_model)
25
25
 
26
- model.get_series_by_imdb_id('1234', 'en')
26
+ model.get_series_by_imdb_id('1234')
27
27
  end
28
28
 
29
29
  it 'should call params with specific params' do
30
- model.should_receive(:params).with(imdbid: '1234', language: 'en').and_return(mock_model)
30
+ model.should_receive(:params).with(imdbid: '1234').and_return(mock_model)
31
31
 
32
- model.get_series_by_imdb_id('1234', 'en')
32
+ model.get_series_by_imdb_id('1234')
33
33
  end
34
34
  end
35
35
 
@@ -37,27 +37,27 @@ describe ThetvdbApi::Search do
37
37
  it 'should call get with specific params' do
38
38
  model.should_receive(:get).with('GetSeriesByRemoteID.php').and_return(mock_model)
39
39
 
40
- model.get_series_by_zap2it_id('1234', 'en')
40
+ model.get_series_by_zap2it_id('1234')
41
41
  end
42
42
 
43
43
  it 'should call params with specific params' do
44
- model.should_receive(:params).with(zap2it: '1234', language: 'en').and_return(mock_model)
44
+ model.should_receive(:params).with(zap2it: '1234').and_return(mock_model)
45
45
 
46
- model.get_series_by_zap2it_id('1234', 'en')
46
+ model.get_series_by_zap2it_id('1234')
47
47
  end
48
48
  end
49
49
 
50
- describe '#get_episode_by_air_date' do
50
+ describe '.get_episode' do
51
51
  it 'should call get with specific params' do
52
52
  model.should_receive(:get).with('GetEpisodeByAirDate.php').and_return(mock_model)
53
53
 
54
- model.get_episode_by_air_date('1234', '2000-01-01', 'en')
54
+ model.get_episode('1234', '2000-01-01')
55
55
  end
56
56
 
57
57
  it 'should call params with specific params' do
58
- model.should_receive(:params).with(seriesid: '1234', airdate: '2000-01-01', language: 'en').and_return(mock_model)
58
+ model.should_receive(:params).with(seriesid: '1234', airdate: '2000-01-01').and_return(mock_model)
59
59
 
60
- model.get_episode_by_air_date('1234', '2000-01-01', 'en')
60
+ model.get_episode('1234', '2000-01-01')
61
61
  end
62
62
  end
63
63
  end
@@ -9,13 +9,13 @@ describe ThetvdbApi::Series do
9
9
  it 'should call get with specific params' do
10
10
  model.should_receive(:get).with('{api_key}/series/{series_id}/{language}.xml').and_return(mock_model)
11
11
 
12
- model.find('1234', 'en')
12
+ model.find('1234')
13
13
  end
14
14
 
15
15
  it 'should call params with specific params' do
16
- model.should_receive(:params).with(series_id: '1234', language: 'en').and_return(mock_model)
16
+ model.should_receive(:params).with(series_id: '1234').and_return(mock_model)
17
17
 
18
- model.find('1234', 'en')
18
+ model.find('1234')
19
19
  end
20
20
  end
21
21
 
@@ -23,13 +23,13 @@ describe ThetvdbApi::Series do
23
23
  it 'should call get with specific params' do
24
24
  model.should_receive(:get).with('{api_key}/series/{series_id}/all/{language}.xml').and_return(mock_model)
25
25
 
26
- model.find_full('1234', 'en')
26
+ model.find_full('1234')
27
27
  end
28
28
 
29
29
  it 'should call params with specific params' do
30
- model.should_receive(:params).with(series_id: '1234', language: 'en').and_return(mock_model)
30
+ model.should_receive(:params).with(series_id: '1234').and_return(mock_model)
31
31
 
32
- model.find_full('1234', 'en')
32
+ model.find_full('1234')
33
33
  end
34
34
  end
35
35
  end
@@ -13,6 +13,12 @@ describe ThetvdbApi::Update do
13
13
  end
14
14
  end
15
15
 
16
+ describe '.day_url' do
17
+ it 'should return correct string' do
18
+ model.day_url.should == "http://thetvdb.com/api/#{model.api_key}/updates/updates_day.xml"
19
+ end
20
+ end
21
+
16
22
  describe '.week' do
17
23
  it 'should call get with specific params' do
18
24
  model.should_receive(:get).with('{api_key}/updates/updates_week.xml').and_return(mock_model)
@@ -21,6 +27,12 @@ describe ThetvdbApi::Update do
21
27
  end
22
28
  end
23
29
 
30
+ describe '.week_url' do
31
+ it 'should return correct string' do
32
+ model.week_url.should == "http://thetvdb.com/api/#{model.api_key}/updates/updates_week.xml"
33
+ end
34
+ end
35
+
24
36
  describe '.month' do
25
37
  it 'should call get with specific params' do
26
38
  model.should_receive(:get).with('{api_key}/updates/updates_month.xml').and_return(mock_model)
@@ -29,6 +41,12 @@ describe ThetvdbApi::Update do
29
41
  end
30
42
  end
31
43
 
44
+ describe '.month_url' do
45
+ it 'should return correct string' do
46
+ model.month_url.should == "http://thetvdb.com/api/#{model.api_key}/updates/updates_month.xml"
47
+ end
48
+ end
49
+
32
50
  describe '.all' do
33
51
  it 'should call get with specific params' do
34
52
  model.should_receive(:get).with('{api_key}/updates/updates_all.xml').and_return(mock_model)
@@ -36,4 +54,10 @@ describe ThetvdbApi::Update do
36
54
  model.all
37
55
  end
38
56
  end
57
+
58
+ describe '.all_url' do
59
+ it 'should return correct string' do
60
+ model.all_url.should == "http://thetvdb.com/api/#{model.api_key}/updates/updates_all.xml"
61
+ end
62
+ end
39
63
  end