tvdbjson 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/tvdbjson/episode.rb +42 -0
- data/lib/tvdbjson/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d402112883f10ef7fde9d3f7b3b2094f511253
|
4
|
+
data.tar.gz: 59bdbe4dab687f6c6fcff256d7d331dcd6d7fa3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69585683eef478df42459d47ac9cc667d88e93a52e3463e658aa1ff0b17a1b99e24eda0d193a16c2c2a50d4edda7e721554148a75efd562ca0b83e7d148d7dcc
|
7
|
+
data.tar.gz: 740017e3bdd296f850a130820ed1193a974d626a05513e7806ce48b7f62624cbb15257aa58baead652b5cc6a8024bc08a4241832c7b79aee43a83714fc88b7b8
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ A super-unofficial Ruby Gem for thetvdb.com ['swagger' api](https://api.thetvdb.
|
|
5
5
|
|
6
6
|
### Install the gem
|
7
7
|
|
8
|
-
Visit [rubygems](https://rubygems.org/gems/
|
8
|
+
Visit [rubygems](https://rubygems.org/gems/tvdbjson) for instructions on how to install this gem via the command line, or for how to include it in your gemfile.
|
9
9
|
|
10
10
|
### Create some environment variables
|
11
11
|
[Create an account](https://www.thetvdb.com/?tab=register) and [register for your API Key](https://www.thetvdb.com/?tab=apiregister) on thetvdb.com
|
@@ -66,6 +66,7 @@ You're going to need to read the source for full details, as this gem is a work
|
|
66
66
|
search_options = { :series_id => game_of_thrones.id, :type => "season", :subkey => 5 }
|
67
67
|
image_results = Tvdbjson::Image.search_by_series_and_season(search_options, auth)
|
68
68
|
|
69
|
+
# Or graphical fanart of a Television series (the other option being text)
|
69
70
|
search_options = { :series_id => game_of_thrones.id, :type => "fanart", :subkey => "graphical" }
|
70
71
|
image_results = Tvdbjson::Image.search_by_series_and_season(search_options, auth)
|
71
72
|
|
@@ -73,6 +74,10 @@ You're going to need to read the source for full details, as this gem is a work
|
|
73
74
|
search_query = { :series_id => game_of_thrones.id, :season_number => 6, :episode_number => 9 }
|
74
75
|
episode_results = Tvdbjson::Episode.search_by_season_and_episode(search_query,auth)
|
75
76
|
|
77
|
+
# Return all episodes, on all pages for a series (may take a while)
|
78
|
+
search_options = { :series_id => game_of_thrones.id }
|
79
|
+
episode_results = Tvdbjson::Episode.all_episodes(search_options,auth)
|
80
|
+
|
76
81
|
```
|
77
82
|
|
78
83
|
## License
|
data/lib/tvdbjson/episode.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "pry-byebug"
|
1
2
|
module Tvdbjson
|
2
3
|
class Episode
|
3
4
|
include Tvdbjson::Hashable
|
@@ -15,6 +16,43 @@ module Tvdbjson
|
|
15
16
|
@overview = options[:overview]
|
16
17
|
end
|
17
18
|
|
19
|
+
def self.all_episodes(options = {}, authentication)
|
20
|
+
raise Tvdbjson::RequiredSeriesIdMissingError if !options[:series_id]
|
21
|
+
raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication)
|
22
|
+
|
23
|
+
hash = {
|
24
|
+
:method => "GET",
|
25
|
+
:uri => "/series/#{options[:series_id]}/episodes",
|
26
|
+
:params => { "page" => 1 }
|
27
|
+
}
|
28
|
+
|
29
|
+
# Create an empty array for all episodes
|
30
|
+
arr = []
|
31
|
+
|
32
|
+
# Receive the first page of results
|
33
|
+
response = send_authenticated_request(hash, authentication)
|
34
|
+
|
35
|
+
# Store the Page count to retrieve additional pages in the future
|
36
|
+
page_count = get_page_count_from_response(response)
|
37
|
+
|
38
|
+
# Whilst we have the response object for page 1, let's add it to our array
|
39
|
+
arr.concat( Episode.from_response(response,options[:series_id]) )
|
40
|
+
|
41
|
+
# Now to process the additional pages (starting with page 2)
|
42
|
+
(2..page_count).each do |page_number|
|
43
|
+
hash = {
|
44
|
+
:method => "GET",
|
45
|
+
:uri => "/series/#{options[:series_id]}/episodes",
|
46
|
+
:params => { "page" => page_number }
|
47
|
+
}
|
48
|
+
response = send_authenticated_request(hash, authentication)
|
49
|
+
arr.concat( Episode.from_response(response,options[:series_id]) )
|
50
|
+
end
|
51
|
+
|
52
|
+
arr
|
53
|
+
|
54
|
+
end
|
55
|
+
|
18
56
|
def self.search_by_season_and_episode(options = {}, authentication)
|
19
57
|
raise Tvdbjson::RequiredSeriesIdMissingError if !options[:series_id]
|
20
58
|
raise Tvdbjson::RequiredSearchParamMissingError if !options[:season_number]
|
@@ -54,5 +92,9 @@ module Tvdbjson
|
|
54
92
|
results_array
|
55
93
|
end
|
56
94
|
|
95
|
+
def self.get_page_count_from_response(response)
|
96
|
+
response.parsed_response["links"]["last"]
|
97
|
+
end
|
98
|
+
|
57
99
|
end
|
58
100
|
end
|
data/lib/tvdbjson/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tvdbjson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Tennant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|