thetvdb_api 0.2.1 → 0.2.2

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +36 -81
  4. data/lib/thetvdb_api/actor.rb +15 -1
  5. data/lib/thetvdb_api/banner.rb +15 -1
  6. data/lib/thetvdb_api/base.rb +4 -4
  7. data/lib/thetvdb_api/episode.rb +50 -5
  8. data/lib/thetvdb_api/response/actors.rb +7 -0
  9. data/lib/thetvdb_api/response/banners.rb +7 -0
  10. data/lib/thetvdb_api/response/collection.rb +9 -0
  11. data/lib/thetvdb_api/response/episode.rb +5 -0
  12. data/lib/thetvdb_api/response/full_series.rb +21 -0
  13. data/lib/thetvdb_api/response/search_multiple_episode.rb +7 -0
  14. data/lib/thetvdb_api/response/search_multiple_series.rb +7 -0
  15. data/lib/thetvdb_api/response/search_series.rb +5 -0
  16. data/lib/thetvdb_api/response/series.rb +5 -0
  17. data/lib/thetvdb_api/response/update.rb +31 -0
  18. data/lib/thetvdb_api/response.rb +30 -8
  19. data/lib/thetvdb_api/search.rb +50 -4
  20. data/lib/thetvdb_api/series.rb +28 -2
  21. data/lib/thetvdb_api/update.rb +24 -8
  22. data/lib/thetvdb_api/version.rb +1 -1
  23. data/lib/thetvdb_api.rb +11 -1
  24. data/spec/integrations/actor_spec.rb +1 -1
  25. data/spec/integrations/banner_spec.rb +1 -1
  26. data/spec/integrations/client_spec.rb +15 -15
  27. data/spec/integrations/episode_spec.rb +4 -4
  28. data/spec/integrations/search_spec.rb +4 -4
  29. data/spec/integrations/series_spec.rb +2 -2
  30. data/spec/integrations/update_spec.rb +4 -4
  31. data/spec/spec_helper.rb +0 -21
  32. data/spec/units/actor_spec.rb +49 -0
  33. data/spec/units/banner_spec.rb +49 -0
  34. data/spec/units/episode_spec.rb +167 -0
  35. data/spec/units/response/actors_spec.rb +15 -0
  36. data/spec/units/response/banners_spec.rb +15 -0
  37. data/spec/units/response/collection_spec.rb +38 -0
  38. data/spec/units/response/episode_spec.rb +15 -0
  39. data/spec/units/response/full_series_spec.rb +51 -0
  40. data/spec/units/response/search_multiple_episode_spec.rb +15 -0
  41. data/spec/units/response/search_multiple_series_spec.rb +15 -0
  42. data/spec/units/response/search_series_spec.rb +15 -0
  43. data/spec/units/response/series_spec.rb +15 -0
  44. data/spec/units/response/update_spec.rb +79 -0
  45. data/spec/units/response_spec.rb +100 -0
  46. data/spec/units/search_spec.rb +178 -0
  47. data/spec/units/series_spec.rb +92 -0
  48. data/spec/units/update_spec.rb +178 -0
  49. data/thetvdb_api.gemspec +1 -1
  50. metadata +53 -49
  51. data/lib/thetvdb_api/mappers/actor.rb +0 -17
  52. data/lib/thetvdb_api/mappers/actors.rb +0 -10
  53. data/lib/thetvdb_api/mappers/banner.rb +0 -32
  54. data/lib/thetvdb_api/mappers/banners.rb +0 -10
  55. data/lib/thetvdb_api/mappers/base_mapper.rb +0 -13
  56. data/lib/thetvdb_api/mappers/episode.rb +0 -35
  57. data/lib/thetvdb_api/mappers/full_series.rb +0 -12
  58. data/lib/thetvdb_api/mappers/search_episode.rb +0 -10
  59. data/lib/thetvdb_api/mappers/search_series/series.rb +0 -25
  60. data/lib/thetvdb_api/mappers/search_series.rb +0 -10
  61. data/lib/thetvdb_api/mappers/series.rb +0 -40
  62. data/lib/thetvdb_api/mappers/update/banner.rb +0 -19
  63. data/lib/thetvdb_api/mappers/update/element.rb +0 -10
  64. data/lib/thetvdb_api/mappers/update/episode.rb +0 -8
  65. data/lib/thetvdb_api/mappers/update/series.rb +0 -8
  66. data/lib/thetvdb_api/mappers/update.rb +0 -14
  67. data/spec/thetvdb_api/actor_spec.rb +0 -21
  68. data/spec/thetvdb_api/banner_spec.rb +0 -21
  69. data/spec/thetvdb_api/episode_spec.rb +0 -63
  70. data/spec/thetvdb_api/mappers/actor_spec.rb +0 -15
  71. data/spec/thetvdb_api/mappers/banner_spec.rb +0 -31
  72. data/spec/thetvdb_api/mappers/search_series/series_spec.rb +0 -15
  73. data/spec/thetvdb_api/mappers/series_spec.rb +0 -31
  74. data/spec/thetvdb_api/mappers/update/banner_spec.rb +0 -15
  75. data/spec/thetvdb_api/response_spec.rb +0 -60
  76. data/spec/thetvdb_api/search_spec.rb +0 -63
  77. data/spec/thetvdb_api/series_spec.rb +0 -35
  78. data/spec/thetvdb_api/update_spec.rb +0 -63
  79. /data/spec/{thetvdb_api → units}/base_spec.rb +0 -0
  80. /data/spec/{thetvdb_api → units}/client_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3908d0d6811769c9845cbef26aee2de5adb3059e
