thetvdb_mapper 0.0.4 → 0.0.5

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +5 -14
  4. data/lib/thetvdb_mapper.rb +4 -10
  5. data/lib/thetvdb_mapper/actor.rb +7 -0
  6. data/lib/thetvdb_mapper/banner.rb +14 -0
  7. data/lib/thetvdb_mapper/base.rb +3 -9
  8. data/lib/thetvdb_mapper/episode.rb +32 -11
  9. data/lib/thetvdb_mapper/series.rb +25 -11
  10. data/lib/thetvdb_mapper/version.rb +1 -1
  11. data/spec/functionals/actor_spec.rb +34 -0
  12. data/spec/functionals/banner_spec.rb +49 -0
  13. data/spec/functionals/episode_spec.rb +88 -0
  14. data/spec/functionals/series_spec.rb +72 -0
  15. data/thetvdb_mapper.gemspec +2 -1
  16. metadata +29 -65
  17. data/lib/thetvdb_mapper/actors.rb +0 -17
  18. data/lib/thetvdb_mapper/banners.rb +0 -17
  19. data/lib/thetvdb_mapper/fetcher.rb +0 -25
  20. data/lib/thetvdb_mapper/full_series.rb +0 -53
  21. data/lib/thetvdb_mapper/mapping/actor.rb +0 -11
  22. data/lib/thetvdb_mapper/mapping/banner.rb +0 -18
  23. data/lib/thetvdb_mapper/mapping/base.rb +0 -27
  24. data/lib/thetvdb_mapper/mapping/episode.rb +0 -45
  25. data/lib/thetvdb_mapper/mapping/series.rb +0 -36
  26. data/lib/thetvdb_mapper/mapping/string_list.rb +0 -5
  27. data/spec/functionals/mapping/actor_spec.rb +0 -36
  28. data/spec/functionals/mapping/banner_spec.rb +0 -72
  29. data/spec/functionals/mapping/episode_spec.rb +0 -165
  30. data/spec/functionals/mapping/series_spec.rb +0 -128
  31. data/spec/integrations/classes/actors_spec.rb +0 -11
  32. data/spec/integrations/classes/banners_spec.rb +0 -11
  33. data/spec/integrations/classes/episode_spec.rb +0 -11
  34. data/spec/integrations/classes/fetcher_spec.rb +0 -35
  35. data/spec/integrations/classes/full_series_spec.rb +0 -11
  36. data/spec/integrations/classes/series_spec.rb +0 -11
  37. data/spec/integrations/integration_spec_helper.rb +0 -2
  38. data/spec/integrations/support/.keep +0 -0
  39. data/spec/units/actors_spec.rb +0 -40
  40. data/spec/units/banners_spec.rb +0 -40
  41. data/spec/units/base_spec.rb +0 -15
  42. data/spec/units/episode_spec.rb +0 -33
  43. data/spec/units/fetcher_spec.rb +0 -67
  44. data/spec/units/full_series_spec.rb +0 -140
  45. data/spec/units/mapping/actor_spec.rb +0 -27
  46. data/spec/units/mapping/banner_spec.rb +0 -54
  47. data/spec/units/mapping/base_spec.rb +0 -36
  48. data/spec/units/mapping/episode_spec.rb +0 -142
  49. data/spec/units/mapping/series_spec.rb +0 -114
  50. data/spec/units/mapping/string_list_spec.rb +0 -11
  51. data/spec/units/series_spec.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ede54fbc1b8f301492dffe4b0e4cf437aa2dff18
4
- data.tar.gz: 4fa1c97f5dfc76c201de14b546dcc8e8f6f8c7a6
3
+ metadata.gz: ddd665856a536718f13177e8c4c018f9a1f3eaa9
4
+ data.tar.gz: 67f691983facc4d15e2226df5680dd007e29f88f
5
5
  SHA512:
