thetvdb_party 0.0.8.pre → 0.0.10.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4ae3f4b66f47ebf2cd6b1b0435740f4c73f273e
4
- data.tar.gz: 918ba53db6eb0bd78de128d1755015cb5a371cea
3
+ metadata.gz: b470ca3188d5901fc1f2a1624f1821dabc239ea6
4
+ data.tar.gz: b916a69a52ac4c41a7f8397bb9aa62b3b30b3dca
5
5
  SHA512:
6
- metadata.gz: 3b889b14be540b6b40d1df6b4dcf801ccfe3a397136ab80ef5c5b9a211a19d42e5c87e71e02612f439a91ece357c3d4dfc3b65c7ffbf097120a0d1008776910e
7
- data.tar.gz: 0c6d13857aa2a5ae02c0c95b01884ae65a013c05e36659412e75a3766ac3626a4a7eb89dd4d804ecf0bfb8e85ce10cab8a19bcc0fd145f67e5d291ffde7c80dd
6
+ metadata.gz: aa03ad7d095c9d53fb808a1cecb1c854e024170b3f2056f2cea5712b939e40b1f0bb16cd0f434f826f2c78e0e5992e316af2936afd774764d911f83e996d30ab
7
+ data.tar.gz: 9ae6fee16491b918866da142a8deaf5b04911020abec32403a9ba606b778c85225e34d40cd3b4c7364dc066b4f8dd309afa74f030469fe63a4ad7c7662790d2d
data/.gitattributes ADDED
@@ -0,0 +1,63 @@
1
+ ###############################################################################
2
+ # Set default behavior to automatically normalize line endings.
3
+ ###############################################################################
4
+ * text=auto
5
+
6
+ ###############################################################################
7
+ # Set default behavior for command prompt diff.
8
+ #
9
+ # This is need for earlier builds of msysgit that does not have it on by
10
+ # default for csharp files.
11
+ # Note: This is only used by command line
12
+ ###############################################################################
13
+ #*.cs diff=csharp
14
+
15
+ ###############################################################################
16
+ # Set the merge driver for project and solution files
17
+ #
18
+ # Merging from the command prompt will add diff markers to the files if there
19
+ # are conflicts (Merging from VS is not affected by the settings below, in VS
20
+ # the diff markers are never inserted). Diff markers may cause the following
21
+ # file extensions to fail to load in VS. An alternative would be to treat
22
+ # these files as binary and thus will always conflict and require user
23
+ # intervention with every merge. To do so, just uncomment the entries below
24
+ ###############################################################################
25
+ #*.sln merge=binary
26
+ #*.csproj merge=binary
27
+ #*.vbproj merge=binary
28
+ #*.vcxproj merge=binary
29
+ #*.vcproj merge=binary
30
+ #*.dbproj merge=binary
31
+ #*.fsproj merge=binary
32
+ #*.lsproj merge=binary
33
+ #*.wixproj merge=binary
34
+ #*.modelproj merge=binary
35
+ #*.sqlproj merge=binary
36
+ #*.wwaproj merge=binary
37
+
38
+ ###############################################################################
39
+ # behavior for image files
40
+ #
41
+ # image files are treated as binary by default.
42
+ ###############################################################################
43
+ #*.jpg binary
44
+ #*.png binary
45
+ #*.gif binary
46
+
47
+ ###############################################################################
48
+ # diff behavior for common document formats
49
+ #
50
+ # Convert binary document formats to text before diffing them. This feature
51
+ # is only available from the command line. Turn it on by uncommenting the
52
+ # entries below.
53
+ ###############################################################################
54
+ #*.doc diff=astextplain
55
+ #*.DOC diff=astextplain
56
+ #*.docx diff=astextplain
57
+ #*.DOCX diff=astextplain
58
+ #*.dot diff=astextplain
59
+ #*.DOT diff=astextplain
60
+ #*.pdf diff=astextplain
61
+ #*.PDF diff=astextplain
62
+ #*.rtf diff=astextplain
63
+ #*.RTF diff=astextplain
data/.gitignore CHANGED
@@ -1,3 +1,203 @@
1
+ ## Ignore Visual Studio temporary files, build results, and
2
+ ## files generated by popular Visual Studio add-ons.
3
+
4
+ # User-specific files
5
+ *.suo
6
+ *.user
7
+ *.sln.docstates
8
+
9
+ # Build results
10
+ [Dd]ebug/
11
+ [Dd]ebugPublic/
12
+ [Rr]elease/
13
+ x64/
14
+ build/
15
+ bld/
16
+ [Bb]in/
17
+ [Oo]bj/
18
+
19
+ # Roslyn cache directories
20
+ *.ide/
21
+
22
+ # MSTest test Results
23
+ [Tt]est[Rr]esult*/
24
+ [Bb]uild[Ll]og.*
25
+
26
+ #NUNIT
27
+ *.VisualState.xml
28
+ TestResult.xml
29
+
30
+ # Build Results of an ATL Project
31
+ [Dd]ebugPS/
32
+ [Rr]eleasePS/
33
+ dlldata.c
34
+
35
+ *_i.c
36
+ *_p.c
37
+ *_i.h
38
+ *.ilk
39
+ *.meta
40
+ *.obj
41
+ *.pch
42
+ *.pdb
43
+ *.pgc
44
+ *.pgd
45
+ *.rsp
46
+ *.sbr
47
+ *.tlb
48
+ *.tli
49
+ *.tlh
50
+ *.tmp
51
+ *.tmp_proj
52
+ *.log
53
+ *.vspscc
54
+ *.vssscc
55
+ .builds
56
+ *.pidb
57
+ *.svclog
58
+ *.scc
59
+
60
+ # Chutzpah Test files
61
+ _Chutzpah*
62
+
63
+ # Visual C++ cache files
64
+ ipch/
65
+ *.aps
66
+ *.ncb
67
+ *.opensdf
68
+ *.sdf
69
+ *.cachefile
70
+
71
+ # Visual Studio profiler
72
+ *.psess
73
+ *.vsp
74
+ *.vspx
75
+
76
+ # TFS 2012 Local Workspace
77
+ $tf/
78
+
79
+ # Guidance Automation Toolkit
80
+ *.gpState
81
+
82
+ # ReSharper is a .NET coding add-in
83
+ _ReSharper*/
84
+ *.[Rr]e[Ss]harper
85
+ *.DotSettings.user
86
+
87
+ # JustCode is a .NET coding addin-in
88
+ .JustCode
89
+
90
+ # TeamCity is a build add-in
91
+ _TeamCity*
92
+
93
+ # DotCover is a Code Coverage Tool
94
+ *.dotCover
95
+
96
+ # NCrunch
97
+ _NCrunch_*
98
+ .*crunch*.local.xml
99
+
100
+ # MightyMoose
101
+ *.mm.*
102
+ AutoTest.Net/
103
+
104
+ # Web workbench (sass)
105
+ .sass-cache/
106
+
107
+ # Installshield output folder
108
+ [Ee]xpress/
109
+
110
+ # DocProject is a documentation generator add-in
111
+ DocProject/buildhelp/
112
+ DocProject/Help/*.HxT
113
+ DocProject/Help/*.HxC
114
+ DocProject/Help/*.hhc
115
+ DocProject/Help/*.hhk
116
+ DocProject/Help/*.hhp
117
+ DocProject/Help/Html2
118
+ DocProject/Help/html
119
+
120
+ # Click-Once directory
121
+ publish/
122
+
123
+ # Publish Web Output
124
+ *.[Pp]ublish.xml
125
+ *.azurePubxml
126
+ ## TODO: Comment the next line if you want to checkin your
127
+ ## web deploy settings but do note that will include unencrypted
128
+ ## passwords
129
+ #*.pubxml
130
+
131
+ # NuGet Packages Directory
132
+ packages/*
133
+ ## TODO: If the tool you use requires repositories.config
134
+ ## uncomment the next line
135
+ #!packages/repositories.config
136
+
137
+ # Enable "build/" folder in the NuGet Packages folder since
138
+ # NuGet packages use it for MSBuild targets.
139
+ # This line needs to be after the ignore of the build folder
140
+ # (and the packages folder if the line above has been uncommented)
141
+ !packages/build/
142
+
143
+ # Windows Azure Build Output
144
+ csx/
145
+ *.build.csdef
146
+
147
+ # Windows Store app package directory
148
+ AppPackages/
149
+
150
+ # Others
151
+ sql/
152
+ *.Cache
153
+ ClientBin/
154
+ [Ss]tyle[Cc]op.*
155
+ ~$*
156
+ *~
157
+ *.dbmdl
158
+ *.dbproj.schemaview
159
+ *.pfx
160
+ *.publishsettings
161
+ node_modules/
162
+ bower_components/
163
+
164
+ # RIA/Silverlight projects
165
+ Generated_Code/
166
+
167
+ # Backup & report files from converting an old project file
168
+ # to a newer Visual Studio version. Backup files are not needed,
169
+ # because we have git ;-)
170
+ _UpgradeReport_Files/
171
+ Backup*/
172
+ UpgradeLog*.XML
173
+ UpgradeLog*.htm
174
+
175
+ # SQL Server files
176
+ *.mdf
177
+ *.ldf
178
+
179
+ # Business Intelligence projects
180
+ *.rdl.data
181
+ *.bim.layout
182
+ *.bim_*.settings
183
+
184
+ # Microsoft Fakes
185
+ FakesAssemblies/
186
+
187
+ # LightSwitch generated files
188
+ GeneratedArtifacts/
189
+ _Pvt_Extensions/
190
+ ModelManifest.xml
191
+
192
+ # Ignore the default SQLite database.
193
+ /db/*.sqlite3
194
+ /db/*.sqlite3-journal
195
+
196
+ # Ignore all logfiles and tempfiles.
197
+ /log/*
198
+ !/log/.keep
199
+ /tmp
200
+
1
201
  /.idea/
2
202
  /.bundle/
3
203
  /.yardoc
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # ThetvdbParty
1
+ # TheTvDbParty
2
2
 
3
- TODO: Write a gem description
3
+ The thetvdb_party gem accesses the TheTvDB programmers API as it is described on http://thetvdb.com/wiki/index.php/Programmers_API
4
+
5
+ It uses compression to minimize bandwith when accessing Full Series Records.
4
6
 
5
7
  ## Installation
6
8
 
@@ -24,7 +26,7 @@ TODO: Write usage instructions here
24
26
 
25
27
  ## Contributing
26
28
 
27
- 1. Fork it ( https://github.com/[my-github-username]/thetvdb_party/fork )
29
+ 1. Fork it ( https://github.com/couven92/thetvdb_party/fork )
28
30
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
31
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
32
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rdoc/task'
2
3
 
4
+ RDoc::Task.new do |rdoc|
5
+ rdoc.main = "README.md"
6
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
7
+ rdoc.rdoc_dir = "doc"
8
+ rdoc.options << "--line-numbers"
9
+ end
data/lib/thetvdb_party.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
2
 
3
3
  require 'thetvdb_party/baseseriesrecord'
4
+ require 'thetvdb_party/baseepisoderecord'
4
5
  require 'thetvdb_party/client'
5
6
  require 'thetvdb_party/searchseriesrecord'
6
7
  require 'thetvdb_party/version'
@@ -0,0 +1,179 @@
1
+ module TheTvDbParty
2
+ # The Base Episode Record contains all of the information available about an episode.
3
+ # Remarks:: The fields #airsafter_season, #airsbefore_episode, and #airsbefore_season will only be included when the
4
+ # episode is listed as a special. Specials are also listed as being in season +0+, so they're easy to
5
+ # identify and sort.
6
+ #
7
+ # #dvd_episodenumber is a decimal and can be used to join episodes together. Usually used to join episodes
8
+ # that aired as two episodes but were released on DVD as a single episode. Normally there would be no
9
+ # decimal value but if you see an episode +1.1+ and +1.2+ that means both records should be combined to
10
+ # make episode +1+. Cartoons are also known to combine up to 9 episodes together,
11
+ # for example {Animaniacs season two}[http://www.thetvdb.com/index.php?tab=season&seriesid=72879&seasonid=4931&lid=7&order=dvd].
12
+ # See Also:: http://thetvdb.com/wiki/index.php?title=API:Base_Episode_Record
13
+ class BaseEpisodeRecord
14
+
15
+ attr_reader :client
16
+ # An unsigned integer assigned by TheTvDb to the episode. Negative, if invalid.
17
+ attr_reader :id
18
+ # A decimal. Negative, if invalid. This returns the value of #dvd_episodenumber if that field is not
19
+ # null. Otherwise it returns the value from #episodenumber.
20
+ # Remarks:: The field can be used as a simple way of prioritizing DVD order over aired order in your program.
21
+ # In general it's best to avoid using this field as you can accomplish the same task locally and have
22
+ # more control if you use the #dvd_episodenumber and #episodenumber fields separately.
23
+ attr_reader :combined_episodenumber
24
+ # A decimal. Negative, if invalid. This returns the value of #dvd_season if that field is not null. Otherwise it returns
25
+ # the value from #seasonnumber.
26
+ # Remarks:: The field can be used as a simple way of prioritizing DVD order over aired order in your program.
27
+ # In general it's best to avoid using this field as you can accomplish the same task locally and have
28
+ # more control if you use the #dvd_season and #seasonnumber fields separately.
29
+ attr_reader :combined_season
30
+ # Deprecated, was meant to be used to aid in scrapping of actual DVD's but has never been populated properly.
31
+ # Any information returned in this field shouldn't be trusted. Will usually be null.
32
+ attr_reader :dvd_chapter
33
+ # Deprecated, was meant to be used to aid in scrapping of actual DVD's but has never been populated properly.
34
+ # Any information returned in this field shouldn't be trusted. Will usually be null.
35
+ attr_reader :dvd_discid
36
+ # A decimal with one decimal and can be used to join episodes together. Negative if invalid,
37
+ # usually used to join episodes that aired as two episodes but were released on DVD as a single episode.
38
+ # If you see an episode +1.1+ and +1.2+ that means both records should be combined to make episode +1+.
39
+ # Cartoons are also known to combine up to 9 episodes together,
40
+ # for example {Animaniacs season two}[http://www.thetvdb.com/index.php?tab=season&seriesid=72879&seasonid=4931&lid=7&order=dvd].
41
+ attr_reader :dvd_episodenumber
42
+ # An unsigned integer indicating the season the episode was in according to the DVD release.
43
+ # Usually is the same as #seasonnumber but can be different.
44
+ # Negative, if invalid
45
+ attr_reader :dvd_season
46
+ # An array of directors in plain text. Empty, if none are listed.
47
+ attr_reader :director
48
+ # An unsigned integer, +0+ (zero) if no image is associated with the episode.
49
+ # Values::
50
+ # +1+:: 4:3 - Indicates an image is a proper 4:3 (1.31 to 1.35) aspect ratio.
51
+ # +2+:: 16:9 - Indicates an image is a proper 16:9 (1.739 to 1.818) aspect ratio.
52
+ # +3+:: Invalid Aspect Ratio - Indicates anything not in a 4:3 or 16:9 ratio. We don't bother listing any other non standard ratios.
53
+ # +4+:: Image too Small - Just means the image is smaller than 300x170.
54
+ # +5+:: Black Bars - Indicates there are black bars along one or all four sides of the image.
55
+ # +6+:: Improper Action Shot - Could mean a number of things, usually used when someone uploads a promotional
56
+ # picture that isn't actually from that episode but does refrence the episode, it could also mean it's a
57
+ # credit shot or that there is writting all over it. It's rarely used since most times an image would just
58
+ # be outright deleted if it falls in this category.
59
+ # Remarks:: If it's +1+ or +2+ TheTvDb assumes it's a proper image, anything above +2+ is considered incorrect and can be replaced by anyone with an account.
60
+ attr_reader :epimgflag
61
+ # A string containing the episode name in the language requested. Will return the English name if no translation is available in the language requested.
62
+ attr_reader :episodename
63
+ # An unsigned integer representing the episode number in its season according to the aired order. Negative, if invalid.
64
+ attr_reader :episodenumber
65
+ # The date the series first aired. +nil+ if not known.
66
+ attr_reader :firstaired
67
+ # An array of the guest stars in that episode. Empty, if none are listed.
68
+ attr_reader :gueststars
69
+ # An alphanumeric string containing the IMDB ID for the series. Can be null.
70
+ attr_reader :imdb_id
71
+ # A two character string indicating the language in accordance with ISO-639-1. Cannot be null.
72
+ attr_reader :language
73
+ # A string containing the overview in the language requested. Will return the English overview if no translation is available in the language requested. Can be null.
74
+ attr_reader :overview
75
+ # An alphanumeric string. Can be null.
76
+ attr_reader :productioncode
77
+ # The average rating users have rated the series out of 10, rounded to 1 decimal place.
78
+ attr_reader :rating
79
+ # An unsigned integer representing the number of users who have rated the series.
80
+ attr_reader :ratingcount
81
+ # An unsigned integer representing the season number for the episode according to the aired order. Negative, if invalid.
82
+ attr_reader :seasonnumber
83
+ # An array of the writers of the episode. Empty, if none are listed.
84
+ attr_reader :writer
85
+ # An unsigned integer. Negative, if invalid.
86
+ # Remarks:: Indicates the absolute episode number and completely ignores seasons.
87
+ # In others words a series with 20 episodes per season will have Season +3+ episode +10+ listed as +50+.
88
+ # The field is mostly used with cartoons and anime series as they may have ambiguous seasons making it
89
+ # easier to use this field.
90
+ attr_reader :absolute_number
91
+ # An unsigned integer indicating the season number this episode comes after. This field is only available for special episodes.
92
+ # Negative, if unavailable.
93
+ attr_reader :airsafter_season
94
+ # An unsigned integer indicating the episode number this special episode airs before.
95
+ # Must be used in conjunction with #airsbefore_season, and not with #airsafter_season.
96
+ # This field is only available for special episodes.
97
+ # Negative, if unavailable.
98
+ attr_reader :airsbefore_episode
99
+ # An unsigned integer indicating the season number this special episode airs before.
100
+ # Should be used in conjunction with #airsbefore_episode for exact placement.
101
+ # This field is only available for special episodes.
102
+ # Negative, if unavailable.
103
+ attr_reader :airsbefore_season
104
+ # Returns the relative path of the episode image. +nil+ if unavailable.
105
+ attr_reader :imagepath_relative
106
+ # Returns the full URI of the episode image. +nil+ if unavailable.
107
+ attr_reader :imagepath_full
108
+ # The last time any changes were made to the episode record. +nil+, if unavailable.
109
+ attr_reader :lastupdated
110
+ # An unsigned integer assigned by TheTvDb to the season. Negative, if invalid.
111
+ attr_reader :seasonid
112
+ # An unsigned integer assigned by TheTvDb to the series. It does not change and will always represent the same series.
113
+ # Negative, if invalid.
114
+ attr_reader :seriesid
115
+ # The date and time the episode image was added to the TheTvDb site. +nil+, if unavailable.
116
+ attr_reader :thumb_added
117
+ # An unsigned integer that represents the height of the episode image in pixels. +0+, if not specified.
118
+ attr_reader :thumb_height
119
+ # An unsigned integer that represents the width of the episode image in pixels. +0+, if not specified.
120
+ attr_reader :thumb_width
121
+
122
+ # Initializes a new Base Episode Record as it was retrieved from a given client.
123
+ # Parameters::
124
+ # +client+:: The TheTvDbParty::Client instance that retrieved the record.
125
+ # +hashValues+:: A Hash{String => String} instance that maps the record element names to their string values.
126
+ def initialize(client, hashValues)
127
+ @client = client
128
+ @hashValues = hashValues
129
+
130
+ read_hash_values
131
+ end
132
+
133
+ # Retrieves the Base Series Record for the series this episode belongs to.
134
+ # Returns:: A TheTvDbParty::BaseSeriesRecord instance that represents the series, or +nil+ if the series record could not be retrieved.
135
+ # See Also:: TheTvDbParty::Client#get_base_series_record
136
+ def get_base_series_record
137
+ @client.get_base_series_record @seriesid
138
+ end
139
+
140
+ private
141
+ def read_hash_values
142
+ @id = @hashValues["id"] ? @hashValues["id"].to_i : -1
143
+ @combined_episodenumber = @hashValues["Combined_episodenumber"] ? @hashValues["Combined_episodenumber"].to_f : -1.0
144
+ @combined_season = @hashValues["Combined_season"] ? @hashValues["Combined_season"].to_f : -1.0
145
+ @dvd_chapter = @hashValues["DVD_chapter"]
146
+ @dvd_discid = @hashValues["DVD_discid"]
147
+ @dvd_episodenumber = @hashValues["DVD_episodenumber"] ? @hashValues["DVD_episodenumber"].to_f : -1.0
148
+ @dvd_season = @hashValues["DVD_season"] ? @hashValues["DVD_season"].to_i : -1
149
+ @director = @hashValues["Director"] ? @hashValues["Director"].split('|').reject { |a| a.nil? || a.empty? } : []
150
+ @epimgflag = @hashValues["EpImgFlag"] ? @hashValues["EpImgFlag"].to_i : 0
151
+ @episodename = @hashValues["EpisodeName"]
152
+ @episodenumber = @hashValues["EpisodeNumber"] ? @hashValues["EpisodeNumber"].to_i : -1
153
+ @firstaired = @hashValues["FirstAired"] ? Date.parse(@hashValues["FirstAired"].to_i) : nil
154
+ @gueststars = @hashValues["GuestStars"] ? @hashValues["GuestStars"].split('|').reject { |a| a.nil? || a.empty? } : []
155
+ @imdb_id = @hashValues["IMDB_ID"]
156
+ @language = @hashValues["Language"]
157
+ @overview = @hashValues["Overview"]
158
+ @productioncode = @hashValues["ProductionCode"]
159
+ @rating = @hashValues["Rating"] ? @hashValues["Rating"].to_f : 0.0
160
+ @ratingcount = @hashValues["RatingCount"] ? @hashValues["RatingCount"].to_i : 0
161
+ @seasonnumber = @hashValues["SeasonNumber"] ? @hashValues["RatingCount"].to_i : -1
162
+ @writer = @hashValues["Writer"] ? @hashValues["Writer"].split('|').reject { |a| a.nil? || a.empty? } : []
163
+ @absolute_number = @hashValues["absolute_number"] ? @hashValues["absolute_number"].to_i : -1
164
+ @airsafter_season = @hashValues["airsafter_season"] ? @hashValues["airsafter_season"].to_i : -1
165
+ @airsbefore_episode = @hashValues["airsbefore_episode"] ? @hashValues["airsbefore_episode"].to_i : -1
166
+ @airsbefore_season = @hashValues["airsbefore_season"] ? @hashValues["airsbefore_season"].to_i : -1
167
+ @imagepath_relative = @hashValues["filename"]
168
+ @imagepath_full = @imagepath_relative ? URI::join(BASE_URL, 'banners/', @imagepath_relative) : nil
169
+ @lastupdated = @hashValues["lastupdated"] ? Time.at(@hashValues["lastupdated"].to_i).to_datetime : nil
170
+ @seasonid = @hashValues["seasonid"] ? @hashValues["seasonid"].to_i : -1
171
+ @seriesid = @hashValues["seriesid"] ? @hashValues["seriesid"].to_i : -1
172
+ @thumb_added = @hashValues["thumb_added"] ? Date.parse(@hashValues["thumb_added"]) : nil
173
+ @thumb_height = @hashValues["thumb_height"] ? @hashValues["thumb_height"].to_i : 0
174
+ @thumb_width = @hashValues["thumb_width"] ? @hashValues["thumb_width"].to_i : 0
175
+
176
+ nil
177
+ end
178
+ end
179
+ end
@@ -1,132 +1,144 @@
1
1
  module TheTvDbParty
2
2
  # The Base Series Record contains all of the information available about a series. It does not include any banner, season, or episode information.
3
+ # See Also:: http://thetvdb.com/wiki/index.php?title=API:Base_Series_Record
3
4
  class BaseSeriesRecord
4
5
 
6
+ # The client instance that retrieved this record.
7
+ # Returns a TheTvDbParty::Client instance
5
8
  attr_reader :client
6
- attr_reader :seriesid, :actors, :added, :addedby, :airs_dayofweek, :airs_time, :bannerpath_full, :bannerpath_relative, :contentrating, :fanartpath_full, :fanartpath_relative, :firstaired, :genres, :imdb_id, :language, :lastupdated, :network, :networkid, :overview, :posterpath_full, :posterpath_relative, :rating, :ratingcount, :runtime, :seriesid, :seriesname, :status, :tvcom_id, :zap2it_id
7
9
 
8
- # @param [TheTvDbParty::Client] client
9
- # @param [Hash{String => String}] hashValues
10
+ # An unsigned integer assigned by our site to the series. It does not change and will always represent the same series. Cannot be null.
11
+ attr_reader :seriesid
12
+ # An array containing the names of actors as string values. Empty if none are listed.
13
+ attr_reader :actors
14
+ # The date/time the series was added to the TheTvDb site. Can be null for older series.
15
+ attr_reader :added
16
+ # An unsigned integer. The ID of the user on our site who added the series to our database. Is nil for older series.
17
+ attr_reader :addedby
18
+ # The full name in English for the day of the week the series airs in plain text. Can be null.
19
+ attr_reader :airs_dayofweek
20
+ # The time of day the series airs on its original network. Can be null.
21
+ attr_reader :airs_time
22
+ # The full path for the highest rated banner for the series, returned as a URI instance.
23
+ attr_reader :bannerpath_full
24
+ # The relative path to the highest rated banner for this series. Retrieve #bannerpath_full get the absolute path.
25
+ attr_reader :bannerpath_relative
26
+ # The rating given to the series based on the US rating system. Can be null or a 4-5 character string.
27
+ attr_reader :contentrating
28
+ # The full path for the highest rated fanart for the series, returned as a URI instance.
29
+ attr_reader :fanartpath_full
30
+ # The relative path to the highest rated fanart for this series. Retrieve #fanartpath_full get the absolute path.
31
+ attr_reader :fanartpath_relative
32
+ # The date the series first aired as a Date instance
33
+ attr_reader :firstaired
34
+ # A list of genres in plain text. Empty if none are listed.
35
+ attr_reader :genres
36
+ # An alphanumeric string containing the IMDB ID for the series. Can be null.
37
+ attr_reader :imdb_id
38
+ # A two character string indicating the language in accordance with ISO-639-1. Cannot be null.
39
+ attr_reader :language
40
+ # The time and date of the last time any changes were made to the series. Can be nil
41
+ attr_reader :lastupdated
42
+ # A string containing the network name in plain text. Can be null.
43
+ attr_reader :network
44
+ # Not in use, will be an unsigned integer if ever used. Can be null.
45
+ attr_reader :networkid
46
+ # A string containing the overview in the language requested. Will return the English overview if no translation is available in the language requested. Can be null.
47
+ attr_reader :overview
48
+ # The full path for the highest rated poster for the series, returned as a URI instance.
49
+ attr_reader :posterpath_full
50
+ # The relative path to the highest rated poster for this series. Retrieve #posterpath_full get the absolute path.
51
+ attr_reader :posterpath_relative
52
+ # The average rating our users have rated the series out of 10, rounded to 1 decimal place.
53
+ attr_reader :rating
54
+ # An unsigned integer representing the number of users who have rated the series.
55
+ attr_reader :ratingcount
56
+ # An unsigned integer representing the runtime of the series in minutes. Negative if unknown.
57
+ attr_reader :runtime
58
+ # Deprecated. An unsigned integer representing the series ID at tv.com. As TV.com now only uses these ID's internally it's of little use and no longer updated. Can be null.
59
+ attr_reader :tvcom_id
60
+ # A string containing the series name in the language you requested. Will return the English name if no translation is found in the language requested. Can be null if the name isn't known in the requested language or English.
61
+ attr_reader :seriesname
62
+ # A string containing either "Ended" or "Continuing". Can be null.
63
+ attr_reader :status
64
+ attr_reader :tvcom_id
65
+ # An alphanumeric string containing the zap2it id. Can be nil.
66
+ attr_reader :zap2it_id
67
+
68
+ # Initializes a new BaseSeriesRecord from the hash that was retrieved by a given client
69
+ # Parameters::
70
+ # +client+:: The TheTvDbParty::Client instance that retrieved the record
71
+ # +hashValues+:: A +Hash{String => String}+ instance that maps the record attribute element names against their values
10
72
  def initialize(client, hashValues)
11
73
  @client = client
12
74
  @hashValues = hashValues
13
- end
14
-
15
- # The client instance that retrieved this record
16
- # @return [TheTvDbParty::Client]
17
- def client; @client end
18
-
19
- # The identifier that is assigned by TheTvDb to the series
20
- # @return [Fixnum] An unsigned integer assigned by our site to the series. It does not change and will always represent the same series. Cannot be nil.
21
- def seriesid; hashValues["id"] ? @hashValues["id"].to_i : -1 end
22
-
23
- # The actors that make up the main cast for the series
24
- # @return [Array<String>] An array containg the names of actors as string values. Empty if none are listed.
25
- def actors; hashValues["Actors"] ? @hashValues["Actors"].split('|').reject { |a| a.nil? || a.empty? } : [] end
26
-
27
- # The day of the week the series airs
28
- # @return [String] The full name in English for the day of the week the series airs in plain text. Can be nil.
29
- def airs_dayofweek; @hashValues["Airs_DayOfWeek"] end
30
-
31
- # The time of day the series airs on its original network.
32
- # @return [Time, NilClass] The time of day the series airs on its original network. Can be nil
33
- # @note The Date portion of the returned value is not relevant
34
- def airs_time; @hashValues["Airs_Time"] ? Time.parse(@hashValues["Airs_Time"]) : nil end
35
-
36
- # The rating given to the series based on the US rating system
37
- # @return [String] Can be nil or a 4-5 character string.
38
- def contentrating; @hashValues["ContentRating"] end
39
-
40
- # The date the series first aired
41
- # @return [Date, NilClass] The date the series first aired. Can be nil
42
- def firstaired; @hashValues["FirstAired"] ? Date.parse(hashValues["FirstAired"]) : nil end
43
-
44
- # The Genres of the series
45
- # @return [Array<String>] A list of genre names. Empty if none are listed
46
- def genres; @hashValues["Genre"] ? @hashValues["Genre"].split('|').reject { |a| a.nil? || a.empty? } : [] end
47
-
48
- # The IMDB ID for the series.
49
- # @return [String] An alphanumeric string containing the IMDB ID for the series. Can be nil.
50
- def imdb_id; @hashValues["IMDB_ID"] end
51
-
52
- # The language of the information that is included in the current record.
53
- # @return [String] A two character string indicating the language in accordance with ISO-639-1. Cannot be nil.
54
- def language; @hashValues["Language"] end
55
-
56
- # The network name on which the series airs
57
- # @return [String] A string containing the network name in plain text. Can be nil.
58
- def network; @hashValues["Network"] end
59
-
60
- # @return [Fixnum] Not in use, will be an unsigned integer if ever used. Can be nil.
61
- def networkid; @hashValues["NetworkID"] ? @hashValues["NetworkID"].to_i : -1 end
62
-
63
- # The overview for the series, if possible in the language requested
64
- # @return [String] A string containing the overview in the language requested. Will return the English overview if no translation is available in the language requested. Can be nil.
65
- def overview; @hashValues["Overview"] end
66
-
67
- # The average rating our users have rated the series out of 10
68
- # @return [Float] The average rating our users have rated the series out of 10, rounded to 1 decimal place. 0.0 if no one has rated the series.
69
- def rating; @hashValues["Rating"] ? @hashValues["Rating"].to_f : 0.0 end
70
75
 
71
- # The number of users who have rated the series
72
- # @return [Fixnum] An unsigned integer representing the number of users who have rated the series.
73
- def ratingcount; @hashValues["RatingCount"] ? @hashValues["RatingCount"].to_i : 0 end
74
-
75
- # The runtime in minutes of an episode of the series.
76
- # @return [Fixnum] An unsigned integer representing the runtime of the series in minutes. -1 if the information is not available.
77
- def runtime; @hashValues["Runtime"] ? @hashValues["Runtime"].to_i : -1 end
78
-
79
- # The series id at tv.com
80
- # @deprecated As TV.com now only uses these ID's internally it's of little use and no longer updated.
81
- # @return [Fixnum, NilClass] An unsigned integer representing the series ID at tv.com. Can be nil.
82
- def tvcom_id; @hashValues["SeriesID"] ? @hashValues["SeriesID"].to_i : nil end
83
-
84
- # The name of the series, if possible in the language requested
85
- # @return [String] A string containing the series name in the language you requested. Will return the English name if no translation is found in the language requested. Can be nil if the name isn't known in the requested language or English.
86
- def seriesname; @hashValues["SeriesName"] end
87
-
88
- # The status of the series
89
- # @return [String] A string containing either "Ended" or "Continuing". Can be nil.
90
- def status; @hashValues["Status"] end
91
-
92
- # The date and time the series was added to the TheTvDb database.
93
- # @return [DateTime, NilClass] Can be nil for older series
94
- def added; @hashValues["added"] ? DateTime.parse(@hashValues["added"]) : nil end
95
-
96
- # The user account identifier of the user who added the series to the database
97
- # @return [Fixnum, NilClass] An unsigned integer. The ID of the user on our site who added the series to our database. Is nil for older series.
98
- def addedby; @hashValues["addedBy"] ? @hashValues["addedBy"].to_i : nil end
99
-
100
- # The path to the highest rated banner for this series.
101
- # @return [String] Returns the relative path to the highest rated banner for this series. Retrieve {#bannerpath_full} get the absolute path.
102
- def bannerpath_relative; @hashValues["banner"] end
103
-
104
- # The path to the highest rated fanart for this series.
105
- # @return [String] Returns the relative path to the highest rated fanart for this series. Retrieve {#fanartpath_full} get the absolute path.
106
- def fanartpath_relative; @hashValues["fanart"] end
107
-
108
- # The path to the highest rated poster for this series.
109
- # @return [String] Returns the relative path to the highest rated poster for this series. Retrieve {#posterpath_full} get the absolute path.
110
- def posterpath_relative; @hashValues["poster"] end
111
-
112
- # The zap2it id for the series
113
- # @return [String] An alphanumeric string containing the zap2it id. Can be nil.
114
- def zap2it_id; @hashValues["zap2it_id"] end
76
+ read_hash_values
77
+ end
115
78
 
116
- # The time and date of the last time any changes were made to the series
117
- # @return [DateTime] An instance containing both time and date of the last update. Can be nil
118
- def lastupdated; @hashValues["lastupdated"] ? Time.at(@hashValues["lastupdated"].to_i).to_datetime : nil end
79
+ # Retrieves episode information of an episode in the series by season and episode number according to default sorting order
80
+ # Parameters::
81
+ # +season_number+:: The number of the season in which the episode appeared.
82
+ # +episode_number+:: The episode number within the season.
83
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance that represents the episode, or +nil+ if the episode could not be found.
84
+ # Remarks:: Specials episodes are ordered within season +0+. Attributes within the returned record indicate at which time (i.e. between which episode the episode should be ordered)
85
+ # See Also:: TheTvDbParty::Client#get_series_season_episode, #get_dvd_season_episode, #get_absolute_episode
86
+ def get_season_episode(season_number, episode_number)
87
+ @client.get_series_season_episode @seriesid, season_number, episode_number
88
+ end
119
89
 
120
- # The full path to the banner for the series.
121
- # @return [URI] The full path for the highest rated banner for the series, returned as a URI instance.
122
- def bannerpath_full; bannerpath_relative ? URI::join(BASE_URL, "banners/", bannerpath_relative) : nil end
90
+ # Retrieves episode information of an episode in the series by season and episode number according to DVD sorting order
91
+ # Parameters::
92
+ # +season_number+:: The number of the season in which the episode appeared.
93
+ # +episode_number+:: The episode number within the season.
94
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance that represents the episode, or +nil+ if the episode could not be found.
95
+ # Remarks:: Specials episodes are ordered within season +0+. Attributes within the returned record indicate at which time (i.e. between which episode the episode should be ordered)
96
+ # See Also:: TheTvDbParty::Client#get_series_dvd_season_episode, #get_season_episode, #get_absolute_episode
97
+ def get_dvd_season_episode(season_number, episode_number)
98
+ @client.get_series_dvd_season_episode @seriesid, season_number, episode_number
99
+ end
123
100
 
124
- # The full path to the banner for the series.
125
- # @return [URI] The full path for the highest rated fanart for the series, returned as a URI instance.
126
- def fanartpath_full; fanartpath_relative ? URI::join(BASE_URL, "banners/", fanartpath_relative) : nil end
101
+ # Retrieves episode information of an episode in the series by season and episode number according to absolute sorting order
102
+ # Parameters::
103
+ # +episode_number+:: The episode number within the series.
104
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance that represents the episode, or +nil+ if the episode could not be found.
105
+ # See Also:: TheTvDbParty::Client#get_series_absolute_episode, #get_season_episode, #get_dvd_season_episode
106
+ def get_absolute_episode(episode_number)
107
+ @client.get_series_absolute_episode @seriesid, episode_number
108
+ end
127
109
 
128
- # The full path to the banner for the series.
129
- # @return [URI] The full path for the highest rated poster for the series, returned as a URI instance.
130
- def posterpath_full; posterpath_relative ? URI::join(BASE_URL, "banners/", posterpath_relative) : nil end
110
+ private
111
+ def read_hash_values
112
+ @seriesid = @hashValues["id"] ? @hashValues["id"].to_i : -1
113
+ @actors = @hashValues["Actors"] ? @hashValues["Actors"].split('|').reject { |a| a.nil? || a.empty? } : []
114
+ @airs_dayofweek = @hashValues["Airs_DayOfWeek"]
115
+ @airs_time = @hashValues["Airs_Time"] ? Time.parse(@hashValues["Airs_Time"]) : nil
116
+ @contentrating = @hashValues["ContentRating"]
117
+ @firstaired = @hashValues["FirstAired"] ? Date.parse(hashValues["FirstAired"]) : nil
118
+ @genres = @hashValues["Genre"] ? @hashValues["Genre"].split('|').reject { |a| a.nil? || a.empty? } : []
119
+ @imdb_id = @hashValues["IMDB_ID"]
120
+ @language = @hashValues["Language"]
121
+ @network = @hashValues["Network"]
122
+ @networkid = @hashValues["NetworkID"] ? @hashValues["NetworkID"].to_i : -1
123
+ @overview = @hashValues["Overview"]
124
+ @rating = @hashValues["Rating"] ? @hashValues["Rating"].to_f : 0.0
125
+ @ratingcount = @hashValues["RatingCount"] ? @hashValues["RatingCount"].to_i : 0
126
+ @runtime = @hashValues["Runtime"] ? @hashValues["Runtime"].to_i : -1
127
+ @tvcom_id = @hashValues["SeriesID"] ? @hashValues["SeriesID"].to_i : nil
128
+ @seriesname = @hashValues["SeriesName"]
129
+ @status = @hashValues["Status"]
130
+ @added = @hashValues["added"] ? DateTime.parse(@hashValues["added"]) : nil
131
+ @addedby = @hashValues["addedBy"] ? @hashValues["addedBy"].to_i : nil
132
+ @bannerpath_relative = @hashValues["banner"]
133
+ @fanartpath_relative = @hashValues["fanart"]
134
+ @posterpath_relative = @hashValues["poster"]
135
+ @zap2it_id = @hashValues["zap2it_id"]
136
+ @lastupdated = @hashValues["lastupdated"] ? Time.at(@hashValues["lastupdated"].to_i).to_datetime : nil
137
+ @bannerpath_full = @bannerpath_relative ? URI::join(BASE_URL, "banners/", @bannerpath_relative) : nil
138
+ @fanartpath_full = @fanartpath_relative ? URI::join(BASE_URL, "banners/", @fanartpath_relative) : nil
139
+ @posterpath_full = @posterpath_relative ? URI::join(BASE_URL, "banners/", @posterpath_relative) : nil
140
+
141
+ nil
142
+ end
131
143
  end
132
144
  end
@@ -1,48 +1,41 @@
1
1
  module TheTvDbParty
2
- # The ThTvDb API client
2
+ # The TheTvDb API client
3
+ #
4
+ # Remarks:: If +nil+ is specified for #apikey, the client will not be able to access the API successfully for most functions
5
+ #
6
+ # The #search method will always be available, even if you do not have a valid API key.
7
+ # Example:: How to use a client to search for a series, and how to get its Base Series Record:: Creates a new client an searches for "The Mentalist"
8
+ # client = TheTvDbParty::Client.new "<myTheTvDbApiKey>"
9
+ # searchResults = client.search "The Mentalist"
10
+ # searchResults.each do |search_result_record|
11
+ # base_series_record = search_result_record.get_base_series_record
12
+ # end
3
13
  class Client
4
14
  include HTTParty
5
15
 
6
- attr_accessor :apikey, :language
16
+ # The API key that is currently in use
17
+ attr_accessor :apikey
18
+
19
+ # Accesses the language currently used by the client when accessing the TheTvDb API.
20
+ attr_accessor :language
7
21
 
8
22
  @language = nil
9
23
 
10
24
  # Creates a new TheTvDb client with the given API key
11
- # @param [String] apikey The API key to use when accessing the ThTvDb programmers API
12
- # @note If nil is specified for _apikey_, the client will not be able to access the API successfully for most functions
13
- # The {#search} method will always be available, even if you do not have a valid API key.
25
+ # apikey:: The API key to use when accessing the ThTvDb programmers API
14
26
  def initialize(apikey)
15
27
  @apikey = apikey
16
28
  end
17
29
 
18
- # Accesses the API key currently used by the client
19
- # @return [String] The API key that is currently in use
20
- def apikey; @apikey end
21
- # @param [String] value The new API key to use
22
- # @return [String] The new value
23
- def apikey=(value) @apikey = value end
24
-
25
- # Accesses the language currently used by the client when accessing the TheTvDb API.
26
- # @return [String] A two-letter string value indicating the language used. May also be 'all' if all availabe translations are retrieved from TheTvDb
27
- # @return [NilClass] nil if the default language (english) should be used.
28
- def language; @language end
29
- # @param [String, NilClass] value A two-letter string value indicating the language used. May also be 'all' if all availabe translations are retrieved from TheTvDb. The may also be nil if the language does not need to be specified explicitly.
30
- # @return [String] The new value
31
- def language=(value) @language = value end
32
-
33
- # This interface allows you to find the id of a series based on its name.
34
- # @param [String] seriesname This is the string you want to search for. If there is an exact match for the parameter, it will be the first result returned.
35
- # @return [Array<TheTvDbParty::SearchSeriesRecord>] An array of records that represent the search results.
36
- # @see http://thetvdb.com/wiki/index.php?title=API:GetSeries
37
- # @note The method call with the account identifier is currently not supported.
38
- # @see #search
30
+ # Alias for #search
39
31
  def get_series(seriesname) search seriesname end
40
32
 
41
33
  # This interface allows you to find the id of a series based on its name.
42
- # @param [String] seriesname This is the string you want to search for. If there is an exact match for the parameter, it will be the first result returned.
43
- # @return [Array<TheTvDbParty::SearchSeriesRecord>] An array of records that represent the search results.
44
- # @see http://thetvdb.com/wiki/index.php?title=API:GetSeries
45
- # @note The method call with the account identifier is currently not supported.
34
+ # Parameters::
35
+ # +seriesname+:: This is the string you want to search for. If there is an exact match for the parameter, it will be the first result returned.
36
+ # Returns:: An array of TheTvDbParty::SearchSeriesRecord instances that represent the search results. Empty if the search does not return any matches.
37
+ # Remarks:: The method call with the account identifier is currently not supported.
38
+ # See Also:: http://thetvdb.com/wiki/index.php?title=API:GetSeries
46
39
  def search(seriesname)
47
40
  http_query = { :seriesname => seriesname }
48
41
  http_query[:language] = @language if @language
@@ -59,9 +52,10 @@ module TheTvDbParty
59
52
  end
60
53
 
61
54
  # Retrieves the Base Series Record for a given series by its series id.
62
- # @param [String, Fixnum] seriesid The TheTvDb assigned unique identifier for the series to access.
63
- # @return [TheTvDbParty::BaseSeriesRecord] A base series record instance or nil if the series could not be found.
64
- def get_base_series_record(seriesid, language = nil)
55
+ # Parameters::
56
+ # +seriesid+:: The TheTvDb assigned unique identifier for the series to access.
57
+ # Returns:: A TheTvDbParty::BaseSeriesRecord instance or +nil+ if the series could not be found.
58
+ def get_base_series_record(seriesid)
65
59
  unless @language
66
60
  request_url = "#{@apikey}/series/#{seriesid}"
67
61
  else
@@ -72,6 +66,80 @@ module TheTvDbParty
72
66
  return nil unless resp["Data"]["Series"]
73
67
  BaseSeriesRecord.new(self, resp["Data"]["Series"])
74
68
  end
69
+
70
+ # Retrieves the base episode record for an episode by its TheTvDb unique identifier
71
+ # Parameters::
72
+ # +episodeid+:: The unique episode identifier of the episode to access
73
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance representing the episode, or +nil+ if the record was not found.
74
+ def get_base_episode_record(episodeid)
75
+ unless @language
76
+ request_url = "#{@apikey}/episodes/#{episodeid}"
77
+ else
78
+ request_url = "#{@apikey}/episodes/#{episodeid}/#{@language}.xml"
79
+ end
80
+ request_url = URI::join(BASE_URL, 'api/', request_url)
81
+ get_base_episode_record_from_url request_url
82
+ end
83
+
84
+ # Retrieves the base episode record for an episode by its default ordering in a series.
85
+ # Parameters::
86
+ # +seriesid+:: The TheTvDb unique identifier for the series to which the episode belongs.
87
+ # +season_number+:: The number of the season in which the episode appeared.
88
+ # +episode_number+:: The episode number within the season
89
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance representing the episode or +nil+ if the record was not found.
90
+ # Remarks:: Specials episodes are ordered within season +0+. Attributes within the returned record indicate at which time (i.e. between which episode the episode should be ordered)
91
+ # See Also:: #get_series_dvd_season_episode, #get_series_absolute_episode, #get_base_episode_record
92
+ def get_series_season_episode(seriesid, season_number, episode_number)
93
+ unless @language
94
+ request_url = "#{@apikey}/series/#{seriesid}/default/#{season_number}/#{episode_number}"
95
+ else
96
+ request_url = "#{@apikey}/series/#{seriesid}/default/#{season_number}/#{episode_number}/#{@language}.xml"
97
+ end
98
+ request_url = URI.join(BASE_URL, 'api/', request_url)
99
+ get_base_episode_record_from_url request_url
100
+ end
101
+
102
+ # Retrieves the base episode record for an episode by its DVD ordering in a series.
103
+ # Parameters::
104
+ # +seriesid+:: The TheTvDb unique identifier for the series to which the episode belongs.
105
+ # +season_number+:: The number of the season in which the episode appeared.
106
+ # +episode_number+:: The episode number within the season
107
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance representing the episode or +nil+ if the record was not found.
108
+ # Remarks:: Specials episodes are ordered within season +0+. Attributes within the returned record indicate at which time (i.e. between which episode the episode should be ordered)
109
+ # See Also:: #get_series_season_episode, #get_series_absolute_episode, #get_base_episode_record
110
+ def get_series_dvd_season_episode(seriesid, season_number, episode_number)
111
+ unless @language
112
+ request_url = "#{@apikey}/series/#{seriesid}/dvd/#{season_number}/#{episode_number}"
113
+ else
114
+ request_url = "#{@apikey}/series/#{seriesid}/dvd/#{season_number}/#{episode_number}/#{@language}.xml"
115
+ end
116
+ request_url = URI.join(BASE_URL, 'api/', request_url)
117
+ get_base_episode_record_from_url request_url
118
+ end
119
+
120
+ # Retrieves the base episode record for an episode by its absolute ordering in a series.
121
+ # Parameters::
122
+ # +seriesid+:: The TheTvDb unique identifier for the series to which the episode belongs.
123
+ # +episode_number+:: The absolute episode number within the series
124
+ # Returns:: A TheTvDbParty::BaseEpisodeRecord instance representing the episode or +nil+ if the record was not found.
125
+ # Remarks:: Specials episodes are ordered within season +0+. Attributes within the returned record indicate at which time (i.e. between which episode the episode should be ordered)
126
+ # See Also:: #get_series_season_episode, #get_series_dvd_season_episode, #get_base_episode_record
127
+ def get_series_absolute_episode(seriesid, episode_number)
128
+ unless @language
129
+ request_url = "#{@apikey}/series/#{seriesid}/absolute/#{episode_number}"
130
+ else
131
+ request_url = "#{@apikey}/series/#{seriesid}/absolute/#{episode_number}/#{@language}.xml"
132
+ end
133
+ request_url = URI.join(BASE_URL, 'api/', request_url)
134
+ get_base_episode_record_from_url request_url
135
+ end
136
+
137
+ private
138
+ def get_base_episode_record_from_url(request_url)
139
+ resp = self.class.get(request_url).parsed_response
140
+ return nil unless resp["Episode"]
141
+ BaseEpisodeRecord.new(self, resp["Episode"])
142
+ end
75
143
  end
76
144
  end
77
145
 
@@ -1,82 +1,74 @@
1
1
  module TheTvDbParty
2
2
  # Represents one record within the search results for a series search
3
- # @example Getting a list of search results from a client
4
- # results = TheTvDbParty::Client.new(nil).search "The Mentalist"
5
- # @example Using the search result record to fetch the Base Series Record
6
- # base_series_record = TheTvDbParty::Client.new(nil).get_base_series_record search_series_record.seriesid
3
+ # See Also:: http://thetvdb.com/wiki/index.php?title=API:GetSeries
7
4
  class SearchSeriesRecord
8
5
 
6
+ # The client instance that retrieved this record
9
7
  attr_reader :client
10
- attr_reader :id, :seriesid, :language, :seriesname, :aliasnames, :bannerpath_relative, :overview, :firstaired, :imdb_id, :zap2it_id, :network, :bannerpath_full
8
+ # *Deprecated:* #id is only included to be backwards compatible with the old API and is deprecated.
9
+ #
10
+ # The unique TheTvDb identifier to access the more detailed Base Series Record and Full Series Record.
11
+ # See Also:: #seriesid
12
+ attr_reader :id
13
+ # The unique TheTvDb identifier to access the more detailed Base Series Record and Full Series Record.
14
+ # Negative, if invalid.
15
+ attr_reader :seriesid
16
+ # Returns a two digit string indicating the language.
17
+ attr_reader :language
18
+ # Returns a string with the series name for the language indicated
19
+ attr_reader :seriesname
20
+ # An array of alias names if the series has any other names in that language. Empty, if none are listed.
21
+ attr_reader :aliasnames
22
+ # The relative path to the highest rated banner for this series. Retrieve #bannerpath_full get the absolute path.
23
+ attr_reader :bannerpath_relative
24
+ # Returns the overview for the series
25
+ attr_reader :overview
26
+ # The first aired date for the series as a Date instance.
27
+ attr_reader :firstaired
28
+ # Returns the IMDB id for the series if known. Otherwise, +nil+.
29
+ attr_reader :imdb_id
30
+ # Returns the zap2it ID if known. Otherwise, +nil+.
31
+ attr_reader :zap2it_id
32
+ # Returns the Network name if known; Otherwise, +nil+.
33
+ attr_reader :network
34
+ # The full path for the highest rated banner for the series, returned as a URI instance.
35
+ attr_reader :bannerpath_full
11
36
 
12
37
  # Initializes a new Search Series Record as is was retrieved from the TheTvDb API
13
- # @param [TheTvDbParty::Client] client The client instance that retrieved the record
14
- # @param [Hash{String => String}] hashValues A Hash instance that maps the record attribute element names against their values represented as strings.
38
+ # Parameters::
39
+ # +client+:: The TheTvDbParty::Client instance that retrieved the record
40
+ # +hashValues+:: A Hash{String => String} instance that maps the record attribute element names against their values represented as strings.
15
41
  def initialize(client, hashValues)
16
42
  @client = client
17
43
  @hashValues = hashValues
18
- end
19
-
20
- # The client instance that retrieved this record
21
- # @return [TheTvDbParty::Client]
22
- def client; @client end
23
-
24
- # The unique TheTvDb identifier to access the more detailed Base Series Record and Full Series Record
25
- # @deprecated {#id} is only included to be backwards compatible with the old API and is deprecated.
26
- # @return [Fixnum] Returns an unsigned integer, or -1 if the record is invalid
27
- # @see #seriesid
28
- def id; @hashValues["id"] ? @hashValues["id"].to_i : -1 end
29
-
30
- # The unique TheTvDb identifier to access the more detailed Base Series Record and Full Series Record
31
- # @return [Fixnum] Returns an unsigned integer, or -1 if the record is invalid
32
- def seriesid; @hashValues["seriesid"] ? @hashValues["seriesid"].to_i : -1 end
33
-
34
- # The language used for the information included in the current record
35
- # @return [String] Returns a two digit string indicating the language.
36
- def language; @hashValues["language"] end
37
-
38
- # The name of the Series
39
- # @return [String] Returns a string with the series name for the language indicated
40
- def seriesname; @hashValues["SeriesName"] end
41
-
42
- # Other names of the series than the information returned by {#seriesname}
43
- # @return [Array<String>] An array of alias names if the series has any other names in that language. Empty if the record does not have any aliases
44
- def aliasnames; @hashValues["AliasNames"] ? @hashValues["AliasNames"].split('|').reject { |a| a.nil? || a.empty? } : [] end
45
44
 
46
- # The path to the highest rated banner for this series.
47
- # @return [String] Returns the relative path to the highest rated banner for this series. Retrieve {#bannerpath_full} get the absolute path.
48
- def bannerpath_relative; @hashValues["banner"] end
49
-
50
- # A short summary of the series
51
- # @return [String] Returns the overview for the series
52
- def overview; @hashValues["Overview"] end
53
-
54
- # The first aired date of the series
55
- # @return [Date] Returns the first aired date for the series as a Date instance
56
- # @return [NilClass] Returns nil if the information is not available
57
- def firstaired; @hashValues["FirstAired"] ? Date.parse(@hashValues["FirstAired"]) : nil end
58
-
59
- # The IMDB id for the series
60
- # @return [String] Returns the IMDB id for the series if known. Otherwise, nil
61
- def imdb_id; @hashValues["IMDB_ID"] end
62
-
63
- # The zap2it id for the series
64
- # @return [String] Returns the zap2it ID if known. Otherwise, nil
65
- def zap2it_id; @hashValues["zap2it_id"] end
66
-
67
- # The network name on which the series aires
68
- # @return [String] Returns the Network name if known; Otherwise, nil.
69
- def network; @hashValues["Network"] end
70
-
71
- # The full path to the banner for the series.
72
- # @return [URI] The full path for the highest rated banner for the series, returned as a URI instance.
73
- def bannerpath_full; bannerpath_relative ? URI::join(BASE_URL, "banners/", bannerpath_relative) : nil end
45
+ read_hash_values
46
+ end
74
47
 
75
48
  # Retrieves the Base Series Record for the series
76
- # @return [TheTvDbParty::BaseSeriesRecord] The Base Series Record for the series
77
- # @see TheTvDbParty::Client.get_base_series_record
49
+ # Return:: A TheTvDbParty::BaseSeriesRecord instance that represents the series; or +nil+, if the record could not be retrieved.
50
+ # See Also:: TheTvDbParty::Client#get_base_series_record
78
51
  def get_base_series_record
79
- client.get_base_series_record seriesid
52
+ @client.get_base_series_record @seriesid
53
+ end
54
+
55
+ private
56
+ def read_hash_values
57
+ def client; @client end
58
+ def id; @hashValues["id"] ? @hashValues["id"].to_i : -1 end
59
+ def seriesid; @hashValues["seriesid"] ? @hashValues["seriesid"].to_i : -1 end
60
+ def language; @hashValues["language"] end
61
+ def seriesname; @hashValues["SeriesName"] end
62
+ def aliasnames; @hashValues["AliasNames"] ? @hashValues["AliasNames"].split('|').reject { |a| a.nil? || a.empty? } : [] end
63
+ def bannerpath_relative; @hashValues["banner"] end
64
+ def overview; @hashValues["Overview"] end
65
+ def firstaired; @hashValues["FirstAired"] ? Date.parse(@hashValues["FirstAired"]) : nil end
66
+ def imdb_id; @hashValues["IMDB_ID"] end
67
+ def zap2it_id; @hashValues["zap2it_id"] end
68
+ def network; @hashValues["Network"] end
69
+ def bannerpath_full; bannerpath_relative ? URI::join(BASE_URL, "banners/", bannerpath_relative) : nil end
70
+
71
+ nil
80
72
  end
81
73
  end
82
74
  end
@@ -1,4 +1,4 @@
1
1
  module TheTvDbParty
2
- # The current version of the `thetvdb_party` gem
3
- VERSION = "0.0.8.pre"
2
+ # The current version of the *thetvdb_party* gem
3
+ VERSION = "0.0.10.pre"
4
4
  end
@@ -0,0 +1,26 @@
1
+ require 'rspec'
2
+ require 'thetvdb_party'
3
+
4
+ describe 'BaseEpisodeRecord' do
5
+
6
+ before(:each) do
7
+ @valid_record = TheTvDbParty::BaseEpisodeRecord.new(nil,
8
+ {
9
+ "id" => "0"
10
+ }
11
+ )
12
+ @invalid_record = TheTvDbParty::BaseEpisodeRecord.new(nil, { })
13
+ end
14
+
15
+ it 'should have an id when valid' do
16
+ expect @valid_record.id == 0
17
+ end
18
+
19
+ it 'should have a negative id when invalid' do
20
+ expect @invalid_record.id < 0
21
+ end
22
+
23
+ it 'should not instantiate when created without hash values' do
24
+ expect{TheTvDbParty::BaseEpisodeRecord.new(nil, nil)}.to raise_error
25
+ end
26
+ end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'thetvdb_party/version'
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  It uses compression to minimize bandwith when accessing Full Series Records.
16
16
  EOF
17
17
  spec.license = "MIT"
18
- spec.homepage = "https://rubygems.org/gems/thetvdb_party"
18
+ spec.homepage = "https://github.com/couven92/thetvdb_party"
19
19
  spec.files = `git ls-files -z`.split("\x0")
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thetvdb_party
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8.pre
4
+ version: 0.0.10.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fredrik Høisæther Rasch
@@ -82,6 +82,7 @@ executables: []
82
82
  extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
+ - ".gitattributes"
85
86
  - ".gitignore"
86
87
  - ".rspec"
87
88
  - Gemfile
@@ -89,14 +90,15 @@ files:
89
90
  - README.md
90
91
  - Rakefile
91
92
  - lib/thetvdb_party.rb
93
+ - lib/thetvdb_party/baseepisoderecord.rb
92
94
  - lib/thetvdb_party/baseseriesrecord.rb
93
95
  - lib/thetvdb_party/client.rb
94
96
  - lib/thetvdb_party/searchseriesrecord.rb
95
97
  - lib/thetvdb_party/version.rb
96
98
  - spec/spec_helper.rb
97
- - spec/thetvdb_party_spec.rb
99
+ - spec/thetvdb_party/baseepisoderecord_spec.rb
98
100
  - thetvdb_party.gemspec
99
- homepage: https://rubygems.org/gems/thetvdb_party
101
+ homepage: https://github.com/couven92/thetvdb_party
100
102
  licenses:
101
103
  - MIT
102
104
  metadata: {}
@@ -127,5 +129,5 @@ specification_version: 4
127
129
  summary: Ruby Gem for accessing the TheTVDB programmers API
128
130
  test_files:
129
131
  - spec/spec_helper.rb
130
- - spec/thetvdb_party_spec.rb
132
+ - spec/thetvdb_party/baseepisoderecord_spec.rb
131
133
  has_rdoc:
@@ -1,32 +0,0 @@
1
- require 'thetvdb_party'
2
-
3
- describe 'Client.search' do
4
-
5
- before(:each) do
6
- @client = TheTvDbParty::Client.new("5CB46CA60629B0DD")
7
- end
8
-
9
- it 'should return matches for "The Mentalist"' do
10
- matches = @client.search "The Mentalist"
11
- expect matches.count > 0
12
- end
13
-
14
- it 'should return more than one match for "Star Trek"' do
15
- matches = @client.search "Star Trek"
16
- expect matches.count > 1
17
- end
18
- end
19
-
20
- describe 'Client.get_base_series_record' do
21
- before(:each) do
22
- @client = TheTvDbParty::Client.new("5CB46CA60629B0DD")
23
- end
24
-
25
- it 'should return records that match the search result' do
26
- matches = @client.search "Star Trek"
27
- matches.each do |ssr|
28
- bsr = @client.get_base_series_record(ssr.seriesid)
29
- expect bsr.seriesname == ssr.seriesname
30
- end
31
- end
32
- end