4
- data.tar.gz: 29b3329554f2171c9e2c98fdc0c3b731cc7f3728
3
+ metadata.gz: 1dcc91a8222745749a555d5d963c6eaad2d2acad
4
+ data.tar.gz: 5eec6981bd50bac65fa2c0e2e6d051b4e0187249
5
5
  SHA512:
6
- metadata.gz: dfea95ba9b1391d05a56e5ed61a7ecc8a1f0eb0d8f3dac102a89b52cb7e95b89b1c528d303562b7bea59f823990a0439cb039cbc4195099f9843fc0fa1e56e83
7
- data.tar.gz: 5ef3fa81e626b31cf682a52396271a1640bf5b361d7b4463a1e2e5a5501e26d792e49864a8b93102c095fa27d247c5600eac370c7e24e29d3b8e48cb7a3683c6
6
+ metadata.gz: a3916560f299474f0964c79bde37783883793db4c7f8476510ef31e1515f00d1fd232e67b33ef807c6c4d337b6634d6a869b708f45b5a3d63c0f4596c49b9e08
7
+ data.tar.gz: 6594ba567f59510b6cb138fa7db45549c5261c5c892134aa10206730aa997c2e450faae0bddcdd0c85749d8a54176f11c14e2f41e05319ad7cbf7c5832bb62a9
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
- script: 'bundle exec rspec spec/thetvdb_api'
2
+ script: 'bundle exec rspec spec/units'
3
3
  rvm:
4
4
  - 2.0.0
data/README.md CHANGED
@@ -38,124 +38,79 @@ Search series by name
38
38
 
39
39
  ```ruby
40
40
  client = ThetvdbApi::Client.new
41
- client.search.get_series('buffy')
42
- client.search.get_series_by_imdb_id('...')
43
- client.search.get_series_by_zap2it_id('...')
44
- client.search.get_episode('123', air_date)
41
+ client.search.get_series('buffy', options = {})
42
+ client.search.get_series_url('buffy', options = {}) # return only full url
43
+ client.search.get_series_by_imdb_id(id, options = {})
44
+ client.search.get_series_by_imdb_id_url(id, options = {}) # return only full url
45
+ client.search.get_series_by_zap2it_id(id)
46
+ client.search.get_series_by_zap2it_id_url(id, options = {}) # return only full url
47
+ client.search.get_episode('123', air_date, options = {})
48
+ client.search.get_episode_url('123', air_date, options = {}) # return only full url
45
49
  ```
