Module: Traktr::Show

Includes:
HTTParty
Defined in:
lib/traktr/show.rb,
lib/traktr/show/season.rb,
lib/traktr/show/episode.rb

Defined Under Namespace

Modules: Episode, Season

Class Method Summary collapse

Class Method Details

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

show GET methods

Raises:

  • (ResponseError)


9
10
11
12
13
14
15
16
# File 'lib/traktr/show.rb', line 9

def self.comments(title, type = :all)
  response = self.get("/" + File.join("comments.json", Traktr.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

.library(show) ⇒ Object

show POST methods

Raises:

  • (ResponseError)


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

def self.library(show)
  data = {
      username: Traktr.username, password: Traktr.password,
      title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
  }
  response = self.post("/" + File.join("library", Traktr.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)


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

def self.related(title, hidewatched = false)
  response = self.get("/" + File.join("related.json", Traktr.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, season) ⇒ Object

Raises:

  • (ResponseError)


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

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

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

.seasons(title) ⇒ Object

Raises:

  • (ResponseError)


36
37
38
39
40
41
42
43
# File 'lib/traktr/show.rb', line 36

def self.seasons(title)
  response = self.get("/" + File.join("seasons.json", Traktr.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)


120
121
122
123
124
125
126
127
128
129
# File 'lib/traktr/show.rb', line 120

def self.seen(show)
  data = {
      username: Traktr.username, password: Traktr.password,
      title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
  }
  response = self.post("/" + File.join("seen", Traktr.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)


52
53
54
55
56
57
58
59
60
# File 'lib/traktr/show.rb', line 52

def self.summaries(titles, extended = :min)
  titles = [titles] if titles.class == String
  response = self.get("/" + File.join("summaries.json", Traktr.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)


45
46
47
48
49
50
# File 'lib/traktr/show.rb', line 45

def self.summary(title, extended = :min)
  response = self.get("/" + File.join("summary.json", Traktr.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)


85
86
87
88
89
90
91
92
93
94
# File 'lib/traktr/show.rb', line 85

def self.unlibrary(show)
  data = {
      username: Traktr.username, password: Traktr.password,
      title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
  }
  response = self.post("/" + File.join("unlibrary", Traktr.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)


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

def self.unwatchlist(shows)
  shows = [ shows ] if shows.class != Array
  data = {
      username: Traktr.username, password: Traktr.password,
      shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
  }
  response = self.post("/" + File.join("unwatchlist", Traktr.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)


62
63
64
65
66
67
68
69
# File 'lib/traktr/show.rb', line 62

def self.watchingnow(title)
  response = self.get("/" + File.join("watchingnow.json", Traktr.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)


96
97
98
99
100
101
102
103
104
105
106
# File 'lib/traktr/show.rb', line 96

def self.watchlist(shows)
  shows = [ shows ] if shows.class != Array
  data = {
      username: Traktr.username, password: Traktr.password,
      shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
  }
  response = self.post("/" + File.join("watchlist", Traktr.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