thetvdb_party 0.0.13.pre → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce7a724e350ab2d80b5e574e8a796e804d878bf7
4
- data.tar.gz: 5a4c17f77cd912885baca62f0af0a1350a3848c4
3
+ metadata.gz: 8472d976bd85da62543a93220c01863222a780f4
4
+ data.tar.gz: 206d4ec2214ef2c0cdf80751a83bb175b2ba0533
5
5
  SHA512:
6
- metadata.gz: f9aa0d56803fd445b98eeb30d9ff4dff8694203bfcaea746cf36411727ac05d67fbdd3b21c67a5b39ff27cc39cb93bca2610d5a0b74db06d143f247bc1347f27
7
- data.tar.gz: d0effd5dc336ac05356c698f156b4d82e7b8c584fd42db41f31a9c2494a40b4d6d3b904b6b3ffbac1bcf546613e225963016b21d0b63ddad22ce035923f2c8c4
6
+ metadata.gz: 60de102168d193eb91044c38579a99bbc4d2eb13b5f30d1d0500452633412650f2d226682bac4823a4f8bc1e5b67e3a8e64db64383a33219557ba3fa8b44ff86
7
+ data.tar.gz: e4476c01fa35228441a03d046c2f29d45d6f94f3a85279786b1c62a093df1fea2a653d67b214f00e5036a0a80567c352d98622470fb8b2fee89c200fd312fd21
data/.gitignore CHANGED
@@ -215,3 +215,6 @@ ModelManifest.xml
215
215
  *.a
216
216
  *.gem
217
217
  mkmf.log
218
+
219
+ # Ignore environment file
220
+ .env.yml
@@ -0,0 +1,10 @@
1
+ # Rename this file to .env.yml
2
+ # Add account settings and API keys here.
3
+ # This file should be listed in .gitignore to keep your settings secret!
4
+ # Each entry gets set as a local environment variable.
5
+ # This file overrides ENV variables in the Unix shell.
6
+ # For example, setting:
7
+ # GMAIL_USERNAME: 'Your_Gmail_Username'
8
+ # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
9
+
10
+ TVDB_API_KEY: '<YOUR API KEY>'
@@ -1,6 +1,8 @@
1
1
  require 'httparty'
2
+ require 'zip'
2
3
 
3
4
  require 'thetvdb_party/baseseriesrecord'
5
+ require 'thetvdb_party/fullseriesrecord'
4
6
  require 'thetvdb_party/baseepisoderecord'
5
7
  require 'thetvdb_party/client'
6
8
  require 'thetvdb_party/searchseriesrecord'
@@ -9,6 +11,7 @@ require 'thetvdb_party/banner'
9
11
  require 'thetvdb_party/version'
10
12
  require 'thetvdb_party/banner'
11
13
  require 'thetvdb_party/actor'
14
+ require 'thetvdb_party/all'
12
15
 
13
16
  # thetvdb_party gem root namespace
14
17
  module TheTvDbParty
@@ -1,34 +1,40 @@
1
1
  module TheTvDbParty
2
2
  class AllSeriesInformation
3
3
 
4
- attr_reader :actors, :banners, :series, :episodes
5
-
6
- def initialize(client, zip_file)
4
+ attr_reader :client, :actors, :banners, :full_series_record
5
+
6
+ def initialize(client, zip_buffer)
7
7
  @client = client
8
8
 
9
- unzip_file(zip_file)
9
+ unzip_file(zip_buffer)
10
10
 
11
11
  end
12
12
 
13
13
  private
14
- def unzip_file(zip_file)
15
- @series = BaseSeriesRectord.new(@client, zip_file.glob("Series").input_stream.read)
14
+ def unzip_file(zip_buffer)
16
15
  @actors = []
17
16
  @banners = []
18
- @episodes = []
19
-
20
- zip_file.glob("Actors").each do |actor|
21
- @actors << Actor.new(@client, actor.input_stream.read)
22
- end
23
-
24
- zip_file.glob("Banners").each do |banner|
25
- @banners << Banner.new(@client, banner.input_stream.read)
26
- end
27
-
28
- zip_file.glob("Episode").each do |episode|
29
- @episodes << Episode.new(@client, episode.input_stream.read)
17
+
18
+ zip_file = Zip::InputStream.open(StringIO.new(zip_buffer))
19
+
20
+ while entry = zip_file.get_next_entry
21
+ case entry.name
22
+ when "en.xml"
23
+ full_hash = MultiXml.parse(entry.get_input_stream.read)
24
+ @full_series_record = FullSeriesRecord.new(@client, full_hash["Data"])
25
+ when "actors.xml"
26
+ actors_hash = MultiXml.parse(entry.get_input_stream.read)
27
+
28
+ actors_hash["Actors"]["Actor"].each do |a|
29
+ actors << Actor.new(@client, a)
30
+ end if actors_hash["Actors"]
31
+ when "banners.xml"
32
+ banners_hash = MultiXml.parse(entry.get_input_stream.read)
33
+ banners_hash["Banners"]["Banner"].each do |b|
34
+ banners << Banner.new(@client, b)
35
+ end if banners_hash["Banners"]
36
+ end
30
37
  end
31
-
32
38
  end
33
39
  end
34
40
  end
@@ -121,6 +121,10 @@ module TheTvDbParty
121
121
  @client.get_series_actors @seriesid
122
122
  end
123
123
 
124
+ def get_full_series_record
125
+ @client.get_full_series_record @seriesid
126
+ end
127
+
124
128
  private
125
129
  def read_hash_values
126
130
  begin
@@ -179,17 +179,33 @@ module TheTvDbParty
179
179
 
180
180
  def get_series_all(seriesid)
181
181
  unless @language
182
- request_url = "#{@apikey}/series/#{seriesid}/all"
182
+ request_url = "#{@apikey}/series/#{seriesid}/all/en.zip"
183
183
  else
184
184
  request_url = "#{@apikey}/series/#{seriesid}/all/#{@language}.zip"
185
185
  end
186
186
 
187
+ request_url = URI.join(BASE_URL, 'api/', request_url)
187
188
  resp = self.class.get(request_url)
188
189
 
189
- return nil unless resp.body.extname == ".zip"
190
+ return nil unless resp.body
191
+
192
+ AllSeriesInformation.new(self, resp.body)
193
+
194
+ end
195
+
196
+ def get_full_series_record(seriesid)
197
+ unless @language
198
+ request_url = "#{@apikey}/series/#{seriesid}/all"
199
+ else
200
+ request_url = "#{@apikey}/series/#{seriesid}/all/#{@language}.xml"
201
+ end
202
+ request_url = URI.join(BASE_URL, 'api/', request_url)
203
+
204
+ resp = self.class.get(request_url).parsed_response
190
205
 
191
- AllSeriesInformation.new(@client, resp.body)
206
+ return nil unless resp["Data"]
192
207
 
208
+ FullSeriesRecord.new self, resp["Data"]
193
209
  end
194
210
 
195
211
  private
@@ -0,0 +1,20 @@
1
+ module TheTvDbParty
2
+ class FullSeriesRecord < BaseSeriesRecord
3
+
4
+ attr_reader :episodes
5
+
6
+ def initialize(client, hashValues)
7
+ super client, hashValues["Series"]
8
+
9
+ episodesHashValue = hashValues["Episode"]
10
+ case episodesHashValue
11
+ when Array
12
+ @episodes = episodesHashValue.map { |episodeHashValues| BaseEpisodeRecord.new client, episodeHashValues }
13
+ when Hash
14
+ @episodes = [ BaseEpisodeRecord.new(client, episodesHashValue) ]
15
+ else
16
+ @episodes = []
17
+ end
18
+ end
19
+ end
20
+ end
@@ -52,6 +52,10 @@ module TheTvDbParty
52
52
  @client.get_base_series_record @seriesid
53
53
  end
54
54
 
55
+ def get_full_series_record
56
+ @client.get_full_series_record @seriesid
57
+ end
58
+
55
59
  private
56
60
  def read_hash_values
57
61
  begin
@@ -1,4 +1,4 @@
1
1
  module TheTvDbParty
2
2
  # The current version of the *thetvdb_party* gem
3
- VERSION = "0.0.13.pre"
3
+ VERSION = "0.1.0"
4
4
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  # This file was generated by the `rspec --init` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause
@@ -16,6 +18,7 @@
16
18
  # users commonly want.
17
19
  #
18
20
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+
19
22
  RSpec.configure do |config|
20
23
  # rspec-expectations config goes here. You can use an alternate
21
24
  # assertion/expectation library such as wrong or the stdlib/minitest
@@ -40,6 +43,11 @@ RSpec.configure do |config|
40
43
  mocks.verify_partial_doubles = true
41
44
  end
42
45
 
46
+ env_file = '.env.yml'
47
+ YAML.load(File.open(env_file)).each do |key, value|
48
+ ENV[key.to_s] = value
49
+ end if File.exist?(env_file)
50
+
43
51
  # The settings below are suggested to provide a good initial experience