46
50
 
47
51
  Search series by id
48
52
 
49
53
  ```ruby
50
54
  client = ThetvdbApi::Client.new
51
- client.series.find('123')
52
- client.series.find_full('123')
55
+ client.series.find('123', options = {})
56
+ client.series.find_url('123', options = {}) # return only full url
57
+ client.series.find_full('123', options = {})
58
+ client.series.find_full_url('123', options = {}) # return only full url
53
59
  ```
54
60
 
55
61
  Return series actors
56
62
 
57
63
  ```ruby
58
64
  client = ThetvdbApi::Client.new
59
- client.actor.all(series_id)
65
+ client.actor.all(series_id, options = {})
66
+ client.actor.all_url(series_id, options = {}) # return only full url
60
67
  ```
61
68
 
62
69
  Return series banners
63
70
 
64
71
  ```ruby
65
72
  client = ThetvdbApi::Client.new
66
- client.banner.all(series_id)
73
+ client.banner.all(series_id, options = {})
74
+ client.banner.all_url(series_id, options = {}) # return only full url
67
75
  ```
68
76
 
69
77
  Return series episode
70
78
 
71
79
  ```ruby
72
80
  client = ThetvdbApi::Client.new
73
- client.episode.find_by_default_order(series_id, season, episode)
74
- client.episode.find_by_dvd_order(series_id, season, episode)
75
- client.episode.find_by_absolute_order(series_id, absolute)
76
- client.episode.find(episode_id)
81
+ client.episode.find_by_default_order(series_id, season, episode, options = {})
82
+ client.episode.find_by_default_order_url(series_id, season, episode, options = {}) # return only full url
83
+ client.episode.find_by_dvd_order(series_id, season, episode, options = {})
84
+ client.episode.find_by_dvd_order_url(series_id, season, episode, options = {}) # return only full url
85
+ client.episode.find_by_absolute_order(series_id, absolute, options = {})
86
+ client.episode.find_by_absolute_order_url(series_id, absolute, options = {}) # return only full url
87
+ client.episode.find(episode_id, options = {})
88
+ client.episode.find_url(episode_id, options = {}) # return only full url
77
89
  ```
78
90
 
79
91
  Get updates
80
92
 
81
93
  ```ruby
82
94
  client = ThetvdbApi::Client.new
83
- client.update.day
84
- client.update.week
85
- client.update.month
86
- client.update.all
95
+ client.update.day(options = {})
96
+ client.update.day_url(options = {}) # return only full url
97
+ client.update.week(options = {})
98
+ client.update.week_url(options = {}) # return only full url
99
+ client.update.month(options = {})
100
+ client.update.month_url(options = {}) # return only full url
101
+ client.update.all(options = {})
102
+ client.update.all_url(options = {}) # return only full url
87
103
  ```
88
104
 
89
- ThetvdbApi return response class with pure xml (in body method) string fetched by Faraday, but it can be automatically mapped to Object. I have prepared some class for it which using happymapper gem. You should pass mapper options at the end of method arguments.
105
+ ThetvdbApi default return response class with pure xml (in body method) string fetched by Faraday. You can pass
90
106
 
91
107
  ```ruby
92
- require 'thetvdb_api/mappers/update'
93
- client = ThetvdbApi::Client.new
94
- client.update.day(mapper: ThetvdbApi::Mappers::Update)
108
+ mapping: true
95
109
  ```
96
110
 