6
- metadata.gz: 5160079ad7df3fb5783774d05f06e3626b736dd6fed7701628700177caed4f447c48c52f840db6f1bf278ed80fa8440de2a83f4273e4c6ce0a60d4896ea029c8
7
- data.tar.gz: f0d4b7e8460b0cfaf0ae5f39b911b11bb4ce3ec18bb825da003a3869269d33bfbb719b6b3e26d65798acba5e0af5aef729a9104bfb5852c4cc5c2f5e132cf7ee
6
+ metadata.gz: 587bf6d15b9874b4a37aca30c0d077d7a8e364eab1494d80aeef078ace628c05b8dbf9687e9054f5363993bbf1c4ba9abd34ef4bd7ffd238bbec03ac024c0db7
7
+ data.tar.gz: dac0f4b0b37568af7519a7437245ead7b5a71f3409c512fd9c8208cf081a010d697c273b958a6550637682b815a6dac0608b8d8298f653bee8c1ef0a96a0f79f
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- script: 'bundle exec rspec spec/units && bundle exec rspec spec/functionals && bundle exec rspec spec/units'
2
+ script: 'bundle exec rspec spec/functionals'
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  # ThetvdbMapper
8
8
 
9
- Fetch data from thetvdb.com and mapping to common hash, where keys are symbols and underline.
9
+ ThetvdbMapper mapping and normalizing keys in hash data provided by ThetvdbApi.
10
10
 
11
11
  ## Installation
12
12
 
@@ -22,22 +22,13 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install thetvdb_mapper
24
24
 
25
- ## Configuration
26
-
27
- ```ruby
28
- ThetvdbApi::Configuration.configure do |config|
29
- config.api_key = '......'
30
- end
31
- ```
32
-
33
25
  ## Usage
34
26
 
35
27
  ```ruby
36
- ThetvdbMapper::Actor.new(series_id).data # return actors
37
- ThetvdbMapper::Banners.new(series_id).data # return banners hash (not image)
38
- ThetvdbMapper::Episode.new(episode_id).data # return episode
39
- ThetvdbMapper::FullSeries.new(series_id).data # return series with all episodes
40
- ThetvdbMapper::Series.new(series_id).data # return series
28
+ ThetvdbMapper::Actor.new(data)
29
+ ThetvdbMapper::Banners.new(data)
30
+ ThetvdbMapper::Episode.new(data)
31
+ ThetvdbMapper::Series.new(data)
41
32
  ```
42
33
 
43
34
  ## Contributing
@@ -1,18 +1,12 @@
1
+ require 'hashie'
2
+
1
3
  module ThetvdbMapper
2
4
  module Mapping; end
3
5
  end
4
6
 
5
7
  require 'thetvdb_mapper/version'
6
- require 'thetvdb_mapper/fetcher'
7
- require 'thetvdb_mapper/mapping/base'
8
- require 'thetvdb_mapper/mapping/actor'
9
- require 'thetvdb_mapper/mapping/banner'
10
- require 'thetvdb_mapper/mapping/episode'
11
- require 'thetvdb_mapper/mapping/series'
12
- require 'thetvdb_mapper/mapping/string_list'
13
8
  require 'thetvdb_mapper/base'
14
- require 'thetvdb_mapper/actors'
15
- require 'thetvdb_mapper/banners'
9
+ require 'thetvdb_mapper/actor'
10
+ require 'thetvdb_mapper/banner'
16
11
  require 'thetvdb_mapper/episode'
17
- require 'thetvdb_mapper/full_series'
18
12
  require 'thetvdb_mapper/series'
