thetvdb_api 0.0.1 → 0.1.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -22
  3. data/lib/thetvdb_api/actor.rb +3 -2
  4. data/lib/thetvdb_api/banner.rb +3 -9
  5. data/lib/thetvdb_api/base.rb +44 -5
  6. data/lib/thetvdb_api/client.rb +34 -0
  7. data/lib/thetvdb_api/episode.rb +14 -31
  8. data/lib/thetvdb_api/search.rb +18 -0
  9. data/lib/thetvdb_api/series.rb +6 -17
  10. data/lib/thetvdb_api/update.rb +17 -0
  11. data/lib/thetvdb_api/version.rb +1 -1
  12. data/lib/thetvdb_api.rb +6 -17
  13. data/spec/integrations/actor_spec.rb +5 -5
  14. data/spec/integrations/banner_spec.rb +5 -5
  15. data/spec/integrations/client_spec.rb +109 -0
  16. data/spec/integrations/episode_spec.rb +14 -14
  17. data/spec/integrations/search_spec.rb +14 -14
  18. data/spec/integrations/series_spec.rb +8 -8
  19. data/spec/integrations/update_spec.rb +11 -11
  20. data/spec/thetvdb_api/actor_spec.rb +5 -12
  21. data/spec/thetvdb_api/banner_spec.rb +5 -57
  22. data/spec/thetvdb_api/base_spec.rb +92 -0
  23. data/spec/thetvdb_api/client_spec.rb +35 -0
  24. data/spec/thetvdb_api/episode_spec.rb +17 -149
  25. data/spec/thetvdb_api/search_spec.rb +42 -0
  26. data/spec/thetvdb_api/series_spec.rb +9 -97
  27. data/spec/thetvdb_api/update_spec.rb +38 -0
  28. data/thetvdb_api.gemspec +0 -1
  29. metadata +15 -61
  30. data/lib/thetvdb_api/request/actor.rb +0 -18
  31. data/lib/thetvdb_api/request/banner.rb +0 -18
  32. data/lib/thetvdb_api/request/base.rb +0 -74
  33. data/lib/thetvdb_api/request/episode.rb +0 -39
  34. data/lib/thetvdb_api/request/module/find.rb +0 -17
  35. data/lib/thetvdb_api/request/module/series_uri.rb +0 -17
  36. data/lib/thetvdb_api/request/search.rb +0 -37
  37. data/lib/thetvdb_api/request/series.rb +0 -48
  38. data/lib/thetvdb_api/request/update.rb +0 -45
  39. data/lib/thetvdb_api/utility/array.rb +0 -5
  40. data/lib/thetvdb_api/utility/date.rb +0 -9
  41. data/lib/thetvdb_api/utility/float.rb +0 -5
  42. data/lib/thetvdb_api/utility/hashie/extensions/key_replace.rb +0 -42
  43. data/lib/thetvdb_api/utility/integer.rb +0 -5
  44. data/lib/thetvdb_api/utility/string.rb +0 -11
  45. data/lib/thetvdb_api/utility/time.rb +0 -9
  46. data/lib/thetvdb_api/utility.rb +0 -7
  47. data/spec/thetvdb_api/request/actor_spec.rb +0 -31
  48. data/spec/thetvdb_api/request/banner_spec.rb +0 -31
  49. data/spec/thetvdb_api/request/base_spec.rb +0 -121
  50. data/spec/thetvdb_api/request/episode_spec.rb +0 -82
  51. data/spec/thetvdb_api/request/module/series_uri_spec.rb +0 -17
  52. data/spec/thetvdb_api/request/search_spec.rb +0 -63
  53. data/spec/thetvdb_api/request/series_spec.rb +0 -86
  54. data/spec/thetvdb_api/request/update_spec.rb +0 -76
  55. data/spec/thetvdb_api/utility/array_spec.rb +0 -9
  56. data/spec/thetvdb_api/utility/date_spec.rb +0 -13
  57. data/spec/thetvdb_api/utility/float_spec.rb +0 -9
  58. data/spec/thetvdb_api/utility/integer_spec.rb +0 -9
  59. data/spec/thetvdb_api/utility/string_spec.rb +0 -9
  60. data/spec/thetvdb_api/utility/time_spec.rb +0 -13
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ThetvdbApi::Request::Episode do
4
- let(:klass) { ThetvdbApi::Request::Episode }
3
+ describe ThetvdbApi::Episode do
4
+ let(:model) { ThetvdbApi::Episode.new(ThetvdbApi::Client.new) }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find_by_default_order' do
8
- it 'should return series class' do
9
- klass.find_by_default_order('70327', '1', '1').result.class.should == ThetvdbApi::Episode
7
+ describe '.find_by_default_order' do
8
+ it 'should return hash' do
9
+ model.find_by_default_order('70327', '1', '1').class.should == Hash
10
10
  end