97
- ## Mappers for:
98
-
99
- ### Search
100
- ```ruby
101
- require 'thetvdb_api/mappers/search_series'
102
- client = ThetvdbApi::Client.new
103
- client.search.get_series('buffy', mapper: ThetvdbApi::Mappers::SearchSeries)
104
- client.search.get_series_by_imdb_id('...', mapper: ThetvdbApi::Mappers::SearchSeries)
105
- client.search.get_series_by_zap2it_id('...', mapper: ThetvdbApi::Mappers::SearchSeries)
106
- ```
107
-
108
- ```ruby
109
- require 'thetvdb_api/mappers/search_episode'
110
- client = ThetvdbApi::Client.new
111
- client.search.get_episode('123', air_date, mapper: ThetvdbApi::Mappers::SearchEpisode)
112
- ```
113
-
114
- ### Series
115
- ```ruby
116
- require 'thetvdb_api/mappers/series'
117
- client = ThetvdbApi::Client.new
118
- client.series.find('123', mapper: ThetvdbApi::Mappers::Series)
119
- ```
120
-
121
- ```ruby
122
- require 'thetvdb_api/mappers/full_series'
123
- client = ThetvdbApi::Client.new
124
- client.series.find_full('123', mapper: ThetvdbApi::Mappers::FullSeries)
125
- ```
126
-
127
- ### Actors
128
- ```ruby
129
- require 'thetvdb_api/mappers/actors'
130
- client = ThetvdbApi::Client.new
131
- client.actor.all(series_id, mapper: ThetvdbApi::Mappers::Actors)
132
- ```
133
-
134
- ### Banners
135
- ```ruby
136
- require 'thetvdb_api/mappers/banners'
137
- client = ThetvdbApi::Client.new
138
- client.banner.all(series_id, mapper: ThetvdbApi::Mappers::Banners)
139
- ```
140
-
141
- ### Episodes
142
- ```ruby
143
- require 'thetvdb_api/mappers/episode'
144
- client = ThetvdbApi::Client.new
145
- client.episode.find_by_default_order(series_id, season, episode, mapper: ThetvdbApi::Mappers::Episode)
146
- client.episode.find_by_dvd_order(series_id, season, episode, mapper: ThetvdbApi::Mappers::Episode)
147
- client.episode.find_by_absolute_order(series_id, absolute, mapper: ThetvdbApi::Mappers::Episode)
148
- client.episode.find(episode_id, mapper: ThetvdbApi::Mappers::Episode)
149
- ```
150
-
151
- ### Updates
152
- ```ruby
153
- require 'thetvdb_api/mappers/update'
154
- client = ThetvdbApi::Client.new
155
- client.update.day(mapper: ThetvdbApi::Mappers::Update)
156
- ```
111
+ options, and ThetvdbApi will return hash/array objects.
157
112
 
158
- You can write own mappers which parse xml and convert it to hash. Remember that your class must have "parse" class method.
113
+ ThetvdbApi give you chance to write own mapper where mapping preformance could be better.
159
114
 
160
115
  ## Contributing
161
116
 
@@ -1,5 +1,19 @@
1
1
  class ThetvdbApi::Actor < ThetvdbApi::Base
2
2
  def find(series_id, options = {})
3
- get("#{series_uri}/actors.xml").params({ series_id: series_id }.merge(options)).response
3
+ find_get_with_params(series_id, options).response(ThetvdbApi::Response::Actors)
4
+ end
5
+
6
+ def find_url(series_id)
7
+ find_get_with_params(series_id).url
8
+ end
9
+
10
+ def find_get_with_params(series_id, options = {})
11
+ get(find_path).params({ series_id: series_id }.merge(options))
12
+ end
13
+
14
+ private
15
+
16
+ def find_path
17
+ "#{series_uri}/actors.xml"
4
18
  end
5
19
  end
@@ -1,5 +1,19 @@
1
1
  class ThetvdbApi::Banner < ThetvdbApi::Base
2
2
  def find(series_id, options = {})