@@ -0,0 +1,7 @@
1
+ class ThetvdbMapper::Actor < ThetvdbMapper::Base
2
+ property :id, from: 'id', with: lambda { |value| value.to_i }
3
+ property :image_path, from: 'Image'
4
+ property :name, from: 'Name'
5
+ property :role, from: 'Role'
6
+ property :sort_order, from: 'SortOrder', with: lambda { |value| value.to_i }
7
+ end
@@ -0,0 +1,14 @@
1
+ class ThetvdbMapper::Banner < ThetvdbMapper::Base
2
+ property :id, from: 'id', with: lambda { |value| value.to_i }
3
+ property :path, from: 'BannerPath'
4
+ property :thumbnail_path, from: 'ThumbnailPath'
5
+ property :vignette_path, from: 'VignettePath'
6
+ property :kind, from: 'BannerType'
7
+ property :kind2, from: 'BannerType2'
8
+ property :language, from: 'Language'
9
+ property :season, from: 'Season', with: lambda { |value| value.to_i }
10
+ property :rating, from: 'Rating', with: lambda { |value| value.to_f }
11
+ property :rating_count, from: 'RatingCount', with: lambda { |value| value.to_i }
12
+ property :series_name, from: 'SeriesName'
13
+ property :colors, from: 'Colors'
14
+ end
@@ -1,11 +1,5 @@
1
- class ThetvdbMapper::Base
2
- attr_reader :id
3
-
4
- def initialize(id)
5
- @id = id
6
- end
7
-
8
- def fetcher
9
- @fetcher ||= ThetvdbMapper::Fetcher.new
1
+ class ThetvdbMapper::Base < Hashie::Trash
2
+ def self.to_array(string)
3
+ string.to_s.split('|').reject{ |element| element.empty? }
10
4
  end
11
5
  end
@@ -1,13 +1,34 @@
1
1
  class ThetvdbMapper::Episode < ThetvdbMapper::Base
2
- def data
3
- @data ||= mapping_object(fetcher.episode(id).body).map
4
- end
5
-
6
- def inspect
7
- "<ThetvdbMapper::Episode data=#{data.to_s} >"
8
- end
9
-
10
- def mapping_object(data)
11
- ThetvdbMapper::Mapping::Episode.new(data)
12
- end
2
+ property :id, from: 'id', with: lambda { |value| value.to_i }
3
+ property :combined_episode_number, from: 'Combined_episodenumber', with: lambda { |value| value.to_f }
4
+ property :combined_season, from: 'Combined_season', with: lambda { |value| value.to_f }
5
+ property :dvd_chapter, from: 'DVD_chapter'
6
+ property :dvd_disc_id, from: 'DVD_discid'
7
+ property :dvd_episode_number, from: 'DVD_episodenumber', with: lambda { |value| value.to_f }
8
+ property :dvd_season, from: 'DVD_season', with: lambda { |value| value.to_i }
9
+ property :directors, from: 'Director', with: lambda { |value| to_array(value) }
10
+ property :ep_img_flag, from: 'EpImgFlag', with: lambda { |value| value.to_i }
11
+ property :name, from: 'EpisodeName'
12
+ property :number, from: 'EpisodeNumber', with: lambda { |value| value.to_i }
13
+ property :first_aired, from: 'FirstAired', with: lambda { |value| Date.parse(value) }
14
+ property :guest_stars, from: 'GuestStars', with: lambda { |value| to_array(value) }
15
+ property :imdb_id, from: 'IMDB_ID'
16
+ property :language, from: 'Language'
17
+ property :overview, from: 'Overview'
18
+ property :production_code, from: 'ProductionCode'
19
+ property :rating, from: 'Rating', with: lambda { |value| value.to_f }
20
+ property :rating_count, from: 'RatingCount', with: lambda { |value| value.to_i }
21
+ property :season, from: 'SeasonNumber', with: lambda { |value| value.to_i }
22
+ property :writers, from: 'Writer', with: lambda { |value| to_array(value) }
23
+ property :absolute_number, from: 'absolute_number', with: lambda { |value| value.to_i }
24
+ property :airs_after_season, from: 'airsafter_season', with: lambda { |value| value.to_i }
25
+ property :airs_before_episode, from: 'airsbefore_episode', with: lambda { |value| value.to_i }
26
+ property :airs_before_season, from: 'airsbefore_season', with: lambda { |value| value.to_i }
27
+ property :filename_path, from: 'filename'
28
+ property :last_updated_at, from: 'lastupdated', with: lambda { |value| Time.at(value.to_i) }
29
+ property :season_id, from: 'seasonid'
30
+ property :series_id, from: 'seriesid'
31
+ property :thumbnail_added_at, from: 'thumb_added', with: lambda { |value| DateTime.parse(value) }
32
+ property :thumbnail_height, from: 'thumb_height', with: lambda { |value| value.to_i }
33
+ property :thumbnail_width, from: 'thumb_width', with: lambda { |value| value.to_i }
13
34
  end