11
11
  end
12
12
 
13
- describe '#find_by_dvd_order' do
14
- it 'should return series and episodes' do
15
- klass.find_by_dvd_order('70327', '1', '1').result.class.should == ThetvdbApi::Episode
13
+ describe '.find_by_dvd_order' do
14
+ it 'should return hash' do
15
+ model.find_by_dvd_order('70327', '1', '1').class.should == Hash
16
16
  end
17
17
  end
18
18
 
19
- describe '#find_by_absolute_order' do
20
- it 'should return series and episodes' do
21
- klass.find_by_absolute_order('70327', '1').result.class.should == ThetvdbApi::Episode
19
+ describe '.find_by_absolute_order' do
20
+ it 'should return hash' do
21
+ model.find_by_absolute_order('70327', '1').class.should == Hash
22
22
  end
23
23
  end
24
24
 
25
- describe '#find' do
26
- it 'should return series and episodes' do
27
- klass.find('533011').result.class.should == ThetvdbApi::Episode
25
+ describe '.find' do
26
+ it 'should return hash' do
27
+ model.find('533011').class.should == Hash
28
28
  end
29
29
  end
30
30
  end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ThetvdbApi::Request::Search do
4
- let(:klass) { ThetvdbApi::Request::Search }
3
+ describe ThetvdbApi::Search do
4
+ let(:model) { ThetvdbApi::Search.new(ThetvdbApi::Client.new) }
5
5
 
6
6
  describe 'real request' do
7
- describe '#get_series' do
8
- it 'should return array' do
9
- klass.get_series('buffy').result.class.should == Array
7
+ describe '.get_series' do
8
+ it 'should return hash' do
9
+ model.get_series('buffy').class.should == Hash
10
10
  end
11
11
  end
12
12
 
13
- describe '#get_series_by_imdb_id' do
14
- it 'should return series class' do
15
- klass.get_series_by_imdb_id('tt0118276').result.class.should == ThetvdbApi::Series
13
+ describe '.get_series_by_imdb_id' do
14
+ it 'should return hash' do
15
+ model.get_series_by_imdb_id('tt0118276').class.should == Hash
16
16
  end
17
17
  end
18
18
 
19
- describe '#get_series_by_zap2it_id' do
20
- it 'should return series class' do
21
- klass.get_series_by_zap2it_id('EP00213110').result.class.should == ThetvdbApi::Series
19
+ describe '.get_series_by_zap2it_id' do
20
+ it 'should return hash' do
21
+ model.get_series_by_zap2it_id('EP00213110').class.should == Hash
22
22
  end
23
23
  end
24
24
 
25
- describe '#get_episode_by_air_date' do
26
- it 'should return episode class' do
27
- klass.get_episode_by_air_date('70327','1997-03-10').result.class.should == ThetvdbApi::Episode
25
+ describe '.get_episode_by_air_date' do
26
+ it 'should return hash' do
27
+ model.get_episode_by_air_date('70327','1997-03-10').class.should == Hash
28
28
  end
29
29
  end