44
52
  # with RSpec, but feel free to customize to your heart's content.
45
53
  =begin
@@ -0,0 +1,28 @@
1
+ require 'rspec'
2
+ require 'thetvdb_party'
3
+
4
+ describe 'TheTvDbParty::AllSeriesInformation' do
5
+
6
+ before(:each) do
7
+ @client = TheTvDbParty::Client.new(ENV["TVDB_API_KEY"])
8
+ results = @client.search('The Big Bang Theory')
9
+ @all_series_info = @client.get_series_all(results.first.seriesid)
10
+ expect(@all_series_info).to_not be_nil
11
+ end
12
+
13
+
14
+ it 'should have a valid client' do
15
+ expect(@all_series_info.client).to be_an_instance_of(TheTvDbParty::Client)
16
+ end
17
+
18
+ it 'should contain a series class' do
19
+ expect(@all_series_info.full_series_record).to be_an_instance_of(TheTvDbParty::FullSeriesRecord)
20
+ end
21
+
22
+ it 'should contain a list of banner classes' do
23
+ expect(@all_series_info.banners).to be_an_instance_of(Array)
24
+ @all_series_info.banners.each do |b|
25
+ expect(b).to be_an_instance_of(TheTvDbParty::Banner)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'rspec'
2
+ require 'thetvdb_party'
3
+
4
+ describe 'TheTvDbParty::FullSeriesRecord' do
5
+
6
+ it 'should have an empty episode list if no episodes are specified' do
7
+ record = TheTvDbParty::FullSeriesRecord.new nil, { "Series" => { } }
8
+ expect(record.episodes).to be_an(Array)
9
+ expect(record.episodes).to be_empty
10
+ end
11
+
12
+ it 'should have a single entry episode list, if only one Episode is specified' do
13
+ record = TheTvDbParty::FullSeriesRecord.new nil, { "Series" => { }, "Episode" => { } }
14
+ expect(record.episodes).to be_an(Array)
15
+ expect(record.episodes.length).to eq 1
16
+ record.episodes.each { |episode_record| expect(episode_record).to be_a(TheTvDbParty::BaseEpisodeRecord) }
17
+ end
18
+
19
+ it 'should have multiple entries in the episode list, if more than one Episode is specified' do
20
+ record = TheTvDbParty::FullSeriesRecord.new nil, { "Series" => { }, "Episode" => [ { }, { } ] }
21
+ expect(record.episodes).to be_an(Array)
22
+ expect(record.episodes.length).to be > 1
23
+ record.episodes.each { |episode_record| expect(episode_record).to be_a(TheTvDbParty::BaseEpisodeRecord) }
24
+ end
25
+
26
+ it 'should not instantiate when constructed with nil hash values' do
27
+ expect { TheTvDbParty::FullSeriesRecord.new nil, nil }.to raise_error
28
+ end
29
+
30
+ it 'should not instantiate when constructed with a hash missing the Series tag' do
31
+ expect { TheTvDbParty::FullSeriesRecord.new nil, { } }.to raise_error
32
+ end
33
+ end
@@ -19,4 +19,19 @@ describe 'TheTvDbParty' do
19
19
  expect(base_series_record.seriesid).to eq result_record.seriesid
20
20
  end
21
21
  end
22
+
23
+ it 'should find the Full Series Record for search results and this should include an episode list' do
24
+ client = TheTvDbParty::Client.new(ENV["TVDB_API_KEY"])
25
+ pending "No API key available, test cannot run. Configure .env file to include an api key." unless client.apikey
26
+ client.search("The Mentalist").each do |result_record|
27
+ expect(result_record).to be_a TheTvDbParty::SearchSeriesRecord
28
+ full_series_record = result_record.get_full_series_record
29
+ expect(full_series_record).to be_a TheTvDbParty::FullSeriesRecord
30
+ expect(full_series_record.seriesid).to eq result_record.seriesid
31
+ expect(full_series_record.episodes.length).to be > 0
32
+ full_series_record.episodes.each do |base_episode_record|
33
+ expect(base_episode_record.seriesid).to eq full_series_record.seriesid
34
+ end
35
+ end
36
+ end
22
37
  end
@@ -10,7 +10,6 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["fredrik.rasch@gmail.com", "tim.teige91@gmail.com", "peterme@peterme.net"]
11
11
  spec.summary = "Ruby Gem for accessing the TheTVDB programmers API"
12
12
  spec.description = <<-EOF