@@ -1,13 +1,27 @@
1
1
  class ThetvdbMapper::Series < ThetvdbMapper::Base
2
- def data
3
- @data ||= mapping_object(fetcher.series(id).body).map
4
- end
5
-
6
- def mapping_object(data)
7
- ThetvdbMapper::Mapping::Series.new(data)
8
- end
9
-
10
- def inspect
11
- "<ThetvdbMapper::Series data=#{data.to_s} >"
12
- end
2
+ property :id, from: 'id', with: lambda { |value| value.to_i }
3
+ property :actors, from: 'Actors', with: lambda { |value| to_array(value) }
4
+ property :airs_day_of_week, from: 'Airs_DayOfWeek'
5
+ property :airs_time, from: 'Airs_Time'
6
+ property :content_rating, from: 'ContentRating'
7
+ property :first_aired, from: 'FirstAired', with: lambda { |value| Date.parse(value) }
8
+ property :genres, from: 'Genre', with: lambda { |value| to_array(value) }
9
+ property :imdb_id, from: 'IMDB_ID'
10
+ property :language, from: 'Language'
11
+ property :network, from: 'Network'
12
+ property :network_id, from: 'NetworkID', with: lambda { |value| value.to_i }
13
+ property :overview, from: 'Overview'
14
+ property :rating, from: 'Rating', with: lambda { |value| value.to_f }
15
+ property :rating_count, from: 'RatingCount', with: lambda { |value| value.to_i }
16
+ property :runtime, from: 'Runtime', with: lambda { |value| value.to_i }
17
+ property :name, from: 'SeriesName'
18
+ property :series_id, from: 'SeriesId', with: lambda { |value| value.to_i }
19
+ property :status, from: 'Status'
20
+ property :added_at, from: 'added', with: lambda { |value| DateTime.parse(value) }
21
+ property :added_by, from: 'addedBy'
22
+ property :banner_path, from: 'banner'
23
+ property :fanart_path, from: 'fanart'
24
+ property :last_updated_at, from: 'lastupdated', with: lambda { |value| Time.at(value.to_i) }
25
+ property :poster_path, from: 'poster'
26
+ property :zap2it_id, from: 'zap2it_id'
13
27
  end