30
30
  end
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ThetvdbApi::Request::Series do
4
- let(:klass) { ThetvdbApi::Request::Series }
3
+ describe ThetvdbApi::Series do
4
+ let(:model) { ThetvdbApi::Series.new(ThetvdbApi::Client.new) }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find' do
8
- it 'should return series class' do
9
- klass.find('70327').result.class.should == ThetvdbApi::Series
7
+ describe '.find' do
8
+ it 'should return hash' do
9
+ model.find('70327').class.should == Hash
10
10
  end
11
11
  end
12
12
 
13
- describe '#find_full' do
14
- it 'should return series and episodes' do
15
- klass.find_full('70327').result.keys.sort.should == [:series, :episodes].sort
13
+ describe '.find_full' do
14
+ it 'should return hash' do
15
+ model.find_full('70327').class.should == Hash
16
16
  end
17
17
  end
18
18
  end
@@ -1,24 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ThetvdbApi::Request::Update do
4
- let(:klass) { ThetvdbApi::Request::Update }
3
+ describe ThetvdbApi::Update do
4
+ let(:model) { ThetvdbApi::Update.new(ThetvdbApi::Client.new) }
5
5
 
6
6
  describe 'real request' do
7
- describe '#day' do
8
- it 'should return correct keys' do
9
- klass.day.result.keys.sort.should == [:series, :episodes, :banners].sort
7
+ describe '.day' do
8
+ it 'should return hash' do
9
+ model.day.class.should == Hash
10
10
  end
11
11
  end
12
12
 
13
- describe '#week' do
14
- it 'should return correct keys' do
15
- klass.week.result.keys.sort.should == [:series, :episodes, :banners].sort
13
+ describe '.week' do
14
+ it 'should return hash' do
15
+ model.week.class.should == Hash
16
16
  end
17
17
  end
18
18
 
19
- describe '#month' do
20
- it 'should return correct keys' do
21
- klass.month.result.keys.sort.should == [:series, :episodes, :banners].sort
19
+ describe '.month' do
20
+ it 'should return hash' do
21
+ model.month.class.should == Hash
22
22
  end
23
23
  end
24
24
  end
@@ -2,20 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe ThetvdbApi::Actor do
4
4
  let(:klass) { ThetvdbApi::Actor }
5
+ let(:model) { klass.new(ThetvdbApi::Client.new(api_key: '123456789')) }
5
6
 
6
- shared_examples 'integer mapping' do |field|
7
- it 'should save as Integer' do
8
- klass.new(field => '123').send(field).should == 123
9
- end
10
- end
11
-
12
- describe 'ceorce' do
13
- describe 'id attribute' do
14
- include_examples 'integer mapping', :id
15
- end
7
+ describe '.find' do
8
+ it 'should call new with specific params' do
9
+ model.should_receive(:get).with('123456789/series/1234/actors.xml').and_return(double(response: true))
16
10
 
17
- describe 'sort_order attribute' do
18
- include_examples 'integer mapping', :sort_order
11
+ model.find('1234')
19
12
  end
20
13
  end
21
14
  end
@@ -2,65 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe ThetvdbApi::Banner do
4
4
  let(:klass) { ThetvdbApi::Banner }
5
+ let(:model) { klass.new(ThetvdbApi::Client.new(api_key: '123456789')) }
5
6
 