3
- get("#{series_uri}/banners.xml").params({ series_id: series_id }.merge(options)).response
3
+ find_get_with_params(series_id, options).response(ThetvdbApi::Response::Banners)
4
+ end
5
+
6
+ def find_url(series_id)
7
+ find_get_with_params(series_id).url
8
+ end
9
+
10
+ def find_get_with_params(series_id, options = {})
11
+ get(find_path).params({ series_id: series_id }.merge(options))
12
+ end
13
+
14
+ private
15
+
16
+ def find_path
17
+ "#{series_uri}/banners.xml"
4
18
  end
5
19
  end
@@ -5,7 +5,7 @@ class ThetvdbApi::Base
5
5
  def initialize(client)
6
6
  @client = client
7
7
  @params = {}
8
- @mapper = nil
8
+ @mapping = false
9
9
  end
10
10
 
11
11
  def connection
@@ -18,14 +18,14 @@ class ThetvdbApi::Base
18
18
  end
19
19
 
20
20
  def params(options)
21
- @mapper = options.delete(:mapper)
21
+ @mapping = options.delete(:mapping)
22
22
  @params = { language: @client.language }.merge(options)
23
23
  self
24
24
  end
25
25
 
26
- def response
26
+ def response(klass = ThetvdbApi::Response)
27
27
  assert_uri_template
28
- ThetvdbApi::Response.new(connection.get(uri, @options), @mapper)
28
+ klass.new(connection.get(uri, @params), @mapping)
29
29
  end
30
30
 
31
31
  def prepare_uri
@@ -3,21 +3,66 @@ class ThetvdbApi::Episode < ThetvdbApi::Base
3
3
  find_by_order('default', series_id, season, episode, options)
4
4
  end
5
5
 
6
+ def find_by_default_order_url(series_id, season, episode, options = {})
7
+ find_by_order_url('default', series_id, season, episode, options)
8
+ end
9
+
6
10
  def find_by_dvd_order(series_id, season, episode, options = {})
7
11
  find_by_order('dvd', series_id, season, episode, options)
8
12
  end
9
13
 
14
+ def find_by_dvd_order_url(series_id, season, episode, options = {})
15
+ find_by_order_url('dvd', series_id, season, episode, options)
16
+ end
17
+
10
18
  def find_by_absolute_order(series_id, absolute, options = {})
11
- get("#{series_uri}/absolute/{absolute}/{language}.xml").
12
- params({ series_id: series_id, absolute: absolute }.merge(options)).response
19
+ find_by_absolute_order_get_with_params(series_id, absolute, options).response(ThetvdbApi::Response::Episode)
20
+ end
21
+
22
+ def find_by_absolute_order_url(series_id, absolute, options = {})
23
+ find_by_absolute_order_get_with_params(series_id, absolute, options).url
24
+ end
25
+
26
+ def find_by_absolute_order_get_with_params(series_id, absolute, options)
27
+ get(find_by_absolute_order_path).params({ series_id: series_id, absolute: absolute }.merge(options))
13
28
  end
14
29
 
15
30
  def find(episode_id, options = {})
16
- get("{api_key}/episodes/{episode_id}/{language}.xml").params({ episode_id: episode_id }.merge(options)).response
31
+ find_get_with_params(episode_id, options).response(ThetvdbApi::Response::Episode)
32
+ end
33
+
34
+ def find_url(episode_id, options = {})
35
+ find_get_with_params(episode_id, options).url
36
+ end
37
+
38
+ def find_get_with_params(episode_id, options)
39
+ get(find_path).params({ episode_id: episode_id }.merge(options))
17
40
  end
18
41
 
19
42
  def find_by_order(order, series_id, season, episode, options)
