tvdbr 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tvdbr (0.2.0)
4
+ tvdbr (0.2.1)
5
5
  hashie
6
6
  httparty (>= 0.8.0)
7
7
 
@@ -8,6 +8,8 @@ tvdb = Tvdbr::Client.new('5FEC454623154441')
8
8
  # Find episode by id
9
9
  episode = tvdb.find_episode_by_id(326177)
10
10
  puts episode.inspect
11
+ episode = tvdb.find_episode_by_id(174207)
12
+ puts episode.inspect
11
13
 
12
14
  # Find episode with airdate
13
15
  episode = tvdb.find_episode_by_airdate(80348, '2007-09-24')
@@ -2,6 +2,8 @@ require 'hashie' unless defined?(Hashie)
2
2
 
3
3
  module Tvdbr
4
4
  class DataSet < Hashie::Mash
5
+ class InvalidFormat < StandardError; end
6
+
5
7
  attr_reader :parent
6
8
 
7
9
  ## INSTANCE METHODS ##
@@ -11,6 +13,8 @@ module Tvdbr
11
13
  @parent = parent
12
14
  source_hash = normalize_keys(source_hash) if source_hash.is_a?(Hash)
13
15
  super(source_hash, default, &block)
16
+ rescue ArgumentError => e # #<ArgumentError: wrong number of arguments (0 for 1)>
17
+ raise InvalidFormat, "#{self.class.name} parse failed with source #{source_hash.inspect}"
14
18
  end
15
19
 
16
20
  # Outputs: <#Tvdb::Series actors="..." added=nil added_by=nil>
@@ -66,10 +70,18 @@ module Tvdbr
66
70
  end
67
71
  end
68
72
 
69
- # Normalizes a value for the formatted hash
70
- # Sometimes TVDB returns a hash with a "__content__" key which needs to be removed
73
+ # Normalizes a value for the formatted hash values
74
+ # TVDB hashes should not contain more hashes
75
+ # Sometimes TVDB returns a hash with content inside which needs to be extracted
71
76
  def normalize_value(val)
72
- val.respond_to?(:has_key?) && val.has_key?("__content__") ? val["__content__"] : val
77
+ if val.is_a?(Hash)
78
+ val = val["__content__"] if val.has_key?("__content__")
79
+ val = val.values.first if val.respond_to?(:values) && val.values.one?
80
+ val = val.join(" ") if val.respond_to?(:join)
81
+ val.to_s
82
+ else # any other value
83
+ val
84
+ end
73
85
  end
74
86
 
75
87
  def underscore(camel_cased_word)
@@ -1,3 +1,3 @@
1
1
  module Tvdbr
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tvdbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-12 00:00:00.000000000 Z
13
+ date: 2012-10-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hashie