6
- shared_examples 'mapping' do |field, field_mapped|
7
- it "should save as #{field_mapped}" do
8
- klass.new(field => '123').send(field_mapped).should_not == nil
9
- end
10
- end
11
-
12
- shared_examples 'integer mapping' do |field|
13
- it 'should save as Integer' do
14
- klass.new(field => '123').send(field).should == 123
15
- end
16
- end
17
-
18
- shared_examples 'float mapping' do |field|
19
- it 'should save as Integer' do
20
- klass.new(field => '12.3').send(field).should == 12.3
21
- end
22
- end
23
-
24
- shared_examples 'time mapping' do |field|
25
- it 'should save as Time' do
26
- time = Time.now
27
- klass.new(field => time.to_i.to_s).send(field).to_i.should == time.to_i
28
- end
29
- end
30
-
31
- describe 'key mapping' do
32
- describe 'Series attribute' do
33
- include_examples 'mapping', :Series, :series_id
34
- end
35
- end
36
-
37
- describe 'ceorce' do
38
- describe 'id attribute' do
39
- include_examples 'integer mapping', :id
40
- end
41
-
42
- describe 'rating attribute' do
43
- include_examples 'float mapping', :rating
44
- end
45
-
46
- describe 'rating_count attribute' do
47
- include_examples 'integer mapping', :rating_count
48
- end
49
-
50
- describe 'season attribute' do
51
- include_examples 'integer mapping', :season
52
- end
53
-
54
- describe 'series_id attribute' do
55
- include_examples 'integer mapping', :series_id
56
- end
57
-
58
- describe 'season_num attribute' do
59
- include_examples 'integer mapping', :season_num
60
- end
7
+ describe '.find' do
8
+ it 'should call new with specific params' do
9
+ model.should_receive(:get).with('123456789/series/1234/banners.xml').and_return(double(response: true))
61
10
 
62
- describe 'time attribute' do
63
- include_examples 'time mapping', :time
11
+ model.find('1234')
64
12
  end
65
13
  end
66
14
  end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ class ExampleClass < ThetvdbApi::Base
4
+ end
5
+
6
+ describe ThetvdbApi::Base do
7
+ let(:klass) { ExampleClass }
8
+ let(:model) { klass.new(ThetvdbApi::Client.new) }
9
+
10
+ describe '.get' do
11
+ it 'should set uri' do
12
+ model.get('http://example.com')
13
+
14
+ model.uri.should == 'http://example.com'
15
+ end
16
+
17
+ it 'should set options' do
18
+ model.get('http://example.com', sample_options: true)
19
+
20
+ model.options.should == { sample_options: true }
21
+ end
22
+
23
+ it 'should return self' do
24
+ model.get('http://example.com').should == model
25
+ end
26
+ end
27
+
28
+ describe '.response' do
29
+ it 'should call get klass method' do
30
+ klass.should_receive(:get).and_return(double(code: 200, parsed_response: {}))
31
+ model.stub(:request_options).and_return({})
32
+
33
+ model.response
34
+ end
35
+
36
+ it 'should return Hash' do
37
+ klass.should_receive(:get).and_return(double(code: 200, parsed_response: {}))
38
+ model.stub(:request_options).and_return({})
39
+
40
+ model.response.class.should == Hash
41
+ end
42
+
43
+ it 'should return nil' do
44
+ klass.should_receive(:get).and_return(double(code: 400))
45
+ model.stub(:request_options).and_return({})
46
+
47
+ model.response.should be_nil
48
+ end
49
+ end
50
+
51
+ describe '.request_options' do
52
+ it 'should return correct keys' do
53
+ model.request_options.keys.sort.should == [:query, :base_uri].sort
54
+ end
55
+ end
56
+
57
+ describe '.series_uri' do
58
+ it 'should use default api_key' do
59
+ klass.new(ThetvdbApi::Client.new(api_key: 'API_KEY')).series_uri('1234').should == 'API_KEY/series/1234/'
60
+ end
61
+ end
62
+
63
+ describe '.api_key' do
64
+ it 'should use default api_key' do
65
+ klass.new(ThetvdbApi::Client.new).api_key.should == ThetvdbApi::Configuration.api_key
66
+ end
67
+
68
+ it 'should set api_key' do
69
+ klass.new(ThetvdbApi::Client.new(api_key: 'API_KEY')).api_key.should == 'API_KEY'
70
+ end
71
+ end
72
+
73
+ describe '.api_url' do
74
+ it 'should use default api_url' do
75
+ klass.new(ThetvdbApi::Client.new).api_url.should == 'http://thetvdb.com/api/'
76
+ end
77
+
78
+ it 'should set api_url' do
79
+ klass.new(ThetvdbApi::Client.new(api_url: 'API_URL')).api_url.should == 'API_URL'
80
+ end
81
+ end
82
+
83
+ describe '.langauge' do
84
+ it 'should use default langauge' do
85
+ klass.new(ThetvdbApi::Client.new).language.should == 'en'
86
+ end
87
+
88
+ it 'should set langauge' do
89
+ klass.new(ThetvdbApi::Client.new(language: 'LANGUAGE')).language.should == 'LANGUAGE'
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbApi::Client do
4
+ let(:klass) { ThetvdbApi::Client }
5
+
6
+ describe '.search' do
7
+ it 'should return search class' do
8
+ klass.new.search.class.should == ThetvdbApi::Search
9
+ end
10
+ end
11
+
12
+ describe '.series' do
13
+ it 'should return series class' do
14
+ klass.new.series.class.should == ThetvdbApi::Series
15
+ end
16
+ end
17
+
18
+ describe '.actor' do
19
+ it 'should return actor class' do
20
+ klass.new.actor.class.should == ThetvdbApi::Actor
21
+ end
22
+ end
23
+
24
+ describe '.banner' do
25
+ it 'should return banner class' do
26
+ klass.new.banner.class.should == ThetvdbApi::Banner
27
+ end
28
+ end
29
+
30
+ describe '.episode' do
31
+ it 'should return episode class' do
32
+ klass.new.episode.class.should == ThetvdbApi::Episode
33
+ end
34
+ end
35
+ end
@@ -2,169 +2,37 @@ require 'spec_helper'
2
2
 