20
- get("#{series_uri}/{order}/{season}/{episode}/{language}.xml").
21
- params({ series_id: series_id, season: season, episode: episode, order: order }.merge(options)).response
43
+ find_by_order_get_with_params(order, series_id, season, episode, options).response(ThetvdbApi::Response::Episode)
44
+ end
45
+
46
+ def find_by_order_url(order, series_id, season, episode, options)
47
+ find_by_order_get_with_params(order, series_id, season, episode, options).url
48
+ end
49
+
50
+ def find_by_order_get_with_params(order, series_id, season, episode, options)
51
+ get(find_by_order_path).
52
+ params({ series_id: series_id, season: season, episode: episode, order: order }.merge(options))
53
+ end
54
+
55
+ private
56
+
57
+ def find_by_absolute_order_path
58
+ "#{series_uri}/absolute/{absolute}/{language}.xml"
59
+ end
60
+
61
+ def find_path
62
+ '{api_key}/episodes/{episode_id}/{language}.xml'
63
+ end
64
+
65
+ def find_by_order_path
66
+ "#{series_uri}/{order}/{season}/{episode}/{language}.xml"
22
67
  end
23
68
  end
@@ -0,0 +1,7 @@
1
+ class ThetvdbApi::Response::Actors < ThetvdbApi::Response
2
+ include ThetvdbApi::Response::Collection
3
+
4
+ def xml_parse
5
+ multi_xml_parse.fetch('Actors', {}).fetch('Actor', [])
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class ThetvdbApi::Response::Banners < ThetvdbApi::Response
2
+ include ThetvdbApi::Response::Collection
3
+
4
+ def xml_parse
5
+ multi_xml_parse.fetch('Banners', {}).fetch('Banner', [])
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module ThetvdbApi::Response::Collection
2
+ def body
3
+ @body ||= if @mapping
4
+ parse.is_a?(Array) ? parse : [parse]
5
+ else
6
+ @faraday_response.body
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class ThetvdbApi::Response::Episode < ThetvdbApi::Response
2
+ def xml_parse
3
+ multi_xml_parse.fetch('Episode', {})
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ class ThetvdbApi::Response::FullSeries < ThetvdbApi::Response
2
+ def parse
3
+ unless @parse
4
+ @parse = xml_parse
5
+ episode_normalize
6
+ end
7
+ @parse
8
+ end
9
+
10
+ def xml_parse
11
+ multi_xml_parse.fetch('Data', {})
12
+ end
13
+
14
+ def episode_normalize
15
+ normalize('Episode')
16
+ end
17
+
18
+ def normalize(key)
19
+ @parse[key] = [@parse[key]] if @parse[key].is_a?(Hash)
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ class ThetvdbApi::Response::SearchMultipleEpisode < ThetvdbApi::Response
2
+ include ThetvdbApi::Response::Collection
3
+
4
+ def xml_parse
5
+ multi_xml_parse.fetch('Data', {}).fetch('Episode', [])
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class ThetvdbApi::Response::SearchMultipleSeries < ThetvdbApi::Response
2
+ include ThetvdbApi::Response::Collection
3
+
4
+ def xml_parse
5
+ multi_xml_parse.fetch('Data', {}).fetch('Series', [])
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class ThetvdbApi::Response::SearchSeries < ThetvdbApi::Response
2
+ def xml_parse
3
+ multi_xml_parse.fetch('Data', {}).fetch('Series', {})
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ThetvdbApi::Response::Series < ThetvdbApi::Response
2
+ def xml_parse
3
+ multi_xml_parse.fetch('Series', {})
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ class ThetvdbApi::Response::Update < ThetvdbApi::Response
2
+ def parse
3
+ unless @parse
4
+ @parse = xml_parse
5
+ series_normalize
6
+ episode_normalize
7
+ banner_normalize
8
+ end
9
+ @parse
10
+ end
11
+
12
+ def xml_parse
13
+ multi_xml_parse.fetch('Data', {})
14
+ end
15
+
16
+ def series_normalize
17
+ normalize('Series')
18
+ end
19
+
20
+ def episode_normalize
21
+ normalize('Episode')
22
+ end
23
+
24
+ def banner_normalize
25
+ normalize('Banner')
26
+ end
27
+
28
+ def normalize(key)
29
+ @parse[key] = [@parse[key]] if @parse[key].is_a?(Hash)
30
+ end
31
+ end
@@ -1,11 +1,9 @@
1
+ require 'multi_xml'
2
+
1
3
  class ThetvdbApi::Response
2
- def initialize(faraday_response, mapper = nil)
4
+ def initialize(faraday_response, mapping = false)
3
5
  @faraday_response = faraday_response
4
- @mapper = mapper
5
- end
6
-
7
- def mapper
8
- @mapper
6
+ @mapping = mapping
9
7
  end
10
8
 
11
9
  def env
@@ -21,10 +19,34 @@ class ThetvdbApi::Response
21
19
  end
22
20
 
23
21
  def body
24
- @body ||= @mapper ? @mapper.parse(@faraday_response.body) : @faraday_response.body
22
+ @body ||= @mapping ? parse : @faraday_response.body
25
23
  end
26
24
 
27
25
  def inspect
28
- "<ThetvdbApi::Response body=#{body.inspect}, mapper=#{mapper.inspect}>"
26
+ body.inspect
27
+ end
28
+
29
+ def [](key)
30
+ parse[key]
31
+ end
32
+
33
+ def []=(key, value)
34
+ parse[key] = value
35
+ end
36
+
37
+ def each(&block)
38
+ parse.each(&block)
39
+ end
40
+
41
+ def multi_xml_parse
42
+ MultiXml.parse(@faraday_response.body)
43
+ end
44
+
45
+ def xml_parse
46
+ multi_xml_parse
47
+ end
48
+
49
+ def parse
50
+ @parse ||= xml_parse
29
51
  end
30
52
  end
@@ -1,17 +1,63 @@
1
1
  class ThetvdbApi::Search < ThetvdbApi::Base
2
2
  def get_series(name, options = {})
3
- get('GetSeries.php').params({ seriesname: name }.merge(options)).response
3
+ get_series_get_with_params(name, options).response(ThetvdbApi::Response::SearchMultipleSeries)
4
+ end
5
+
6
+ def get_series_url(name, options = {})
7
+ get_series_get_with_params(name, options).url
8
+ end
9
+
10
+ def get_series_get_with_params(name, options)
11
+ get(get_series_path).params({ seriesname: name }.merge(options))
4
12
  end
5
13
 
6
14
  def get_series_by_imdb_id(id, options = {})
7
- get('GetSeriesByRemoteID.php').params({ imdbid: id }.merge(options)).response
15
+ get_series_by_imdb_id_get_with_params(id, options).response(ThetvdbApi::Response::SearchSeries)
16
+ end
17
+
18
+ def get_series_by_imdb_id_url(id, options = {})
19
+ get_series_by_imdb_id_get_with_params(id, options).url
20
+ end
21
+
22
+ def get_series_by_imdb_id_get_with_params(id, options)
23
+ get(get_series_by_remote_id_path).params({ imdbid: id }.merge(options))
8
24
  end
9
25
 
10
26
  def get_series_by_zap2it_id(id, options = {})
11
- get('GetSeriesByRemoteID.php').params({ zap2it: id }.merge(options)).response
27
+ get_series_by_zap2it_id_get_with_params(id, options).response(ThetvdbApi::Response::SearchSeries)
28
+ end
29
+
30
+ def get_series_by_zap2it_id_url(id, options = {})
31
+ get_series_by_zap2it_id_get_with_params(id, options).url
32
+ end
33
+
34
+ def get_series_by_zap2it_id_get_with_params(id, options)
35
+ get(get_series_by_remote_id_path).params({ zap2it: id }.merge(options))
12
36
  end
13
37
 
14
38
  def get_episode(series_id, air_date, options = {})
