traktr 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2be4dc41f9bdab35ee6efd4c32496d80d9c72ac
4
- data.tar.gz: 4af66c432614436188985df65bc85475db044fe2
3
+ metadata.gz: ff5530ddf41945252c0fd25a646fa99d0447862b
4
+ data.tar.gz: 192df29f7c2dfd344b5e2d3928344a372231dc88
5
5
  SHA512:
6
- metadata.gz: 370a936cb1b8cfc021fd173dd6eff26bca9d6b7fb5b3e8f66d6311fd02cb8c40ef9a4311892dc6b89ff30706b7ca6a47ae207f0719efb1f2cb6f00f64afae064
7
- data.tar.gz: 740e0274f5783d6ada811e4acfc4241b0dfd0e8f76579afccde14caa5cbf244bde4bd8c72d0125c503d8cca316d64d992d02ce6f0622ac3b8e666cd5ed920b93
6
+ metadata.gz: 5cc91fad8010a43a44f6e8656d69dc9147d6721745e262b2d7da4a83cda02d6ed1ee2ec40fba6d2e0e2ef713a9a185912646b4eecc078419ef45067eb8fcbf62
7
+ data.tar.gz: d48a37bedb5f961f732081c1e057bdf8757f1ad14878dab9cedb9441d9050bdcfe94914acbbcead48d2b6c54f86f13474d59c7134371e128aaade0aac7406253
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Traktr
2
2
 
3
- TODO: Write a gem description
3
+ Traktr is a ruby client API for the trakt.tv RESTful web service. Trakt allows users to:
4
+
5
+ 1. Automatically track what you're watching
6
+ 2. Track your progress and see what's on tonight
7
+ 3. Catalog your entire media collection
8
+ 4. Submit ratings and reviews, follow other members, and make friends
9
+ 5. Share to your social networks in real time
10
+ 6. Discover new shows and movies
11
+ 7. Organize lists of your favorite shows and movies to make sure you don't forget them
12
+
13
+ This client API supports all non-DEV REST methods. (If you need the DEV methods, submit a pull request!)
14
+
15
+ The full API documentation can be found at http://trakt.tv/api-docs
4
16
 
5
17
  ## Installation
6
18
 
@@ -18,7 +30,29 @@ Or install it yourself as:
18
30
 
19
31
  ## Usage
20
32
 
21
- TODO: Write usage instructions here
33
+ To interface with the Trakt API, you must create a client instance
34
+
35
+ ```ruby
36
+ API_KEY = "abcdefghijklmnopqrstuvwxyz"
37
+ USERNAME = "john_doe"
38
+ PASSWORD = "p@ssw0rd"
39
+ SHA1_PASSWORD = "57b2ad99044d337197c0c39fd3823568ff81e48a"
40
+
41
+ # for non-authenticated methods, you can create an instance without supplying
42
+ # username and password
43
+ trakt = Traktr::Client.new(API_KEY)
44
+
45
+ # if you need to use an authenticated method, you can provide your plaintext
46
+ # password
47
+ trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
48
+
49
+ # or the SHA1 hash of your password
50
+ trakt = Traktr::Client.new(API_KEY, USERNAME, SHA1_PASSWORD, true)
51
+ ```
52
+
53
+ From there, just string together method calls that match the Trakt API endpoints!
54
+ It's that easy (aka, I need to add more documentation here). See the RSpec tests
55
+ for examples of all of the supported methods.
22
56
 
23
57
  ## Contributing
24
58
 
@@ -1,20 +1,11 @@
1
1
  require 'httparty'
2
- require 'mash'
3
2
  require 'json'
4
- require 'uri'
3
+ require 'mash'
5
4
 
6
5
  module Traktr
7
6
  include HTTParty
8
7
  base_uri "http://api.trakt.tv"
9
8
  end
10
9
 
11
- require 'traktr/authentication'
12
- require 'traktr/version'
13
10
 