3
3
  describe ThetvdbApi::Episode do
4
4
  let(:klass) { ThetvdbApi::Episode }
5
+ let(:model) { klass.new(ThetvdbApi::Client.new(api_key: '123456789')) }
5
6
 
6
- shared_examples 'mapping' do |field, field_mapped|
7
- it "should save as #{field_mapped}" do
8
- klass.new(field => '123').send(field_mapped).should_not == nil
9
- end
10
- end
7
+ describe '.find_by_default_order' do
8
+ it 'should call new with specific params' do
9
+ model.should_receive(:get).with('123456789/series/1234/default/1/1/en.xml').and_return(double(response: true))
11
10
 
12
- shared_examples 'integer mapping' do |field|
13
- it 'should save as Integer' do
14
- klass.new(field => '123').send(field).should == 123
11
+ model.find_by_default_order('1234', '1', '1')
15
12
  end
16
13
  end
17
14
 
18
- shared_examples 'float mapping' do |field|
19
- it 'should save as Integer' do
20
- klass.new(field => '12.3').send(field).should == 12.3
21
- end
22
- end
15
+ describe '.find_by_dvd_order' do
16
+ it 'should call new with specific params' do
17
+ model.should_receive(:get).with('123456789/series/1234/dvd/1/1/en.xml').and_return(double(response: true))
23
18
 
24
- shared_examples 'date mapping' do |field|
25
- it 'should save as Date' do
26
- klass.new(field => '2000-01-01').send(field).should == Date.new(2000, 1, 1)
19
+ model.find_by_dvd_order('1234', '1', '1')
27
20
  end
28
21
  end
29
22
 
30
- shared_examples 'time mapping' do |field|
31
- it 'should save as Time' do
32
- time = Time.now
33
- klass.new(field => time.to_i.to_s).send(field).to_i.should == time.to_i
34
- end
35
- end
23
+ describe '.find_by_absolute_order' do
24
+ it 'should call new with specific params' do
25
+ model.should_receive(:get).with('123456789/series/1234/absolute/1/en.xml').and_return(double(response: true))
36
26
 
37
- shared_examples 'array mapping' do |field|
38
- it 'should save as Array' do
39
- klass.new(field => '|John|Joe').send(field).should == ['John', 'Joe']
27
+ model.find_by_absolute_order('1234', '1')
40
28
  end
41
29
  end
42
30
 