13
- NOTE: This Gem is currently in its pre-alpha development stadium and currently only supports minimal capability.
14
13
  The thetvdb_party gem accesses the TheTvDB programmers API as it is described on \"http://thetvdb.com/wiki/index.php/Programmers_API\".
15
14
  It uses compression to minimize bandwith when accessing Full Series Records.
16
15
  EOF
@@ -29,6 +28,6 @@ Gem::Specification.new do |spec|
29
28
  spec.add_development_dependency "rspec", "~> 3.2"
30
29
  spec.add_development_dependency "coderay", "~> 1.1"
31
30
 
32
- spec.add_dependency "httparty", "~> 0.6"
33
31
  spec.add_dependency "rubyzip", "~> 1.1"
32
+ spec.add_dependency "httparty", "~> 0.6"
34
33
  end
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.13.pre
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fredrik Høisæther Rasch
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-02-27 00:00:00.000000000 Z
15
+ date: 2015-02-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -71,35 +71,34 @@ dependencies:
71
71
  - !ruby/object:Gem::Version
72
72
  version: '1.1'
73
73
  - !ruby/object:Gem::Dependency
74
- name: httparty
74
+ name: rubyzip
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '0.6'
79
+ version: '1.1'
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: '0.6'
86
+ version: '1.1'
87
87
  - !ruby/object:Gem::Dependency
88
- name: rubyzip
88
+ name: httparty
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '1.1'
93
+ version: '0.6'
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '1.1'
100
+ version: '0.6'
101
101
  description: |2
102
- NOTE: This Gem is currently in its pre-alpha development stadium and currently only supports minimal capability.
103
102
  The thetvdb_party gem accesses the TheTvDB programmers API as it is described on "http://thetvdb.com/wiki/index.php/Programmers_API".
104
103
  It uses compression to minimize bandwith when accessing Full Series Records.
105
104
  email:
@@ -117,6 +116,7 @@ files:
117
116
  - LICENSE.txt
118
117
  - README.md
119
118
  - Rakefile
119
+ - Sample Environment Configuration.yml
120
120
  - lib/thetvdb_party.rb
121
121
  - lib/thetvdb_party/actor.rb
122
122
  - lib/thetvdb_party/all.rb
@@ -124,14 +124,17 @@ files:
124
124
  - lib/thetvdb_party/baseepisoderecord.rb
125
125
  - lib/thetvdb_party/baseseriesrecord.rb
126
126
  - lib/thetvdb_party/client.rb
127
+ - lib/thetvdb_party/fullseriesrecord.rb
127
128
  - lib/thetvdb_party/searchseriesrecord.rb
128
129
  - lib/thetvdb_party/version.rb
129
130
  - spec/spec_helper.rb
130
131
  - spec/thetvdb_party/actor_spec.rb
132
+ - spec/thetvdb_party/all_spec.rb
131
133
  - spec/thetvdb_party/banner_spec.rb
132
134
  - spec/thetvdb_party/baseepisoderecord_spec.rb
133
135
  - spec/thetvdb_party/baseseriesrecord_spec.rb
134
136
  - spec/thetvdb_party/client_spec.rb
137
+ - spec/thetvdb_party/fullseriesrecord_spec.rb
135
138
  - spec/thetvdb_party/searchseriesrecord_spec.rb
136
139
  - spec/thetvdb_party_spec.rb
137
140
  - thetvdb_party.gemspec
@@ -155,9 +158,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
158
  version: '0'
156
159
  required_rubygems_version: !ruby/object:Gem::Requirement
157
160
  requirements:
158
- - - ">"
161
+ - - ">="
159
162
  - !ruby/object:Gem::Version
160
- version: 1.3.1
163
+ version: '0'
161
164
  requirements: []
162
165
  rubyforge_project:
163
166
  rubygems_version: 2.4.5
@@ -167,10 +170,12 @@ summary: Ruby Gem for accessing the TheTVDB programmers API
167
170
  test_files:
168
171
  - spec/spec_helper.rb
169
172
  - spec/thetvdb_party/actor_spec.rb
173
+ - spec/thetvdb_party/all_spec.rb
170
174
  - spec/thetvdb_party/banner_spec.rb
171
175
  - spec/thetvdb_party/baseepisoderecord_spec.rb
172
176
  - spec/thetvdb_party/baseseriesrecord_spec.rb
173
177
  - spec/thetvdb_party/client_spec.rb
178
+ - spec/thetvdb_party/fullseriesrecord_spec.rb
174
179
  - spec/thetvdb_party/searchseriesrecord_spec.rb
175
180
  - spec/thetvdb_party_spec.rb
176
181
  has_rdoc: