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,39 +0,0 @@
1
- class ThetvdbApi::Request::Episode < ThetvdbApi::Request::Base
2
- include ThetvdbApi::Request::Module::SeriesUri
3
-
4
- def self.find_by_default_order(series_id, season, episode, language = ThetvdbApi::Configuration.language)
5
- new(find_by_default_order_path(series_id, season, episode, language))
6
- end
7
-
8
- def self.find_by_dvd_order(series_id, season, episode, language = ThetvdbApi::Configuration.language)
9
- new(find_by_dvd_order_path(series_id, season, episode, language))
10
- end
11
-
12
- def self.find_by_absolute_order(series_id, absolute, language = ThetvdbApi::Configuration.language)
13
- new(find_by_absolute_order_path(series_id, absolute, language))
14
- end
15
-
16
- def self.find(episode_id, language = ThetvdbApi::Configuration.language)
17
- new(find_path(episode_id, language))
18
- end
19
-
20
- def self.find_by_default_order_path(series_id, season, episode, language)
21
- "#{series_uri(series_id)}default/#{season}/#{episode}/#{language}.xml"
22
- end
23
-
24
- def self.find_by_dvd_order_path(series_id, season, episode, language)
25
- "#{series_uri(series_id)}dvd/#{season}/#{episode}/#{language}.xml"
26
- end
27
-
28
- def self.find_by_absolute_order_path(series_id, absolute, language)
29
- "#{series_uri(series_id)}absolute/#{absolute}/#{language}.xml"
30
- end
31
-
32
- def self.find_path(episode_id, language)
33
- "#{ThetvdbApi::Configuration.api_key}/episodes/#{episode_id}/#{language}.xml"
34
- end
35
-
36
- def result
37
- @result ||= object_response('Episode', ThetvdbApi::Episode)
38
- end
39
- end
@@ -1,17 +0,0 @@
1
- module ThetvdbApi
2
- module Request
3
- module Module
4
- module Find
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
- def find(series_id)
11
- new(find_path(series_id))
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module ThetvdbApi
2
- module Request
3
- module Module
4
- module SeriesUri
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
- def series_uri(series_id)
11
- "#{ThetvdbApi::Configuration.api_key}/series/#{series_id}/"
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,37 +0,0 @@
1
- class ThetvdbApi::Request::Search < ThetvdbApi::Request::Base
2
- def self.get_series(name, language = ThetvdbApi::Configuration.language)
3
- new('GetSeries.php', :series, :collection, seriesname: name, language: language)
4
- end
5
-
6
- def self.get_series_by_imdb_id(id, language = ThetvdbApi::Configuration.language)
7
- new('GetSeriesByRemoteID.php', :series, :object, imdbid: id, language: language)
8
- end
9
-
10
- def self.get_series_by_zap2it_id(id, language = ThetvdbApi::Configuration.language)
11
- new('GetSeriesByRemoteID.php', :series, :object, zap2it: id, language: language)
12
- end
13
-
14
- def self.get_episode_by_air_date(series_id, air_date, language = ThetvdbApi::Configuration.language)
15
- new('GetEpisodeByAirDate.php', :episode, :object, apikey: ThetvdbApi::Configuration.api_key, seriesid: series_id,
16
- airdate: air_date, language: language)
17
- end
18
-
19
- def initialize(uri, map_to, kind, options = {})
20
- @uri = uri
21
- @options = options
22
- @map_to = map_to
23
- @kind = kind
24
- end
25
-
26
- def request_options
27
- super(@options)
28
- end
29
-
30
- def result
31
- @result ||= if @kind == :collection
32
- collection_response(map_node[@map_to], map_class[@map_to])
33
- else
34
- object_response(map_node[@map_to], map_class[@map_to])
35
- end
36
- end
37
- end
@@ -1,48 +0,0 @@
1
- class ThetvdbApi::Request::Series < ThetvdbApi::Request::Base
2
- include ThetvdbApi::Request::Module::SeriesUri
3
-
4
- def self.find(series_id, language = ThetvdbApi::Configuration.language)
5
- new(find_path(series_id, language), :base)
6
- end
7
-
8
- def self.find_full(series_id, language = ThetvdbApi::Configuration.language)
9
- new(find_full_path(series_id, language), :full)
10
- end
11
-
12
- def self.find_path(series_id, language)
13
- "#{series_uri(series_id)}#{language}.xml"
14
- end
15
-
16
- def self.find_full_path(series_id, language)
17
- "#{series_uri(series_id)}all/#{language}.xml"
18
- end
19
-
20
- def initialize(uri, map_to)
21
- @uri = uri
22
- @map_to = map_to
23
- end
24
-
25
- def result
26
- @result ||= case @map_to
27
- when :base
28
- series_response
29
- when :full
30
- full_response
31
- end
32
- end
33
-
34
- def series_response
35
- object_response('Series', ThetvdbApi::Series)
36
- end
37
-
38
- def episodes_response
39
- collection_response('Episode', ThetvdbApi::Episode)
40
- end
41
-
42
- def full_response
43
- {
44
- series: series_response,
45
- episodes: episodes_response
46
- }
47
- end
48
- end
@@ -1,45 +0,0 @@
1
- class ThetvdbApi::Request::Update < ThetvdbApi::Request::Base
2
- def self.day
3
- new(:day)
4
- end
5
-
6
- def self.week
7
- new(:week)
8
- end
9
-
10
- def self.month
11
- new(:month)
12
- end
13
-
14
- def self.all
15
- new(:all)
16
- end
17
-
18
- def initialize(period)
19
- @period = period
20
- end
21
-
22
- def uri
23
- "#{ThetvdbApi::Configuration.api_key}/updates/updates_#{@period}.xml"
24
- end
25
-
26
- def series_response
27
- collection_response('Series', ThetvdbApi::Series)
28
- end
29
-
30
- def episodes_response
31
- collection_response('Episode', ThetvdbApi::Episode)
32
- end
33
-
34
- def banners_response
35
- collection_response('Banner', ThetvdbApi::Banner)
36
- end
37
-
38
- def result
39
- {
40
- series: series_response,
41
- episodes: episodes_response,
42
- banners: banners_response
43
- }
44
- end
45
- end
@@ -1,5 +0,0 @@
1
- class Array
2
- def self.coerce(value)
3
- value.to_s.split('|').reject { |element| element.empty? }
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- class Date
2
- def self.coerce(value)
3
- begin
4
- Date.parse(value)
5
- rescue => e
6
- nil
7
- end
8
- end
9
- end
@@ -1,5 +0,0 @@
1
- class Float
2
- def self.coerce(value)
3
- value.to_f
4
- end
5
- end
@@ -1,42 +0,0 @@
1
- module Hashie
2
- module Extensions
3
- module KeyReplace
4
- def self.included(base)
5
- base.send :extend, ClassMethods
6
- end
7
-
8
- def initialize(source_hash = nil, default = nil, &blk)
9
- source_hash = replace_keys(source_hash)
10
- super
11
- end
12
-
13
- def replace_keys(source_hash)
14
- source_hash.keys.each do |key|
15
- new_key = self.class.key_replace(key) || key.to_s.underscore
16
-
17
- if new_key != key
18
- source_hash[new_key] = source_hash[key]
19
- source_hash.delete(key)
20
- end
21
- end
22
- source_hash
23
- end
24
-
25
- module ClassMethods
26
- def replace_key(*attrs)
27
- @key_replaces ||= {}
28
- into = attrs.pop
29
- attrs.each { |key| @key_replaces[key] = into }
30
- end
31
-
32
- def key_replaces
33
- @key_replaces || {}
34
- end
35
-
36
- def key_replace(key)
37
- key_replaces[key.to_sym]
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def self.coerce(value)
3
- value.to_i
4
- end
5
- end
@@ -1,11 +0,0 @@
1
- class String
2
- def underscore
3
- word = self.dup
4
- word.gsub!(/::/, '/')
5
- word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
6
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
7
- word.tr!("-", "_")
8
- word.downcase!
9
- word
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- class Time
2
- def self.coerce(value)
3
- begin
4
- Time.parse(value)
5
- rescue
6
- Time.at(value.to_i)
7
- end
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- require 'thetvdb_api/utility/array'
2
- require 'thetvdb_api/utility/date'
3
- require 'thetvdb_api/utility/float'
4
- require 'thetvdb_api/utility/integer'
5
- require 'thetvdb_api/utility/string'
6
- require 'thetvdb_api/utility/time'
7
- require 'thetvdb_api/utility/hashie/extensions/key_replace'
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ThetvdbApi::Request::Actor do
4
- let(:klass) { ThetvdbApi::Request::Actor }
5
- let(:model) { klass.new('http://example.com') }
6
-
7
- describe '#find' do
8
- it 'should call new with specific params' do
9
- klass.stub(:find_path).and_return('PATH')
10
- klass.should_receive(:new).with('PATH')
11
-
12
- klass.find('1234')
13
- end
14
- end
15
-
16
- describe '#find_path' do
17
- it 'should return correct uri' do
18
- ThetvdbApi::Configuration.stub(:api_key).and_return('API_KEY')
19
-
20
- klass.find_path('1234').should == 'API_KEY/series/1234/actors.xml'
21
- end
22
- end
23
-
24
- describe '#result' do
25
- it 'should call object_response method' do
26
- model.should_receive(:collection_response).with('Actor', ThetvdbApi::Actor)
27
-
28
- model.result
29
- end
30
- end
31
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ThetvdbApi::Request::Banner do
4
- let(:klass) { ThetvdbApi::Request::Banner }
5
- let(:model) { klass.new('http://example.com') }
6
-
7
- describe '#find' do
8
- it 'should call new with specific params' do
9
- klass.stub(:find_path).and_return('PATH')
10
- klass.should_receive(:new).with('PATH')
11
-
12
- klass.find('1234')
13
- end
14
- end
15
-
16
- describe '#find_path' do
17
- it 'should return correct uri' do
18
- ThetvdbApi::Configuration.stub(:api_key).and_return('API_KEY')
19
-
20
- klass.find_path('1234').should == 'API_KEY/series/1234/banners.xml'
21
- end
22
- end
23
-
24
- describe '#result' do
25
- it 'should call object_response method' do
26
- model.should_receive(:collection_response).with('Banner', ThetvdbApi::Banner)
27
-
28
- model.result
29
- end
30
- end
31
- end
@@ -1,121 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ExampleRequestClass < ThetvdbApi::Request::Base
4
- end
5
-
6
- describe ThetvdbApi::Request::Base do
7
- let(:klass) { ExampleRequestClass }
8
- let(:model) { klass.new('test') }
9
-
10
- describe '#api_key' do
11
- it 'should call api_key from configuration' do
12
- ThetvdbApi::Configuration.should_receive(:api_key)
13
-
14
- klass.api_key
15
- end
16
- end
17
-
18
- describe '#response' do
19
- it 'should call get klass method' do
20
- klass.should_receive(:get)
21
- model.stub(:request_options).and_return({})
22
-
23
- model.response
24
- end
25
- end
26
-
27
- describe '#request_options' do
28
- it 'should return correct keys' do
29
- model.request_options({}).keys.sort.should == [:query, :base_uri].sort
30
- end
31
- end
32
-
33
- describe '#collection_response' do
34
- it 'should return filled array when condition is true' do
35
- model.stub(:response_condition?).and_return(true)
36
- model.stub(:array_mapped).and_return(['test'])
37
-
38
- model.collection_response('Series', OpenStruct).should_not be_empty
39
- end
40
-
41
- it 'should return empty array when condition is false' do
42
- model.stub(:response_condition?).and_return(false)
43
-
44
- model.collection_response('Series', OpenStruct).should be_empty
45
- end
46
- end
47
-
48
- describe '#object_response' do
49
- it 'should return object when condition is true' do
50
- model.stub(:response_condition?).and_return(true)
51
- model.stub_chain(:response, :[]).and_return({})
52
-
53
- model.object_response('Series', OpenStruct).class.should == OpenStruct
54
- end
55
-
56
- it 'should return nil when condition is false' do
57
- model.stub(:response_condition?).and_return(false)
58
-
59
- model.object_response('Series', OpenStruct).should be_nil
60
- end
61
- end
62
-
63
- describe '#response_condition?' do
64
- it 'should return true when code is 200 and return Data hash' do
65
- model.stub_chain(:response, :code).and_return 200
66
- model.stub_chain(:response, :[]).and_return({})
67
-
68
- model.response_condition?.should be_true
69
- end
70
-
71
- it 'should return false when code is different than 200' do
72
- model.stub_chain(:response, :code).and_return 400
73
- model.stub_chain(:response, :[]).and_return({})
74
-
75
- model.response_condition?.should be_false
76
- end
77
-
78
- it 'should return false when return blank response' do
79
- model.stub_chain(:response, :code).and_return 200
80
- model.stub_chain(:response, :[]).and_return('')
81
-
82
- model.response_condition?.should be_false
83
- end
84
- end
85
-
86
- describe '#array_normalize' do
87
- it 'should return Array when dig return Array' do
88
- model.stub(:dig).and_return(Array)
89
- model.array_normalize('Series').class.should == Array
90
- end
91
-
92
- it 'should return Array when dig return Hash' do
93
- model.stub(:dig).and_return(Hash)
94
- model.array_normalize('Series').class.should == Array
95
- end
96
- end
97
-
98
- describe '#array_mapped' do
99
- it 'should map Array elements to objects' do
100
- model.stub(:array_normalize).and_return([{ 'test' => 'value' }])
101
- model.array_mapped(OpenStruct, 'Series').first.class.should == OpenStruct
102
- end
103
- end
104
-
105
- describe '#dig' do
106
- it 'should dig to correct hash' do
107
- model.stub(:response).and_return({ 'Data' => { 'Series' => 'series value' } })
108
-
109
- model.dig('Series').should == 'series value'
110
- end
111
- end
112
-
113
- describe '#data' do
114
- it 'should return correct value' do
115
- model.stub(:response).and_return({ 'key' => 'value' })
116
- model.stub(:data_key).and_return('key')
117
-
118
- model.data.should == 'value'
119
- end
120
- end
121
- end