Class: Tvdbjson::Series

Inherits:
Object
  • Object
show all
Extended by:
Requestable
Includes:
Hashable
Defined in:
lib/tvdbjson/series.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Requestable

build_uri, send_authenticated_request

Methods included from Hashable

#to_hash

Constructor Details

#initialize(options = {}) ⇒ Series

Returns a new instance of Series.



7
8
9
10
11
12
13
14
15
16
# File 'lib/tvdbjson/series.rb', line 7

def initialize(options = {})
  @id          = options[:id]
  @name        = options[:name]
  @overview    = options[:overview]
  @network     = options[:network]
  @banner_url  = options[:banner_url]
  @first_aired = options[:first_aired]
  @status      = options[:status]
  @aliases     = options[:aliases]
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def aliases
  @aliases
end

Returns the value of attribute banner_url.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def banner_url
  @banner_url
end

#first_airedObject

Returns the value of attribute first_aired.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def first_aired
  @first_aired
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def name
  @name
end

#networkObject

Returns the value of attribute network.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def network
  @network
end

#overviewObject

Returns the value of attribute overview.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def overview
  @overview
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/tvdbjson/series.rb', line 5

def status
  @status
end

Class Method Details

.from_response(response) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tvdbjson/series.rb', line 57

def self.from_response(response)
  results_array = []

  begin
    response.parsed_response["data"].each do |record|
      hash               = {}
      hash[:id]          = record["id"]
      hash[:name]        = record["seriesName"]
      hash[:overview]    = record["overview"]
      hash[:network]     = record["network"]
      hash[:banner_url]  = "https://thetvdb.com/banners/" + record["banner"]
      hash[:first_aired] = record["firstAired"]
      hash[:status]      = record["status"]
      hash[:aliases]     = record["aliases"]

      result             = Series.new(hash)
      results_array      << result
    end
  rescue NoMethodError
    # Means an empty result set was found, don't do anything special
    # here as this method will return an empty array.
  end
  results_array
end

.search_by_imdb(str, authentication) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tvdbjson/series.rb', line 31

def self.search_by_imdb(str, authentication)
  raise Tvdbjson::RequiredSearchParamMissingError if !str
  raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication)

  hash = {
    :method       => "GET",
    :uri          => "/search/series",
    :after_action => "Tvdbjson::Series.from_response(response)",
    :params       => { "imdbId" => str }
  }
  send_authenticated_request(hash, authentication)
end

.search_by_name(str, authentication) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tvdbjson/series.rb', line 18

def self.search_by_name(str, authentication)
  raise Tvdbjson::RequiredSearchParamMissingError if !str
  raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication)

  hash = {
    :method       => "GET",
    :uri          => "/search/series",
    :after_action => "Tvdbjson::Series.from_response(response)",
    :params       => { "name" => str }
  }
  send_authenticated_request(hash, authentication)
end

.search_by_zap2it_id(str, authentication) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tvdbjson/series.rb', line 44

def self.search_by_zap2it_id(str, authentication)
  raise Tvdbjson::RequiredSearchParamMissingError if !str
  raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication)

  hash = {
    :method       => "GET",
    :uri          => "/search/series",
    :after_action => "Tvdbjson::Series.from_response(response)",
    :params       => { "zap2itId" => str }
  }
  send_authenticated_request(hash, authentication)
end