the_tvdb 0.1.2 → 0.1.3

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.
data/lib/the_tvdb/show.rb CHANGED
@@ -12,10 +12,15 @@ module TheTvdb
12
12
  end
13
13
 
14
14
  def self.find(remote_id)
15
- info = TheTvdb.gateway.get_series_package(remote_id)
16
- show = self.new(info['Series'])
17
- show.episodes = info['Episode'].blank? ? [] : [ info['Episode'] ].flatten.map {|e| TheTvdb::Episode.new(e) }
18
- show
15
+ begin
16
+ info = TheTvdb.gateway.get_series_package(remote_id)
17
+ show = self.new(info['Series'])
18
+ show.episodes = info['Episode'].blank? ? [] : [ info['Episode'] ].flatten.map {|e| TheTvdb::Episode.new(e) }
19
+ show
20
+ rescue
21
+ puts 'There was an issue with the series you tried to fetch'
22
+ nil
23
+ end
19
24
  end
20
25
 
21
26
  def initialize(info, partial=false)
@@ -1,3 +1,3 @@
1
1
  module TheTvdb
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/the_tvdb.rb CHANGED
@@ -22,11 +22,19 @@ module TheTvdb
22
22
  # update time and the updated shows are returned
23
23
  #
24
24
  # @param [Integer] timestamp the last update timestamp (if not provided the last_updated attribute of Gateway is used instead)
25
- # @return [Hash] the new last_updated time and the Shows that have been updated
26
- def self.update(timestamp = nil)
25
+ # @param [Boolean] full_data if set to true will return full Show and Episode objects, not just the ids (defaults to false)
26
+ # @return [Hash] the new last_updated time and the Shows that have been updated or their ids
27
+ def self.update(timestamp=nil, full_data=false)
27
28
  update_hash = gateway.update(timestamp)
28
29
  result = { time: update_hash['Time'].to_i }
29
- result[:shows] = update_hash['Series'].map {|show_remote_id| Show.find(show_remote_id) } if update_hash['Series']
30
+ result[:shows] = []
31
+ if update_hash['Series']
32
+ if full_data
33
+ result[:shows] = update_hash['Series'].map {|show_remote_id| Show.find(show_remote_id) }
34
+ else
35
+ result[:shows] = update_hash['Series']
36
+ end
37
+ end
30
38
  gateway.last_updated = result[:time]
31
39
  result
32
40
  end
@@ -21,12 +21,19 @@ describe TheTvdb::Gateway do
21
21
  end
22
22
 
23
23
  describe "#update" do
24
- it "should return a list of updated series and episodes" do
25
- result = TheTvdb.update(1356079970)
24
+ it "should return an array of updated series and episodes" do
25
+ result = TheTvdb.update(1356079970, true)
26
26
  result[:time].should == 1356080761
27
27
  result[:shows].should have(3).items
28
28
  gateway.last_updated.should == 1356080761
29
29
  end
30
+
31
+ it "should return the ids of updated series" do
32
+ result = TheTvdb.update(1356079970)
33
+ result[:shows].should have(3).items
34
+ result[:shows].first.should == '80367'
35
+ gateway.last_updated.should == 1356080761
36
+ end
30
37
  end
31
38
 
32
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_tvdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-30 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri