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
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbApi::Search do
4
+ let(:klass) { ThetvdbApi::Search }
5
+ let(:model) { klass.new(ThetvdbApi::Client.new(api_key: '123456789')) }
6
+
7
+ describe '.get_series' do
8
+ it 'should call get with specific params' do
9
+ model.should_receive(:get).with('GetSeries.php', seriesname: 'buffy', language: 'en').
10
+ and_return(double(response: true))
11
+
12
+ model.get_series('buffy', 'en')
13
+ end
14
+ end
15
+
16
+ describe '.get_series_by_imdb_id' do
17
+ it 'should call get with specific params' do
18
+ model.should_receive(:get).with('GetSeriesByRemoteID.php', imdbid: '1234', language: 'en').
19
+ and_return(double(response: true))
20
+
21
+ model.get_series_by_imdb_id('1234', 'en')
22
+ end
23
+ end
24
+
25
+ describe '.get_series_by_zap2it_id' do
26
+ it 'should call get with specific params' do
27
+ model.should_receive(:get).with('GetSeriesByRemoteID.php', zap2it: '1234', language: 'en').
28
+ and_return(double(response: true))
29
+
30
+ model.get_series_by_zap2it_id('1234', 'en')
31
+ end
32
+ end
33
+
34
+ describe '#get_episode_by_air_date' do
35
+ it 'should call get with specific params' do
36
+ model.should_receive(:get).with('GetEpisodeByAirDate.php', apikey: '123456789', seriesid: '1234',
37
+ airdate: '2000-01-01', language: 'en').and_return(double(response: true))
38
+
39
+ model.get_episode_by_air_date('1234', '2000-01-01', 'en')
40
+ end
41
+ end
42
+ end
@@ -2,109 +2,21 @@ require 'spec_helper'
2
2
 
3
3
  describe ThetvdbApi::Series do
4
4
  let(:klass) { ThetvdbApi::Series }
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 '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)
27
- end
28
- end
7
+ describe '.find' do
8
+ it 'should call get with specific params' do
9
+ model.should_receive(:get).with('123456789/series/1234/en.xml').and_return(double(response: true))
29
10
 
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
11
+ model.find('1234', 'en')
34
12
  end
35
13
  end
36
14
 
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']
40
- end
41
- end
42
-
43
- describe 'key mapping' do
44
- describe 'lastupdated attribute' do
45
- include_examples 'mapping', :lastupdated, :last_updated_at
46
- end
47
-
48
- describe 'seriesid attribute' do
49
- include_examples 'mapping', :seriesid, :series_id
50
- end
51
- end
52
-
53
- describe 'ceorce' do
54
- describe 'id attribute' do
55
- include_examples 'integer mapping', :id
56
- end
57
-
58
- describe 'actors attribute' do
59
- include_examples 'array mapping', :actors
60
- end
61
-
62
- describe 'added_at attribute' do
63
- include_examples 'time mapping', :added_at
64
- end
65
-
66
- describe 'added_by attribute' do
67
- include_examples 'integer mapping', :added_by
68
- end
69
-
70
- describe 'alias_names attribute' do
71
- include_examples 'array mapping', :alias_names
72
- end
73
-
74
- describe 'first_aired attribute' do
75
- include_examples 'date mapping', :first_aired
76
- end
77
-
78
- describe 'genre attribute' do
79
- include_examples 'array mapping', :genre
80
- end
81
-
82
- describe 'last_updated_at attribute' do
83
- include_examples 'time mapping', :last_updated_at
84
- end
85
-
86
- describe 'network_id attribute' do
87
- include_examples 'integer mapping', :network_id
88
- end
89
-
90
- describe 'rating attribute' do
91
- include_examples 'float mapping', :rating
92
- end
93
-
94
- describe 'rating_count attribute' do
95
- include_examples 'integer mapping', :rating_count
96
- end
97
-
98
- describe 'runtime attribute' do
99
- include_examples 'integer mapping', :runtime
100
- end
101
-
102
- describe 'series_id attribute' do
103
- include_examples 'integer mapping', :series_id
104
- end
15
+ describe '.find_full' do
16
+ it 'should call get with specific params' do
17
+ model.should_receive(:get).with('123456789/series/1234/all/en.xml').and_return(double(response: true))
105
18
 
106
- describe 'time attribute' do
107
- include_examples 'time mapping', :time
19
+ model.find_full('1234', 'en')
108
20
  end
109
21
  end