@@ -1,3 +1,3 @@
1
1
  module ThetvdbMapper
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbMapper::Actor do
4
+ let(:model) { ThetvdbMapper::Actor.new(input_data) }
5
+ let(:input_data) do
6
+ {
7
+ 'id' => '123',
8
+ 'Image' => '/image_path',
9
+ 'Name' => 'name',
10
+ 'Role' => 'role',
11
+ 'SortOrder' => '1'
12
+ }
13
+ end
14
+
15
+ let(:output_data) do
16
+ {
17
+ id: 123,
18
+ image_path: '/image_path',
19
+ name: 'name',
20
+ role: 'role',
21
+ sort_order: 1
22
+ }
23
+ end
24
+
25
+ describe '.map' do
26
+ it 'should return specific keys' do
27
+ model.keys.sort.should == [:id, :image_path, :name, :role, :sort_order].sort
28
+ end
29
+
30
+ it 'should return corrected Hash after mapping' do
31
+ model.to_hash.should == output_data
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbMapper::Banner do
4
+ let(:model) { ThetvdbMapper::Banner.new(input_data) }
5
+ let(:input_data) do
6
+ {
7
+ 'id' => '123',
8
+ 'BannerPath' => '/image_path',
9
+ 'ThumbnailPath' => '/image2_path',
10
+ 'VignettePath' => '/image3_path',
11
+ 'BannerType' => 'kind',
12
+ 'BannerType2' => 'kind2',
13
+ 'Language' => 'en',
14
+ 'Season' => '1',
15
+ 'Rating' => '1.1',
16
+ 'RatingCount' => '123',
17
+ 'SeriesName' => 'Test',
18
+ 'Colors' => 'RGB',
19
+ }
20
+ end
21
+
22
+ let(:output_data) do
23
+ {
24
+ id: 123,
25
+ path: '/image_path',
26
+ thumbnail_path: '/image2_path',
27
+ vignette_path: '/image3_path',
28
+ kind: 'kind',
29
+ kind2: 'kind2',
30
+ language: 'en',
31
+ season: 1,
32
+ rating: 1.1,
33
+ rating_count: 123,
34
+ series_name: 'Test',
35
+ colors: 'RGB'
36
+ }
37
+ end
38
+
39
+ describe '#map' do
40
+ it 'should return specific keys' do
41
+ model.keys.sort.should == [:path, :thumbnail_path, :vignette_path, :kind, :kind2, :language, :season,
42
+ :rating, :rating_count, :series_name, :colors, :id].sort
43
+ end
44
+
45
+ it 'should return corrected Hash after mapping' do
46
+ model.to_hash.should == output_data
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbMapper::Episode do
4
+ let(:model) { ThetvdbMapper::Episode.new(input_data) }
5
+ let(:input_data) do
6
+ {
7
+ 'id' => '123',
8
+ 'Combined_episodenumber' => 1,
9
+ 'Combined_season' => 2,
10
+ 'DVD_episodenumber' => 3,
11
+ 'DVD_season' => 4,
12
+ 'Director' => 'McG',
13
+ 'EpImgFlag' => 1,
14
+ 'EpisodeName' => 'Test',
15
+ 'EpisodeNumber' => 5,
16
+ 'FirstAired' => '2000-01-01',
17
+ 'GuestStars' => 'Mieko Hillman|Kristine Blackport',
18
+ 'IMDB_ID' => 'tt000000',
19
+ 'Language' => 'en',
20
+ 'Overview' => 'overview',
21
+ 'ProductionCode' => '1234',
22
+ 'Rating' => '1.1',
23
+ 'RatingCount' => '12',
24
+ 'SeasonNumber' => '1',
25
+ 'Writer' => 'McG',
26
+ 'absolute_number' => '1',
27
+ 'airsafter_season' => '1',
28
+ 'airsbefore_episode' => '1',
29
+ 'airsbefore_season' => '1',
30
+ 'filename' => '/path',
31
+ 'lastupdated' => 1,
32
+ 'seasonid' => '1',
33
+ 'seriesid' => '1',
34
+ 'thumb_added' => '2000-01-01 01:00:00',
35
+ 'thumb_height' => '100',
36
+ 'thumb_width' => '100'
37
+ }
38
+ end
39
+
40
+ let(:output_data) do
41
+ {
42
+ id: 123,
43
+ combined_episode_number: 1.0,
44
+ combined_season: 2.0,
45
+ dvd_episode_number: 3.0,
46
+ dvd_season: 4,
47
+ directors: ['McG'],
48
+ ep_img_flag: 1,
49
+ name: 'Test',
50
+ number: 5,
51
+ first_aired: Date.parse('2000-01-01'),
52
+ guest_stars: ['Mieko Hillman', 'Kristine Blackport'],
53
+ imdb_id: 'tt000000',
54
+ language: 'en',
55
+ overview: 'overview',
56
+ production_code: '1234',
57
+ rating: 1.1,
58
+ rating_count: 12,
59
+ season: 1,
60
+ writers: ['McG'],
61
+ absolute_number: 1,
62
+ airs_after_season: 1,
63
+ airs_before_episode: 1,
64
+ airs_before_season: 1,
65
+ filename_path: '/path',
66
+ last_updated_at: Time.at(1),
67
+ season_id: '1',
68
+ series_id: '1',
69
+ thumbnail_added_at: DateTime.parse('2000-01-01 01:00:00'),
70
+ thumbnail_height: 100,
71
+ thumbnail_width: 100
72
+ }
73
+ end
74
+
75
+ describe '#map' do
76
+ it 'should return specific keys' do
77
+ model.keys.sort.should == [:id, :combined_episode_number, :combined_season, :dvd_episode_number,
78
+ :dvd_season, :directors, :ep_img_flag, :name, :number, :first_aired, :guest_stars, :imdb_id, :language,
79
+ :overview, :production_code, :rating, :rating_count, :season, :writers, :absolute_number, :airs_after_season,
80
+ :airs_before_episode, :airs_before_season, :filename_path, :last_updated_at, :season_id, :series_id,
81
+ :thumbnail_added_at, :thumbnail_height, :thumbnail_width].sort
82
+ end
83
+
84
+ it 'should return corrected Hash after mapping' do
85
+ model.to_hash.should == output_data
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThetvdbMapper::Series do
4
+ let(:model) { ThetvdbMapper::Series.new(input_data) }
5
+ let(:input_data) do
6
+ {
7
+ 'id' => '123',
8
+ 'Airs_DayOfWeek' => 'Monday',
9
+ 'Airs_Time' => '8 AM',
10
+ 'ContentRating' => 'PG',
11
+ 'FirstAired' => '2000-01-01',
12
+ 'Genre' => 'sci-fi',
13
+ 'IMDB_ID' => 'tt000000',
14
+ 'Language' => 'en',
15
+ 'Network' => 'SyFy',
16
+ 'NetworkID' => '1',
17
+ 'Overview' => 'overview',
18
+ 'Rating' => '1.1',
19
+ 'RatingCount' => '123',
20
+ 'Runtime' => '60',
21
+ 'SeriesName' => 'Test',
22
+ 'Status' => 'continue',
23
+ 'added' => '2000-01-01 01:00:00',
24
+ 'addedBy' => 'test',
25
+ 'banner' => 'banner_path',
26
+ 'fanart' => 'fanart_path',
27
+ 'lastupdated' => 1,
28
+ 'poster' => 'poster_path',
29
+ 'zap2it_id' => 'zap123'
30
+ }
31
+ end
32
+
33
+ let(:output_data) do
34
+ {
35
+ id: 123,
36
+ airs_day_of_week: 'Monday',
37
+ airs_time: '8 AM',
38
+ content_rating: 'PG',
39
+ first_aired: Date.parse('2000-01-01'),
40
+ genres: ['sci-fi'],
41
+ imdb_id: 'tt000000',
42
+ language: 'en',
43
+ network: 'SyFy',
44
+ network_id: 1,
45
+ overview: 'overview',
46
+ rating: 1.1,
47
+ rating_count: 123,
48
+ runtime: 60,
49
+ name: 'Test',
50
+ status: 'continue',
51
+ added_at: DateTime.parse('2000-01-01 01:00:00'),
52
+ added_by: 'test',
53
+ banner_path: 'banner_path',
54
+ fanart_path: 'fanart_path',
55
+ last_updated_at: Time.at(1),
56
+ poster_path: 'poster_path',
57
+ zap2it_id: 'zap123'
58
+ }
59
+ end
60
+
61
+ describe '#map' do
62
+ it 'should return specific keys' do
63
+ model.keys.sort.should == [:id, :airs_day_of_week, :airs_time, :content_rating, :first_aired, :genres,
64
+ :imdb_id, :language, :network, :network_id, :overview, :rating, :rating_count, :runtime, :name, :status,
65
+ :added_at, :added_by, :banner_path, :fanart_path, :last_updated_at, :poster_path, :zap2it_id].sort
66
+ end
67
+
68
+ it 'should return corrected Hash after mapping' do
69
+ model.to_hash.should == output_data
70
+ end
71
+ end
72
+ end