Class: Traktr::Show

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/traktr/show.rb,
lib/traktr/show/season.rb,
lib/traktr/show/episode.rb

Defined Under Namespace

Classes: Episode, Season

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Show

Returns a new instance of Show.



6
7
8
# File 'lib/traktr/show.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#comments(title, type = :all) ⇒ Object

show GET methods

Raises:

  • (ResponseError)


17
18
19
20
21
22
23
24
# File 'lib/traktr/show.rb', line 17

def comments(title, type = :all)
  response = self.class.get("/" + File.join("comments.json", @client.api_key, title, type.to_s))
  raise ResponseError.new(response) if response.code != 200

  response.parsed_response.collect do |comment|
    Mash.new(comment)
  end
end

#episodeObject



10
11
12
# File 'lib/traktr/show.rb', line 10

def episode
  @episode ||= Traktr::Show::Episode.new(@client)
end

#library(show) ⇒ Object

show POST methods

Raises:

  • (ResponseError)


88
89
90
91
92
93
94
95
96
97
# File 'lib/traktr/show.rb', line 88

def library(show)
  data = {
      username: @client.username, password: @client.password,
      title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
  }
  response = self.class.post("/" + File.join("library", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

Raises:

  • (ResponseError)


26
27
28
29
30
31
32
33
# File 'lib/traktr/show.rb', line 26

def related(title, hidewatched = false)
  response = self.class.get("/" + File.join("related.json", @client.api_key, title, hidewatched.to_s))
  raise ResponseError.new(response) if response.code != 200

  response.parsed_response.collect do |summary|
    Mash.new(summary)
  end
end

#season(title = nil, season = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/traktr/show.rb', line 35

def season(title = nil, season = nil)
  if title && season
    response = self.class.get("/" + File.join("season.json", @client.api_key, title, season.to_s))
    raise ResponseError.new(response) if response.code != 200

    response.parsed_response.collect do |episode|
      Mash.new(episode)
    end
  elsif !title && !season
    @season ||= Traktr::Show::Season.new(@client)
  else
    raise ArgumentError.new("wrong number of arguments")
  end
end

#seasons(title) ⇒ Object

Raises:

  • (ResponseError)


50
51
52
53
54
55
56
57
# File 'lib/traktr/show.rb', line 50

def seasons(title)
  response = self.class.get("/" + File.join("seasons.json", @client.api_key, title))
  raise ResponseError.new(response) if response.code != 200

  response.parsed_response.collect do |season|
    Mash.new(season)
  end
end

#seen(show) ⇒ Object

Raises:

  • (ResponseError)


134
135
136
137
138
139
140
141
142
143
# File 'lib/traktr/show.rb', line 134

def seen(show)
  data = {
      username: @client.username, password: @client.password,
      title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
  }
  response = self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#summaries(titles, extended = :min) ⇒ Object

Raises:

  • (ResponseError)


66
67
68
69
70
71
72
73
74
# File 'lib/traktr/show.rb', line 66

def summaries(titles, extended = :min)
  titles = [titles] if titles.class == String
  response = self.class.get("/" + File.join("summaries.json", @client.api_key, titles.join(","), extended.to_s))
  raise ResponseError.new(response) if response.code != 200

  response.parsed_response.collect do |summary|
    Mash.new(summary)
  end
end

#summary(title, extended = :min) ⇒ Object

Raises:

  • (ResponseError)


59
60
61
62
63
64
# File 'lib/traktr/show.rb', line 59

def summary(title, extended = :min)
  response = self.class.get("/" + File.join("summary.json", @client.api_key, title, extended.to_s))
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#unlibrary(show) ⇒ Object

Raises:

  • (ResponseError)


99
100
101
102
103
104
105
106
107
108
# File 'lib/traktr/show.rb', line 99

def unlibrary(show)
  data = {
      username: @client.username, password: @client.password,
      title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
  }
  response = self.class.post("/" + File.join("unlibrary", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#unwatchlist(shows) ⇒ Object

Raises:

  • (ResponseError)


122
123
124
125
126
127
128
129
130
131
132
# File 'lib/traktr/show.rb', line 122

def unwatchlist(shows)
  shows = [ shows ] if shows.class != Array
  data = {
      username: @client.username, password: @client.password,
      shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
  }
  response = self.class.post("/" + File.join("unwatchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#watchingnow(title) ⇒ Object

Raises:

  • (ResponseError)


76
77
78
79
80
81
82
83
# File 'lib/traktr/show.rb', line 76

def watchingnow(title)
  response = self.class.get("/" + File.join("watchingnow.json", @client.api_key, title))
  raise ResponseError.new(response) if response.code != 200

  response.parsed_response.collect do |user|
    Mash.new(user)
  end
end

#watchlist(shows) ⇒ Object

Raises:

  • (ResponseError)


110
111
112
113
114
115
116
117
118
119
120
# File 'lib/traktr/show.rb', line 110

def watchlist(shows)
  shows = [ shows ] if shows.class != Array
  data = {
      username: @client.username, password: @client.password,
      shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
  }
  response = self.class.post("/" + File.join("watchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
  raise ResponseError.new(response) if response.code != 200

  Mash.new(JSON.parse(response.parsed_response))
end