110
22
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbApi::Update do
4
+ let(:klass) { ThetvdbApi::Update }
5
+ let(:model) { klass.new(ThetvdbApi::Client.new(api_key: '123456789')) }
6
+
7
+ describe '.day' do
8
+ it 'should call get with specific params' do
9
+ model.should_receive(:get).with('123456789/updates/updates_day.xml').and_return(double(response: true))
10
+
11
+ model.day
12
+ end
13
+ end
14
+
15
+ describe '.week' do
16
+ it 'should call get with specific params' do
17
+ model.should_receive(:get).with('123456789/updates/updates_week.xml').and_return(double(response: true))
18
+
19
+ model.week
20
+ end
21
+ end
22
+
23
+ describe '.month' do
24
+ it 'should call get with specific params' do
25
+ model.should_receive(:get).with('123456789/updates/updates_month.xml').and_return(double(response: true))
26
+
27
+ model.month
28
+ end
29
+ end
30
+
31
+ describe '.all' do
32
+ it 'should call get with specific params' do
33
+ model.should_receive(:get).with('123456789/updates/updates_all.xml').and_return(double(response: true))
34
+
35
+ model.all
36
+ end
37
+ end
38
+ end
data/thetvdb_api.gemspec CHANGED
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'confiture', '>= 0.1.4'
22
22
  spec.add_dependency 'httparty', '>= 0.12.0'
23
- spec.add_runtime_dependency 'hashie', '>= 2.0.5'
24
23
 
25
24
  spec.add_development_dependency 'bundler', '~> 1.3'
26
25
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thetvdb_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Wawer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: confiture
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.12.0
41
- - !ruby/object:Gem::Dependency
42
- name: hashie
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: 2.0.5
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: 2.0.5
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -127,29 +113,16 @@ files:
127
113
  - lib/thetvdb_api/actor.rb
128
114
  - lib/thetvdb_api/banner.rb
129
115
  - lib/thetvdb_api/base.rb
116
+ - lib/thetvdb_api/client.rb
130
117
  - lib/thetvdb_api/configuration.rb
131
118
  - lib/thetvdb_api/episode.rb
132
- - lib/thetvdb_api/request/actor.rb
133
- - lib/thetvdb_api/request/banner.rb
134
- - lib/thetvdb_api/request/base.rb
135
- - lib/thetvdb_api/request/episode.rb
136
- - lib/thetvdb_api/request/module/find.rb
137
- - lib/thetvdb_api/request/module/series_uri.rb
138
- - lib/thetvdb_api/request/search.rb
139
- - lib/thetvdb_api/request/series.rb
140
- - lib/thetvdb_api/request/update.rb
119
+ - lib/thetvdb_api/search.rb
141
120
  - lib/thetvdb_api/series.rb
142
- - lib/thetvdb_api/utility.rb
143
- - lib/thetvdb_api/utility/array.rb
144
- - lib/thetvdb_api/utility/date.rb
145
- - lib/thetvdb_api/utility/float.rb
146
- - lib/thetvdb_api/utility/hashie/extensions/key_replace.rb
147
- - lib/thetvdb_api/utility/integer.rb
148
- - lib/thetvdb_api/utility/string.rb
149
- - lib/thetvdb_api/utility/time.rb
121
+ - lib/thetvdb_api/update.rb
150
122
  - lib/thetvdb_api/version.rb
151
123
  - spec/integrations/actor_spec.rb
152
124
  - spec/integrations/banner_spec.rb
125
+ - spec/integrations/client_spec.rb
153
126
  - spec/integrations/episode_spec.rb
154
127
  - spec/integrations/search_spec.rb
155
128
  - spec/integrations/series_spec.rb
@@ -158,23 +131,13 @@ files:
158
131
  - spec/support/thetvdb_api.rb
159
132
  - spec/thetvdb_api/actor_spec.rb
160
133
  - spec/thetvdb_api/banner_spec.rb
134
+ - spec/thetvdb_api/base_spec.rb
135
+ - spec/thetvdb_api/client_spec.rb
161
136
  - spec/thetvdb_api/configuration_spec.rb
162
137
  - spec/thetvdb_api/episode_spec.rb
163
- - spec/thetvdb_api/request/actor_spec.rb
164
- - spec/thetvdb_api/request/banner_spec.rb
165
- - spec/thetvdb_api/request/base_spec.rb
166
- - spec/thetvdb_api/request/episode_spec.rb
167
- - spec/thetvdb_api/request/module/series_uri_spec.rb
168
- - spec/thetvdb_api/request/search_spec.rb
169
- - spec/thetvdb_api/request/series_spec.rb
170
- - spec/thetvdb_api/request/update_spec.rb
138
+ - spec/thetvdb_api/search_spec.rb
171
139
  - spec/thetvdb_api/series_spec.rb
172
- - spec/thetvdb_api/utility/array_spec.rb
173
- - spec/thetvdb_api/utility/date_spec.rb
174
- - spec/thetvdb_api/utility/float_spec.rb
175
- - spec/thetvdb_api/utility/integer_spec.rb
176
- - spec/thetvdb_api/utility/string_spec.rb
177
- - spec/thetvdb_api/utility/time_spec.rb
140
+ - spec/thetvdb_api/update_spec.rb
178
141
  - thetvdb_api.gemspec
179
142
  homepage: http://github.com/wafcio/thetvdb_api
180
143
  licenses:
@@ -203,6 +166,7 @@ summary: Ruby client for thetvdb.com API
203
166
  test_files:
204
167
  - spec/integrations/actor_spec.rb
205
168
  - spec/integrations/banner_spec.rb
169
+ - spec/integrations/client_spec.rb
206
170
  - spec/integrations/episode_spec.rb
207
171
  - spec/integrations/search_spec.rb
208
172
  - spec/integrations/series_spec.rb
@@ -211,20 +175,10 @@ test_files:
211
175
  - spec/support/thetvdb_api.rb
212
176
  - spec/thetvdb_api/actor_spec.rb
213
177
  - spec/thetvdb_api/banner_spec.rb
178
+ - spec/thetvdb_api/base_spec.rb
179
+ - spec/thetvdb_api/client_spec.rb
214
180
  - spec/thetvdb_api/configuration_spec.rb
215
181
  - spec/thetvdb_api/episode_spec.rb
216
- - spec/thetvdb_api/request/actor_spec.rb
217
- - spec/thetvdb_api/request/banner_spec.rb
218
- - spec/thetvdb_api/request/base_spec.rb
219
- - spec/thetvdb_api/request/episode_spec.rb
220
- - spec/thetvdb_api/request/module/series_uri_spec.rb
221
- - spec/thetvdb_api/request/search_spec.rb
222
- - spec/thetvdb_api/request/series_spec.rb
223
- - spec/thetvdb_api/request/update_spec.rb
182
+ - spec/thetvdb_api/search_spec.rb
224
183
  - spec/thetvdb_api/series_spec.rb
225
- - spec/thetvdb_api/utility/array_spec.rb
226
- - spec/thetvdb_api/utility/date_spec.rb
227
- - spec/thetvdb_api/utility/float_spec.rb
228
- - spec/thetvdb_api/utility/integer_spec.rb
229
- - spec/thetvdb_api/utility/string_spec.rb
230
- - spec/thetvdb_api/utility/time_spec.rb
184
+ - spec/thetvdb_api/update_spec.rb
@@ -1,18 +0,0 @@
1
- class ThetvdbApi::Request::Actor < ThetvdbApi::Request::Base
2
- include ThetvdbApi::Request::Module::Find
3
- include ThetvdbApi::Request::Module::SeriesUri
4
-
5
- def self.find_path(series_id)
6
- "#{series_uri(series_id)}actors.xml"
7
- end
8
-
9
- def result
10
- @result ||= collection_response('Actor', ThetvdbApi::Actor)
11
- end
12
-
13
- private
14
-
15
- def data_key
16
- 'Actors'
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- class ThetvdbApi::Request::Banner < ThetvdbApi::Request::Base
2
- include ThetvdbApi::Request::Module::Find
3
- include ThetvdbApi::Request::Module::SeriesUri
4
-
5
- def self.find_path(series_id)
6
- "#{series_uri(series_id)}banners.xml"
7
- end
8
-
9
- def result
10
- @result ||= collection_response('Banner', ThetvdbApi::Banner)
11
- end
12
-
13
- private
14
-
15
- def data_key
16
- 'Banners'
17
- end
18
- end
@@ -1,74 +0,0 @@
1
- require 'httparty'
2
-
3
- class ThetvdbApi::Request::Base
4
- include HTTParty
5
-
6
- attr_reader :uri
7
-
8
- def self.api_key
9
- ThetvdbApi::Configuration.api_key
10
- end
11
-
12
- def initialize(uri)
13
- @uri = uri
14
- end
15
-
16
- def response
17
- @response ||= self.class.get(uri, request_options)
18
- end
19
-
20
- def request_options(options = {})
21
- {
22
- query: options,
23
- base_uri: ThetvdbApi::Configuration.api_url
24
- }
25
- end
26
-
27
- def collection_response(key, klass)
28
- response_condition? ? array_mapped(klass, key) : []
29
- end
30
-
31
- def object_response(key, klass)
32
- response_condition? ? klass.new(data[key]) : nil
33
- end
34
-
35
- def response_condition?
36
- response.code == 200 && data.is_a?(Hash)
37
- end
38
-
39
- def array_normalize(key)
40
- dig(key).is_a?(Array) ? dig(key) : [dig(key)]
41
- end
42
-
43
- def array_mapped(klass, key)
44
- array_normalize(key).map { |data| klass.new(data) }
45
- end
46
-
47
- def dig(key)
48
- data[key]
49
- end
50
-
51
- def data
52
- response[data_key]
53
- end
54
-
55
- private
56
-
57
- def data_key
58
- 'Data'
59
- end
60
-
61
- def map_node
62
- {
63
- series: 'Series',
64
- episode: 'Episode'
65
- }
66
- end
67
-
68
- def map_class
69
- {
70
- series: ThetvdbApi::Series,
71
- episode: ThetvdbApi::Episode
72
- }
73
- end
74
- end