14
- require 'traktr/account'
15
- require 'traktr/movie'
16
- require 'traktr/movies'
17
- require 'traktr/search'
18
- require 'traktr/show'
19
- require 'traktr/shows'
20
- require 'traktr/user'
11
+ require 'traktr/client'
@@ -1,23 +1,26 @@
1
1
  module Traktr
2
- module Account
2
+ class Account
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, "account")
5
5
 
6
- def self.settings
7
- data = { username: Traktr.username, password: Traktr.password }
8
- response = self.post("/" + File.join("settings", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def settings
11
+ data = { username: @client.username, password: @client.password }
12
+ response = self.class.post("/" + File.join("settings", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
9
13
  raise ResponseError.new(response) if response.code != 200
10
14
 
11
15
  Mash.new(response.parsed_response)
12
16
  end
13
17
 
14
- def self.test
15
- data = { username: Traktr.username, password: Traktr.password }
16
- response = self.post("/" + File.join("test", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
18
+ def test
19
+ data = { username: @client.username, password: @client.password }
20
+ response = self.class.post("/" + File.join("test", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
17
21
  raise ResponseError.new(response) if response.code != 200
18
22
 
19
23
  Mash.new(response.parsed_response)
20
24
  end
21
-
22
25
  end
23
26
  end
@@ -0,0 +1,57 @@
1
+ require 'digest/sha1'
2
+
3
+ require 'traktr/account'
4
+ require 'traktr/movie'
5
+ require 'traktr/movies'
6
+ require 'traktr/search'
7
+ require 'traktr/show'
8
+ require 'traktr/show/episode'
9
+ require 'traktr/show/season'
10
+ require 'traktr/shows'
11
+ require 'traktr/user'
12
+ require 'traktr/version'
13
+
14
+
15
+ module Traktr
16
+ class Client
17
+ attr_reader :api_key, :username, :password
18
+
19
+ def initialize(api_key, username = nil, password = nil, sha1 = false)
20
+ @api_key = api_key || ""
21
+ @username = username || ""
22
+ @password = password ? (sha1 ? password : Digest::SHA1.hexdigest(password)) : ""
23
+ end
24
+
25
+ def account
26
+ @account ||= Traktr::Account.new(self)
27
+ end
28
+
29
+ def movie
30
+ @movie ||= Traktr::Movie.new(self)
31
+ end
32
+
33
+ def movies
34
+ @movies ||= Traktr::Movies.new(self)
35
+ end
36
+
37
+ def search
38
+ @search ||= Traktr::Search.new(self)
39
+ end
40
+
41
+ def show
42
+ @show ||= Traktr::Show.new(self)
43
+ end
44
+
45
+ def shows
46
+ @shows ||= Traktr::Shows.new(self)
47
+ end
48
+
49
+ def user
50
+ @user ||= Traktr::User.new(self)
51
+ end
52
+
53
+ def version
54
+ @version ||= Traktr::Version.new(self)
55
+ end
56
+ end
57
+ end
@@ -1,13 +1,17 @@
1
1
  module Traktr
2
- module Movie
2
+ class Movie
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, 'movie')
5
5
 
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
6
10
  ##
7
11
  ## movie GET methods
8
12
  ##
9
- def self.comments(title, type = :all)
10
- response = self.get('/' + File.join('comments.json', Traktr.api_key, title, type.to_s))
13
+ def comments(title, type = :all)
14
+ response = self.class.get('/' + File.join('comments.json', @client.api_key, title, type.to_s))
11
15
  raise ResponseError.new(response) if response.code != 200
12
16
 
13
17
  response.parsed_response.collect do |comment|
@@ -15,8 +19,8 @@ module Traktr
15
19
  end
16
20
  end
17
21
 
18
- def self.related(title, hidewatched = false)
19
- response = self.get('/' + File.join('related.json', Traktr.api_key, title, hidewatched.to_s))
22
+ def related(title, hidewatched = false)
23
+ response = self.class.get('/' + File.join('related.json', @client.api_key, title, hidewatched.to_s))
20
24
  raise ResponseError.new(response) if response.code != 200
21
25
 
22
26
  response.parsed_response.collect do |summary|
@@ -24,16 +28,16 @@ module Traktr
24
28
  end
25
29
  end
26
30
 
27
- def self.summary(title, extended = :min)
28
- response = self.get('/' + File.join('summary.json', Traktr.api_key, title.to_s, extended.to_s))
31
+ def summary(title, extended = :min)
32
+ response = self.class.get('/' + File.join('summary.json', @client.api_key, title.to_s, extended.to_s))
29
33
  raise ResponseError.new(response) if response.code != 200
30
34
 
31
35
  Mash.new(response.parsed_response)
32
36
  end
33
37
 
34
- def self.summaries(titles, extended = :min)
38
+ def summaries(titles, extended = :min)
35
39
  titles = [titles] if titles.class == String
36
- response = self.get('/' + File.join('summaries.json', Traktr.api_key, titles.join(','), extended.to_s))
40
+ response = self.class.get('/' + File.join('summaries.json', @client.api_key, titles.join(','), extended.to_s))
37
41
  raise ResponseError.new(response) if response.code != 200
38
42
 
39
43
  response.parsed_response.collect do |summary|
@@ -41,8 +45,8 @@ module Traktr
41
45
  end
42
46
  end
43
47
 
44
- def self.watchingnow(title)
45
- response = self.get('/' + File.join('watchingnow.json', Traktr.api_key, title))
48
+ def watchingnow(title)
49
+ response = self.class.get('/' + File.join('watchingnow.json', @client.api_key, title))
46
50
  raise ResponseError.new(response) if response.code != 200
47
51
 
48
52
  response.parsed_response.collect do |user|
@@ -53,73 +57,73 @@ module Traktr
53
57
  ##
54
58
  ## movie POST methods
55
59
  ##
56
- def self.library(movies)
60
+ def library(movies)
57
61
  movies = [ movies ] if movies.class != Array
58
62
  data = {
59
- username: Traktr.username, password: Traktr.password,
63
+ username: @client.username, password: @client.password,
60
64
  movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
61
65
  }
62
- response = self.post('/' + File.join('library', Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
66
+ response = self.class.post('/' + File.join('library', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
63
67
  raise ResponseError.new(response) if response.code != 200
64
68
 
65
69
  Mash.new(JSON.parse(response.parsed_response))
66
70
  end
67
71
 
68
- def self.unlibrary(movies)
72
+ def unlibrary(movies)
69
73
  movies = [ movies ] if movies.class != Array
70
74
  data = {
71
- username: Traktr.username, password: Traktr.password,
75
+ username: @client.username, password: @client.password,
72
76
  movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
73
77
  }
74
- response = self.post('/' + File.join('unlibrary', Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
78
+ response = self.class.post('/' + File.join('unlibrary', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
75
79
  raise ResponseError.new(response) if response.code != 200
76
80
 
77
81
  Mash.new(response.parsed_response)
78
82
  end
79
83
 
80
- def self.watchlist(movies)
84
+ def watchlist(movies)
81
85
  movies = [ movies ] if movies.class != Array
82
86
  data = {
83
- username: Traktr.username, password: Traktr.password,
87
+ username: @client.username, password: @client.password,
84
88
  movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
85
89
  }
86
- response = self.post('/' + File.join('watchlist', Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
90
+ response = self.class.post('/' + File.join('watchlist', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
87
91
  raise ResponseError.new(response) if response.code != 200
88
92
 
89
93
  Mash.new(JSON.parse(response.parsed_response))
90
94
  end
91
95
 
92
- def self.unwatchlist(movies)
96
+ def unwatchlist(movies)
93
97
  movies = [ movies ] if movies.class != Array
94
98
  data = {
95
- username: Traktr.username, password: Traktr.password,
99
+ username: @client.username, password: @client.password,
96
100
  movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
97
101
  }
98
- response = self.post('/' + File.join('unwatchlist', Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
102
+ response = self.class.post('/' + File.join('unwatchlist', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
99
103
  raise ResponseError.new(response) if response.code != 200
100
104
 
101
105
  Mash.new(response.parsed_response)
102
106
  end
103
107
 
104
- def self.seen(movies)
108
+ def seen(movies)
105
109
  movies = [ movies ] if movies.class != Array
106
110
  data = {
107
- username: Traktr.username, password: Traktr.password,
111
+ username: @client.username, password: @client.password,
108
112
  movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
109
113
  }
110
- response = self.post('/' + File.join('seen', Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
114
+ response = self.class.post('/' + File.join('seen', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
111
115
  raise ResponseError.new(response) if response.code != 200
112
116
 
113
117
  Mash.new(JSON.parse(response.parsed_response))
114
118
  end
115
119
 
116
- def self.unseen(movies)
120
+ def unseen(movies)
117
121
  movies = [ movies ] if movies.class != Array
118
122
  data = {
119
- username: Traktr.username, password: Traktr.password,
123
+ username: @client.username, password: @client.password,
120
124
  movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
121
125
  }
122
- response = self.post('/' + File.join('unseen', Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
126
+ response = self.class.post('/' + File.join('unseen', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
123
127
  raise ResponseError.new(response) if response.code != 200
124
128
 
125
129
  Mash.new(response.parsed_response)
@@ -1,13 +1,17 @@
1
1
  module Traktr
2
- module Movies
2
+ class Movies
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, 'movies')
5
5
 
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
6
10
  ##
7
11
  ## movies GET methods
8
12
  ##
9
- def self.trending
10
- response = self.get('/' + File.join('trending.json', Traktr.api_key))
13
+ def trending
14
+ response = self.class.get('/' + File.join('trending.json', @client.api_key))
11
15
  raise ResponseError.new(response) if response.code != 200
12
16
 
13
17
  response.parsed_response.collect do |movie|
@@ -15,8 +19,8 @@ module Traktr
15
19
  end
16
20
  end
17
21
 
18
- def self.updated(timestamp)
19
- response = self.get('/' + File.join('updated.json', Traktr.api_key, timestamp.to_i.to_s))
22
+ def updated(timestamp)
23
+ response = self.class.get('/' + File.join('updated.json', @client.api_key, timestamp.to_i.to_s))
20
24
  raise ResponseError.new(response) if response.code != 200
21
25
 
22
26
  Mash.new(response.parsed_response)
@@ -1,13 +1,17 @@
1
1
  module Traktr
2
- module Search
2
+ class Search
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, 'search')
5
5
 
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
6
10
  ##
7
11
  ## search GET methods
8
12
  ##
9
- def self.episodes(query)
10
- response = self.get('/' + File.join('episodes.json', Traktr.api_key, URI::encode(query)))
13
+ def episodes(query)
14
+ response = self.class.get('/' + File.join('episodes.json', @client.api_key, URI::encode(query)))
11
15
  raise ResponseError.new(response) if response.code != 200
12
16
 
13
17
  response.parsed_response.collect do |result|
@@ -15,8 +19,8 @@ module Traktr
15
19
  end
16
20
  end
17
21
 
18
- def self.movies(query)
19
- response = self.get('/' + File.join('movies.json', Traktr.api_key, URI::encode(query)))
22
+ def movies(query)
23
+ response = self.class.get('/' + File.join('movies.json', @client.api_key, URI::encode(query)))
20
24
  raise ResponseError.new(response) if response.code != 200
21
25
 
22
26
  response.parsed_response.collect do |result|
@@ -24,8 +28,8 @@ module Traktr
24
28
  end
25
29
  end
26
30
 
27
- def self.people(query)
28
- response = self.get('/' + File.join('people.json', Traktr.api_key, URI::encode(query)))
31
+ def people(query)
32
+ response = self.class.get('/' + File.join('people.json', @client.api_key, URI::encode(query)))
29
33
  raise ResponseError.new(response) if response.code != 200
30
34
 
31
35
  response.parsed_response.collect do |result|
@@ -33,8 +37,8 @@ module Traktr
33
37
  end
34
38
  end
35
39
 
36
- def self.shows(query, limit = 30, seasons = nil)
37
- response = self.get('/' + File.join('shows.json', Traktr.api_key, URI::encode(query), limit.to_s, seasons.to_s))
40
+ def shows(query, limit = 30, seasons = nil)
41
+ response = self.class.get('/' + File.join('shows.json', @client.api_key, URI::encode(query), limit.to_s, seasons.to_s))
38
42
  raise ResponseError.new(response) if response.code != 200
39
43
 
40
44
  response.parsed_response.collect do |result|
@@ -42,8 +46,8 @@ module Traktr
42
46
  end
43
47
  end
44
48
 
45
- def self.users(query)
46
- response = self.get('/' + File.join('users.json', Traktr.api_key, URI::encode(query)))
49
+ def users(query)
50
+ response = self.class.get('/' + File.join('users.json', @client.api_key, URI::encode(query)))
47
51
  raise ResponseError.new(response) if response.code != 200
48
52
 
49
53
  response.parsed_response.collect do |result|
@@ -1,13 +1,26 @@
1
1
  module Traktr
2
- module Show
2
+ class Show
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, "show")
5
5
 
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def episode
11
+ @episode ||= Traktr::Show::Episode.new(@client)
12
+ end
13
+
14
+ def season
15
+
16
+
17
+ end
18
+
6
19
  ##
7
20
  ## show GET methods
8
21
  ##
9
- def self.comments(title, type = :all)
10
- response = self.get("/" + File.join("comments.json", Traktr.api_key, title, type.to_s))
22
+ def comments(title, type = :all)
23
+ response = self.class.get("/" + File.join("comments.json", @client.api_key, title, type.to_s))
11
24
  raise ResponseError.new(response) if response.code != 200
12
25
 
13
26
  response.parsed_response.collect do |comment|
@@ -15,8 +28,8 @@ module Traktr
15
28
  end
16
29
  end
17
30
 
18
- def self.related(title, hidewatched = false)
19
- response = self.get("/" + File.join("related.json", Traktr.api_key, title, hidewatched.to_s))
31
+ def related(title, hidewatched = false)
32
+ response = self.class.get("/" + File.join("related.json", @client.api_key, title, hidewatched.to_s))
20
33
  raise ResponseError.new(response) if response.code != 200
21
34
 
22
35
  response.parsed_response.collect do |summary|
@@ -24,17 +37,23 @@ module Traktr
24
37
  end
25
38
  end
26
39
 
27
- def self.season(title, season)
28
- response = self.get("/" + File.join("season.json", Traktr.api_key, title, season.to_s))
29
- raise ResponseError.new(response) if response.code != 200
30
-
31
- response.parsed_response.collect do |episode|
32
- Mash.new(episode)
40
+ def season(title = nil, season = nil)
41
+ if title && season
42
+ response = self.class.get("/" + File.join("season.json", @client.api_key, title, season.to_s))
43
+ raise ResponseError.new(response) if response.code != 200
44
+
45
+ response.parsed_response.collect do |episode|
46
+ Mash.new(episode)
47
+ end
48
+ elsif !title && !season
49
+ @season ||= Traktr::Show::Season.new(@client)
50
+ else
51
+ raise ArgumentError.new("wrong number of arguments")
33
52
  end
34
53
  end
35
54
 
36
- def self.seasons(title)
37
- response = self.get("/" + File.join("seasons.json", Traktr.api_key, title))
55
+ def seasons(title)
56
+ response = self.class.get("/" + File.join("seasons.json", @client.api_key, title))
38
57
  raise ResponseError.new(response) if response.code != 200
39
58
 
40
59
  response.parsed_response.collect do |season|
@@ -42,16 +61,16 @@ module Traktr
42
61
  end
43
62
  end
44
63
 
45
- def self.summary(title, extended = :min)
46
- response = self.get("/" + File.join("summary.json", Traktr.api_key, title, extended.to_s))
64
+ def summary(title, extended = :min)
65
+ response = self.class.get("/" + File.join("summary.json", @client.api_key, title, extended.to_s))
47
66
  raise ResponseError.new(response) if response.code != 200
48
67
 
49
68
  Mash.new(response.parsed_response)
50
69
  end
51
70
 
52
- def self.summaries(titles, extended = :min)
71
+ def summaries(titles, extended = :min)
53
72
  titles = [titles] if titles.class == String
54
- response = self.get("/" + File.join("summaries.json", Traktr.api_key, titles.join(","), extended.to_s))
73
+ response = self.class.get("/" + File.join("summaries.json", @client.api_key, titles.join(","), extended.to_s))
55
74
  raise ResponseError.new(response) if response.code != 200
56
75
 
57
76
  response.parsed_response.collect do |summary|
@@ -59,8 +78,8 @@ module Traktr
59
78
  end
60
79
  end
61
80
 
62
- def self.watchingnow(title)
63
- response = self.get("/" + File.join("watchingnow.json", Traktr.api_key, title))
81
+ def watchingnow(title)
82
+ response = self.class.get("/" + File.join("watchingnow.json", @client.api_key, title))
64
83
  raise ResponseError.new(response) if response.code != 200
65
84
 
66
85
  response.parsed_response.collect do |user|
@@ -71,64 +90,61 @@ module Traktr
71
90
  ##
72
91
  ## show POST methods
73
92
  ##
74
- def self.library(show)
93
+ def library(show)
75
94
  data = {
76
- username: Traktr.username, password: Traktr.password,
95
+ username: @client.username, password: @client.password,
77
96
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
78
97
  }
79
- response = self.post("/" + File.join("library", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
98
+ response = self.class.post("/" + File.join("library", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
80
99
  raise ResponseError.new(response) if response.code != 200
81
100
 
82
101
  Mash.new(response.parsed_response)
83
102
  end
84
103
 
85
- def self.unlibrary(show)
104
+ def unlibrary(show)
86
105
  data = {
87
- username: Traktr.username, password: Traktr.password,
106
+ username: @client.username, password: @client.password,
88
107
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
89
108
  }
90
- response = self.post("/" + File.join("unlibrary", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
109
+ response = self.class.post("/" + File.join("unlibrary", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
91
110
  raise ResponseError.new(response) if response.code != 200
92
111
 
93
112
  Mash.new(response.parsed_response)
94
113
  end
95
114
 
96
- def self.watchlist(shows)
115
+ def watchlist(shows)
97
116
  shows = [ shows ] if shows.class != Array
98
117
  data = {
99
- username: Traktr.username, password: Traktr.password,
118
+ username: @client.username, password: @client.password,
100
119
  shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
101
120
  }
102
- response = self.post("/" + File.join("watchlist", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
121
+ response = self.class.post("/" + File.join("watchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
103
122
  raise ResponseError.new(response) if response.code != 200
104
123
 
105
124
  Mash.new(JSON.parse(response.parsed_response))
106
125
  end
107
126
 
108
- def self.unwatchlist(shows)
127
+ def unwatchlist(shows)
109
128
  shows = [ shows ] if shows.class != Array
110
129
  data = {
111
- username: Traktr.username, password: Traktr.password,
130
+ username: @client.username, password: @client.password,
112
131
  shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
113
132
  }
114
- response = self.post("/" + File.join("unwatchlist", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
133
+ response = self.class.post("/" + File.join("unwatchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
115
134
  raise ResponseError.new(response) if response.code != 200
116
135
 
117
136
  Mash.new(response.parsed_response)
118
137
  end
119
138
 
120
- def self.seen(show)
139
+ def seen(show)
121
140
  data = {
122
- username: Traktr.username, password: Traktr.password,
141
+ username: @client.username, password: @client.password,
123
142
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
124
143
  }
125
- response = self.post("/" + File.join("seen", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
144
+ response = self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
126
145
  raise ResponseError.new(response) if response.code != 200
127
146
 
128
147
  Mash.new(response.parsed_response)
129
148
  end
130
149
  end
131
150
  end
132
-
133
- require 'traktr/show/episode'
134
- require 'traktr/show/season'