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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dbe78e1e66f145fec0db2f40aad36ff573c0956
4
- data.tar.gz: 530b460304b87029fa61bab4581518bc1f54b7f7
3
+ metadata.gz: 3126b9fe360eb24809166f9de6477785b90d8774
4
+ data.tar.gz: fb816d9de43b4d28198b5921ad34753eac59198e
5
5
  SHA512:
6
- metadata.gz: b14ac566eb33f5da78352a0c5d890055066f025c86e7287bd6837063158a3d8e11b7f0ffa5ffc9e4c60e7c3fde393a141038103adebf4dbc1f0538bb118361e8
7
- data.tar.gz: b9dbd2246a575db7199c1efcd82fd782628f33a18b69ecefb52ad00e86a02f2b5ea9fded43dc72667d27a2689d8f84a9fd03747f6c626b66f91aa11f61e5bbc6
6
+ metadata.gz: 9d192a544f0fa46dc2d91376d3912e466e76e465082e7e21954bdde486dbcb43957aa40232d96412776e48e0e80dbb8a35637e0034925d2cf6bb98088ef54d65
7
+ data.tar.gz: f2e07b40ad52056bc1ab1cb9027672e275b191b49812989e97c203314a8b075f2ecdcf2c06ad61577cd1c835119bf80b63a9dce400e53738a188e55558a2739a
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Dependency Status](https://gemnasium.com/wafcio/thetvdb_api.png)](https://gemnasium.com/wafcio/thetvdb_api)
3
3
  [![Code Climate](https://codeclimate.com/github/wafcio/thetvdb_api.png)](https://codeclimate.com/github/wafcio/thetvdb_api)
4
4
  [![Coverage Status](https://coveralls.io/repos/wafcio/thetvdb_api/badge.png)](https://coveralls.io/r/wafcio/thetvdb_api)
5
+ [![Gem Version](https://badge.fury.io/rb/thetvdb_api.png)](http://badge.fury.io/rb/thetvdb_api)
5
6
 
6
7
  # ThetvdbApi
7
8
 
@@ -14,40 +15,78 @@ You can add it to your Gemfile with:
14
15
  ```ruby
15
16
  gem 'thetvdb_api'
16
17
  ```
18
+
17
19
  Run the bundle command to install it.
18
20
 
19
- After you install Devise and add it to your Gemfile, you need to run the generator:
21
+ After you install ThetvdbApi and add it to your Gemfile, you need to run the generator (if you use Ruby on Rails application):
20
22
 
21
23
  ```console
22
24
  rails generate thetvdb_api:install
23
25
  ```
24
26
 
25
- The generator will install an initializer where you must past your API KEY.
27
+ The generator will install an initializer where you must past your api_key, and can past: language (2 letters abbrevation), api_url (base url).
26
28
 
27
29
  ## How to use
28
30
 
29
- All request class return instance where result method contain object or collection.
31
+ There is one entry point, in initialize you can past hash with api_key, language and api_url values, or leave empty:
30
32
 
31
- For example:
32
- ```console
33
- series = ThetvdbApi::Request::Series.find('buffy')
34
- series.result
35
- => #<ThetvdbApi::Series ...>
36
- ```
37
-
38
- * ThetvdbApi::Request::Actor.all(series_id) - return all banners for specific series
39
- * ThetvdbApi::Request::Banner.all(series_id) - return all banners for specific series
40
- * ThetvdbApi::Request::Episode.find_by_default_order(series_id, season, episode) - return episode
41
- * ThetvdbApi::Request::Episode.find_by_dvd_order(series_id, season, episode) - return episode
42
- * ThetvdbApi::Request::Episode.find_by_absolute_order(series_id, absolute) - return episode
43
- * ThetvdbApi::Request::Episode.find(episode_id) - return episode
44
- * ThetvdbApi::Request::Series.find(series_id) - return series
45
- * ThetvdbApi::Request::Series.find_full(series_id) - return hash with series data and all episodes
46
- * ThetvdbApi::Request::Update.day - return series updates from last day
47
- * ThetvdbApi::Request::Update.week - return series updates from last week
48
- * ThetvdbApi::Request::Update.month - return series updates from last month
49
- * ThetvdbApi::Request::Update.all - return all series updates
33
+ ```ruby
34
+ client = ThetvdbApi::Client.new(api_url: '...', api_key: '...', language: 'en')
35
+ ```
36
+
37
+ Search series by name
38
+
39
+ ```ruby
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_by_air_date('123', air_date)
45
+ ```
46
+
47
+ Search series by id
48
+
49
+ ```ruby
50
+ client = ThetvdbApi::Client.new
51
+ client.series.find('123')
52
+ client.series.find_full('123')
53
+ ```
54
+
55
+ Return series actors
56
+
57
+ ```ruby
58
+ client = ThetvdbApi::Client.new
59
+ client.actor.all(series_id)
60
+ ```
61
+
62
+ Return series banners
63
+
64
+ ```ruby
65
+ client = ThetvdbApi::Client.new
66
+ client.banner.all(series_id)
67
+ ```
68
+
69
+ Return series episode
70
+
71
+ ```ruby
72
+ 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)
77
+ ```
78
+
79
+ Get updates
80
+
81
+ ```ruby
82
+ client = ThetvdbApi::Client.new
83
+ client.update.day
84
+ client.update.week
85
+ client.update.month
86
+ client.update.all
87
+ ```
50
88
 
89
+ In each response you get pure hash, without any coerce or key mapping.
51
90
 
52
91
  ## Contributing
53
92
 
@@ -1,4 +1,5 @@
1
1
  class ThetvdbApi::Actor < ThetvdbApi::Base
2
- coerce_key :id, Integer
3
- coerce_key :sort_order, Integer
2
+ def find(series_id)
3
+ get("#{series_uri(series_id)}actors.xml").response
4
+ end
4
5
  end
@@ -1,11 +1,5 @@
1
1
  class ThetvdbApi::Banner < ThetvdbApi::Base
2
- replace_key :Series, :series_id
3
-
4
- coerce_key :id, Integer
5
- coerce_key :rating, Float
6
- coerce_key :rating_count, Integer
7
- coerce_key :season, Integer
8
- coerce_key :series_id, Integer
9
- coerce_key :season_num, Integer
10
- coerce_key :time, Time
2
+ def find(series_id)
3
+ get("#{series_uri(series_id)}banners.xml").response
4
+ end
11
5
  end
@@ -1,7 +1,46 @@
1
- require 'hashie'
1
+ require 'httparty'
2
2
 
3
- class ThetvdbApi::Base < Hashie::Mash
4
- include Hashie::Extensions::MethodAccess
5
- include Hashie::Extensions::KeyReplace
6
- include Hashie::Extensions::Coercion
3
+ class ThetvdbApi::Base
4
+ include HTTParty
5
+
6
+ attr_reader :client, :uri, :options
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def get(uri, options = {})
13
+ @uri = uri
14
+ @options = options
15
+
16
+ self
17
+ end
18
+
19
+ def response
20
+ response = self.class.get(uri, request_options(options))
21
+ response.code == 200 ? response.parsed_response : nil
22
+ end
23
+
24
+ def request_options(options = {})
25
+ {
26
+ query: options,
27
+ base_uri: api_url
28
+ }
29
+ end
30
+
31
+ def series_uri(series_id)
32
+ "#{api_key}/series/#{series_id}/"
33
+ end
34
+
35
+ def api_url
36
+ client.api_url
37
+ end
38
+
39
+ def api_key
40
+ client.api_key
41
+ end
42
+
43
+ def language
44
+ client.language
45
+ end
7
46
  end
@@ -0,0 +1,34 @@
1
+ class ThetvdbApi::Client
2
+ attr_reader :api_key, :api_url, :language
3
+
4
+ def initialize(options = {})
5
+
6
+ @api_key = options[:api_key] ? options[:api_key] : ThetvdbApi::Configuration.api_key
7
+ @api_url = options[:api_url] ? options[:api_url] : ThetvdbApi::Configuration.api_url
8
+ @language = options[:language] ? options[:language] : ThetvdbApi::Configuration.language
9
+ end
10
+
11
+ def search
12
+ @search ||= ThetvdbApi::Search.new(self)
13
+ end
14
+
15
+ def series
16
+ @series ||= ThetvdbApi::Series.new(self)
17
+ end
18
+
19
+ def actor
20
+ @actor ||= ThetvdbApi::Actor.new(self)
21
+ end
22
+
23
+ def banner
24
+ @banner ||= ThetvdbApi::Banner.new(self)
25
+ end
26
+
27
+ def episode
28
+ @episode ||= ThetvdbApi::Episode.new(self)
29
+ end
30
+
31
+ def update
32
+ @update ||= ThetvdbApi::Update.new(self)
33
+ end
34
+ end
@@ -1,34 +1,17 @@
1
1
  class ThetvdbApi::Episode < ThetvdbApi::Base
2
- replace_key :airsafter_season, :airs_after_season
3
- replace_key :airsbefore_episode, :airs_before_episode
4
- replace_key :airsbefore_season, :airs_before_season
5
- replace_key :Combined_episodenumber, :combined_episode_number
6
- replace_key :DVD_discid, :dvd_disc_id
7
- replace_key :DVD_episodenumber, :dvd_episode_number
8
- replace_key :lastupdated, :last_updated_at
9
- replace_key :seasonid, :season_id
10
- replace_key :series, :series_id
11
- replace_key :seriesid, :series_id
12
- replace_key :thumb_added, :thumb_added_at
2
+ def find_by_default_order(series_id, season, episode, language = self.language)
3
+ get("#{series_uri(series_id)}default/#{season}/#{episode}/#{language}.xml").response
4
+ end
13
5
 
14
- coerce_key :id, Integer
15
- coerce_key :absolute_number, Integer
16
- coerce_key :combined_episode_number, Integer
17
- coerce_key :combined_season, Integer
18
- coerce_key :director, Array
19
- coerce_key :ep_img_flag, Integer
20
- coerce_key :episode_number, Integer
21
- coerce_key :first_aired, Date
22
- coerce_key :guest_stars, Array
23
- coerce_key :last_updated_at, Time
24
- coerce_key :rating, Float
25
- coerce_key :rating_count, Integer
26
- coerce_key :season_id, Integer
27
- coerce_key :season_number, Integer
28
- coerce_key :series_id, Integer
29
- coerce_key :thumb_added_at, Time
30
- coerce_key :thumb_height, Integer
31
- coerce_key :thumb_width, Integer
32
- coerce_key :time, Time
33
- coerce_key :writer, Array
6
+ def find_by_dvd_order(series_id, season, episode, language = self.language)
7
+ get("#{series_uri(series_id)}dvd/#{season}/#{episode}/#{language}.xml").response
8
+ end
9
+
10
+ def find_by_absolute_order(series_id, absolute, language = self.language)
11
+ get("#{series_uri(series_id)}absolute/#{absolute}/#{language}.xml").response
12
+ end
13
+
14
+ def find(episode_id, language = self.language)
15
+ get("#{api_key}/episodes/#{episode_id}/#{language}.xml").response
16
+ end
34
17
  end
@@ -0,0 +1,18 @@
1
+ class ThetvdbApi::Search < ThetvdbApi::Base
2
+ def get_series(name, language = self.language)
3
+ get('GetSeries.php', seriesname: name, language: language).response
4
+ end
5
+
6
+ def get_series_by_imdb_id(id, language = self.language)
7
+ get('GetSeriesByRemoteID.php', imdbid: id, language: language).response
8
+ end
9
+
10
+ def get_series_by_zap2it_id(id, language = self.language)
11
+ get('GetSeriesByRemoteID.php', zap2it: id, language: language).response
12
+ end
13
+
14
+ def get_episode_by_air_date(series_id, air_date, language = self.language)
15
+ get('GetEpisodeByAirDate.php', apikey: self.api_key, seriesid: series_id, airdate: air_date, language: language).
16
+ response
17
+ end
18
+ end
@@ -1,20 +1,9 @@
1
1
  class ThetvdbApi::Series < ThetvdbApi::Base
2
- replace_key :added, :added_at
3
- replace_key :lastupdated, :last_updated_at
4
- replace_key :seriesid, :series_id
2
+ def find(series_id, language = self.language)
3
+ get("#{series_uri(series_id)}#{language}.xml").response
4
+ end
5
5
 
6
- coerce_key :id, Integer
7
- coerce_key :actors, Array
8
- coerce_key :added_at, Time
9
- coerce_key :added_by, Integer
10
- coerce_key :alias_names, Array
11
- coerce_key :first_aired, Date
12
- coerce_key :genre, Array
13
- coerce_key :last_updated_at, Time
14
- coerce_key :network_id, Integer
15
- coerce_key :rating, Float
16
- coerce_key :rating_count, Integer
17
- coerce_key :runtime, Integer
18
- coerce_key :series_id, Integer
19
- coerce_key :time, Time
6
+ def find_full(series_id, language = self.language)
7
+ get("#{series_uri(series_id)}all/#{language}.xml").response
8
+ end
20
9
  end
@@ -0,0 +1,17 @@
1
+ class ThetvdbApi::Update < ThetvdbApi::Base
2
+ def day
3
+ get("#{api_key}/updates/updates_day.xml").response
4
+ end
5
+
6
+ def week
7
+ get("#{api_key}/updates/updates_week.xml").response
8
+ end
9
+
10
+ def month
11
+ get("#{api_key}/updates/updates_month.xml").response
12
+ end
13
+
14
+ def all
15
+ get("#{api_key}/updates/updates_all.xml").response
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module ThetvdbApi
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/thetvdb_api.rb CHANGED
@@ -1,23 +1,12 @@
1
- module ThetvdbApi
2
- module Request
3
- module Module; end
4
- end
5
- end
1
+ module ThetvdbApi; end
6
2
 
7
3
  require 'thetvdb_api/version'
8
4
  require 'thetvdb_api/configuration'
9
- require 'thetvdb_api/utility'
5
+ require 'thetvdb_api/client'
10
6
  require 'thetvdb_api/base'
7
+ require 'thetvdb_api/search'
8
+ require 'thetvdb_api/update'
9
+ require 'thetvdb_api/series'
10
+ require 'thetvdb_api/episode'
11
11
  require 'thetvdb_api/actor'
12
12
  require 'thetvdb_api/banner'
13
- require 'thetvdb_api/episode'
14
- require 'thetvdb_api/series'
15
- require 'thetvdb_api/request/base'
16
- require 'thetvdb_api/request/module/find'
17
- require 'thetvdb_api/request/module/series_uri'
18
- require 'thetvdb_api/request/search'
19
- require 'thetvdb_api/request/update'
20
- require 'thetvdb_api/request/series'
21
- require 'thetvdb_api/request/episode'
22
- require 'thetvdb_api/request/actor'
23
- require 'thetvdb_api/request/banner'
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ThetvdbApi::Request::Actor do
4
- let(:klass) { ThetvdbApi::Request::Actor }
3
+ describe ThetvdbApi::Actor do
4
+ let(:model) { ThetvdbApi::Actor.new(ThetvdbApi::Client.new) }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find' do
8
- it 'should return array' do
9
- klass.find('70327').result.class.should == Array
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
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ThetvdbApi::Request::Banner do
4
- let(:klass) { ThetvdbApi::Request::Banner }
3
+ describe ThetvdbApi::Banner do
4
+ let(:model) { ThetvdbApi::Banner.new(ThetvdbApi::Client.new) }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find' do
8
- it 'should return array' do
9
- klass.find('72449').result.class.should == Array
7
+ describe '.find' do
8
+ it 'should return hash' do
9
+ model.find('72449').class.should == Hash
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbApi::Client do
4
+ let(:client) { ThetvdbApi::Client.new }
5
+
6
+ describe 'real request' do
7
+ describe '.search' do
8
+ describe '.get_series' do
9
+ it 'should return hash' do
10
+ client.search.get_series('buffy').class.should == Hash
11
+ end
12
+ end
13
+
14
+ describe '.get_series_by_imdb_id' do
15
+ it 'should return hash' do
16
+ client.search.get_series_by_imdb_id('tt0118276').class.should == Hash
17
+ end
18
+ end
19
+
20
+ describe '.get_series_by_zap2it_id' do
21
+ it 'should return hash' do
22
+ client.search.get_series_by_zap2it_id('EP00213110').class.should == Hash
23
+ end
24
+ end
25
+
26
+ describe '.get_episode_by_air_date' do
27
+ it 'should return hash' do
28
+ client.search.get_episode_by_air_date('70327','1997-03-10').class.should == Hash
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '.series' do
34
+ describe '.find' do
35
+ it 'should return hash' do
36
+ client.series.find('70327').class.should == Hash
37
+ end
38
+ end
39
+
40
+ describe '.find_full' do
41
+ it 'should return hash' do
42
+ client.series.find_full('70327').class.should == Hash
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '.actor' do
48
+ describe '.find' do
49
+ it 'should return hash' do
50
+ client.actor.find('70327').class.should == Hash
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '.banner' do
56
+ describe '.find' do
57
+ it 'should return hash' do
58
+ client.banner.find('70327').class.should == Hash
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '.episode' do
64
+ describe '.find_by_default_order' do
65
+ it 'should return hash' do
66
+ client.episode.find_by_default_order('70327', '1', '1').class.should == Hash
67
+ end
68
+ end
69
+
70
+ describe '.find_by_dvd_order' do
71
+ it 'should return hash' do
72
+ client.episode.find_by_dvd_order('70327', '1', '1').class.should == Hash
73
+ end
74
+ end
75
+
76
+ describe '.find_by_absolute_order' do
77
+ it 'should return hash' do
78
+ client.episode.find_by_absolute_order('70327', '1').class.should == Hash
79
+ end
80
+ end
81
+
82
+ describe '.find' do
83
+ it 'should return hash' do
84
+ client.episode.find('533011').class.should == Hash
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '.update' do
90
+ describe '.day' do
91
+ it 'should return hash' do
92
+ client.update.day.class.should == Hash
93
+ end
94
+ end
95
+
96
+ describe '.week' do
97
+ it 'should return hash' do
98
+ client.update.week.class.should == Hash
99
+ end
100
+ end
101
+
102
+ describe '.month' do
103
+ it 'should return hash' do
104
+ client.update.month.class.should == Hash
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end