15
- get('GetEpisodeByAirDate.php').params({ seriesid: series_id, airdate: air_date }.merge(options)).response
39
+ get_episode_get_with_params(series_id, air_date, options).response(ThetvdbApi::Response::SearchMultipleEpisode)
40
+ end
41
+
42
+ def get_episode_url(series_id, air_date, options = {})
43
+ get_episode_get_with_params(series_id, air_date, options).url
44
+ end
45
+
46
+ def get_episode_get_with_params(series_id, air_date, options)
47
+ get(get_episode_path).params({ seriesid: series_id, airdate: air_date }.merge(options))
48
+ end
49
+
50
+ private
51
+
52
+ def get_series_path
53
+ 'GetSeries.php'
54
+ end
55
+
56
+ def get_series_by_remote_id_path
57
+ 'GetSeriesByRemoteID.php'
58
+ end
59
+
60
+ def get_episode_path
61
+ 'GetEpisodeByAirDate.php'
16
62
  end
17
63
  end
@@ -1,9 +1,35 @@
1
1
  class ThetvdbApi::Series < ThetvdbApi::Base
2
2
  def find(series_id, options = {})
3
- get("#{series_uri}/{language}.xml").params({ series_id: series_id }.merge(options)).response
3
+ find_get_with_params(series_id, options).response(ThetvdbApi::Response::Series)
4
+ end
5
+
6
+ def find_url(series_id, options = {})
7
+ find_get_with_params(series_id, options).url
8
+ end
9
+
10
+ def find_get_with_params(series_id, options)
11
+ get(find_path).params({ series_id: series_id }.merge(options))
4
12
  end
5
13
 
6
14
  def find_full(series_id, options = {})
7
- get("#{series_uri}/all/{language}.xml").params({ series_id: series_id }.merge(options)).response
15
+ find_full_get_with_params(series_id, options).response(ThetvdbApi::Response::FullSeries)
16
+ end
17
+
18
+ def find_full_url(series_id, options = {})
19
+ find_full_get_with_params(series_id, options).url
20
+ end
21
+
22
+ def find_full_get_with_params(series_id, options)
23
+ get(find_full_path).params({ series_id: series_id }.merge(options))
24
+ end
25
+
26
+ private
27
+
28
+ def find_path
29
+ "#{series_uri}/{language}.xml"
30
+ end
31
+
32
+ def find_full_path
33
+ "#{series_uri}/all/{language}.xml"
8
34
  end
9
35
  end
@@ -1,34 +1,50 @@
1
1
  class ThetvdbApi::Update < ThetvdbApi::Base
2
2
  def day(options = {})
3
- get(day_path).params(options).response
3
+ day_get_with_params(options).response(ThetvdbApi::Response::Update)
4
4
  end
5
5
 
6
6
  def day_url
7
- get(day_path).url
7
+ day_get_with_params.url
8
+ end
9
+
10
+ def day_get_with_params(options = {})
11
+ get(day_path).params(options)
8
12
  end
9
13
 
10
14
  def week(options = {})
11
- get(week_path).params(options).response
15
+ week_get_with_params(options).response(ThetvdbApi::Response::Update)
12
16
  end
13
17
 
14
18
  def week_url
15
- get(week_path).url
19
+ week_get_with_params.url
20
+ end
21
+
22
+ def week_get_with_params(options = {})
23
+ get(week_path).params(options)
16
24
  end
17
25
 
18
26
  def month(options = {})
19
- get(month_path).params(options).response
27
+ month_get_with_params(options).response(ThetvdbApi::Response::Update)
20
28
  end
21
29
 
22
30
  def month_url
23
- get(month_path).url
31
+ month_get_with_params.url
32
+ end
33
+
34
+ def month_get_with_params(options = {})
35
+ get(month_path).params(options)
24
36
  end
25
37
 
26
38
  def all(options = {})
27
- get(all_path).params(options).response
39
+ all_get_with_params(options).response(ThetvdbApi::Response::Update)
28
40
  end
29
41
 
30
42
  def all_url
31
- get(all_path).url
43
+ all_get_with_params.url
44
+ end
45
+
46
+ def all_get_with_params(options = {})
47
+ get(all_path).params(options)
32
48
  end
33
49
 
34
50
  private
@@ -1,3 +1,3 @@
1
1
  module ThetvdbApi
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end