Class: Traktr::Show
- Inherits:
-
Object
- Object
- Traktr::Show
- Includes:
- HTTParty
- Defined in:
- lib/traktr/show.rb,
lib/traktr/show/season.rb,
lib/traktr/show/episode.rb
Defined Under Namespace
Instance Method Summary collapse
-
#comments(title, type = :all) ⇒ Object
show GET methods.
- #episode ⇒ Object
-
#initialize(client) ⇒ Show
constructor
A new instance of Show.
-
#library(show) ⇒ Object
show POST methods.
- #related(title, hidewatched = false) ⇒ Object
- #season(title = nil, season = nil) ⇒ Object
- #seasons(title) ⇒ Object
- #seen(show) ⇒ Object
- #summaries(titles, extended = :min) ⇒ Object
- #summary(title, extended = :min) ⇒ Object
- #unlibrary(show) ⇒ Object
- #unwatchlist(shows) ⇒ Object
- #watchingnow(title) ⇒ Object
- #watchlist(shows) ⇒ Object
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
22 23 24 25 26 27 28 29 |
# File 'lib/traktr/show.rb', line 22 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 |
#episode ⇒ Object
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
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/traktr/show.rb', line 93 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 |
#related(title, hidewatched = false) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/traktr/show.rb', line 31 def (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
14 15 16 17 |
# File 'lib/traktr/show.rb', line 14 def season end |
#seasons(title) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/traktr/show.rb', line 55 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
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/traktr/show.rb', line 139 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
71 72 73 74 75 76 77 78 79 |
# File 'lib/traktr/show.rb', line 71 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
64 65 66 67 68 69 |
# File 'lib/traktr/show.rb', line 64 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
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/traktr/show.rb', line 104 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
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/traktr/show.rb', line 127 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
81 82 83 84 85 86 87 88 |
# File 'lib/traktr/show.rb', line 81 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
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/traktr/show.rb', line 115 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 |