43
- describe 'key mapping' do
44
- describe 'airsafter_season attribute' do
45
- include_examples 'mapping', :airsafter_season, :airs_after_season
46
- end
47
-
48
- describe 'airsbefore_episode attribute' do
49
- include_examples 'mapping', :airsbefore_episode, :airs_before_episode
50
- end
51
-
52
- describe 'airsbefore_season attribute' do
53
- include_examples 'mapping', :airsbefore_season, :airs_before_season
54
- end
55
-
56
- describe 'Combined_episodenumber attribute' do
57
- include_examples 'mapping', :Combined_episodenumber, :combined_episode_number
58
- end
59
-
60
- describe 'DVD_discid attribute' do
61
- include_examples 'mapping', :DVD_discid, :dvd_disc_id
62
- end
63
-
64
- describe 'DVD_episodenumber attribute' do
65
- include_examples 'mapping', :DVD_episodenumber, :dvd_episode_number
66
- end
67
-
68
- describe 'lastupdated attribute' do
69
- include_examples 'mapping', :lastupdated, :last_updated_at
70
- end
71
-
72
- describe 'seasonid attribute' do
73
- include_examples 'mapping', :seasonid, :season_id
74
- end
75
-
76
- describe 'series attribute' do
77
- include_examples 'mapping', :series, :series_id
78
- end
79
-
80
- describe 'seriesid attribute' do
81
- include_examples 'mapping', :seriesid, :series_id
82
- end
83
-
84
- describe 'thumb_added attribute' do
85
- include_examples 'mapping', :thumb_added, :thumb_added_at
86
- end
87
- end
88
-
89
- describe 'ceorce' do
90
- describe 'id attribute' do
91
- include_examples 'integer mapping', :id
92
- end
93
-
94
- describe 'absolute_number attribute' do
95
- include_examples 'integer mapping', :absolute_number
96
- end
97
-
98
- describe 'combined_episode_number attribute' do
99
- include_examples 'integer mapping', :combined_episode_number
100
- end
101
-
102
- describe 'combined_season attribute' do
103
- include_examples 'integer mapping', :combined_season
104
- end
105
-
106
- describe 'director attribute' do
107
- include_examples 'array mapping', :director
108
- end
109
-
110
- describe 'ep_img_flag attribute' do
111
- include_examples 'integer mapping', :ep_img_flag
112
- end
113
-
114
- describe 'episode_number attribute' do
115
- include_examples 'integer mapping', :episode_number
116
- end
117
-
118
- describe 'first_aired attribute' do
119
- include_examples 'date mapping', :first_aired
120
- end
121
-
122
- describe 'guest_stars attribute' do
123
- include_examples 'array mapping', :guest_stars
124
- end
125
-
126
- describe 'last_updated_at attribute' do
127
- include_examples 'time mapping', :last_updated_at
128
- end
129
-
130
- describe 'rating attribute' do
131
- include_examples 'float mapping', :rating
132
- end
133
-
134
- describe 'rating_count attribute' do
135
- include_examples 'integer mapping', :rating_count
136
- end
137
-
138
- describe 'season_id attribute' do
139
- include_examples 'integer mapping', :season_id
140
- end
141
-
142
- describe 'season_number attribute' do
143
- include_examples 'integer mapping', :season_number
144
- end
145
-
146
- describe 'series_id attribute' do
147
- include_examples 'integer mapping', :series_id
148
- end
149
-
150
- describe 'thumb_addedd_at attribute' do
151
- include_examples 'time mapping', :thumb_added_at
152
- end
153
-
154
- describe 'thumb_height attribute' do
155
- include_examples 'integer mapping', :thumb_height
156
- end
157
-
158
- describe 'thumb_width attribute' do
159
- include_examples 'integer mapping', :thumb_width
160
- end
161
-
162
- describe 'time attribute' do
163
- include_examples 'time mapping', :time
164
- end
31
+ describe '.find' do
32
+ it 'should call new with specific params' do
33
+ model.should_receive(:get).with('123456789/episodes/1234/en.xml').and_return(double(response: true))
165
34
 
166
- describe 'writer attribute' do
167
- include_examples 'array mapping', :writer
35
+ model.find('1234')
168
36
  end
169
37
  end
170
38
  end