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.
@@ -1,14 +1,18 @@
1
1
  module Traktr
2
- module Show
3
- module Episode
2
+ class Show
3
+ class Episode
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::Show.base_uri, "episode")
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
6
10
 
7
11
  ##
8
12
  ## show-episode GET methods
9
13
  ##
10
- def self.comments(title, season, episode)
11
- response = self.get("/" + File.join("comments.json", Traktr.api_key, title, season.to_s, episode.to_s))
14
+ def comments(title, season, episode)
15
+ response = self.class.get("/" + File.join("comments.json", @client.api_key, title, season.to_s, episode.to_s))
12
16
  raise ResponseError.new(response) if response.code != 200
13
17
 
14
18
  response.parsed_response.collect do |comment|
@@ -16,15 +20,15 @@ module Traktr
16
20
  end
17
21
  end
18
22
 
19
- def self.summary(title, season, episode)
20
- response = self.get("/" + File.join("summary.json", Traktr.api_key, title, season.to_s, episode.to_s))
23
+ def summary(title, season, episode)
24
+ response = self.class.get("/" + File.join("summary.json", @client.api_key, title, season.to_s, episode.to_s))
21
25
  raise ResponseError.new(response) if response.code != 200
22
26
 
23
27
  Mash.new(response.parsed_response)
24
28
  end
25
29
 
26
- def self.watchingnow(title, season, episode)
27
- response = self.get("/" + File.join("watchingnow.json", Traktr.api_key, title, season.to_s, episode.to_s))
30
+ def watchingnow(title, season, episode)
31
+ response = self.class.get("/" + File.join("watchingnow.json", @client.api_key, title, season.to_s, episode.to_s))
28
32
  raise ResponseError.new(response) if response.code != 200
29
33
 
30
34
  response.parsed_response.collect do |user|
@@ -36,73 +40,73 @@ module Traktr
36
40
  ##
37
41
  ## show-episode POST methods
38
42
  ##
39
- def self.library(show, episodes)
43
+ def library(show, episodes)
40
44
  data = {
41
- username: Traktr.username, password: Traktr.password,
45
+ username: @client.username, password: @client.password,
42
46
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
43
47
  episodes: episodes.collect{ |e| { season: e.season, episode: e.episode } }
44
48
  }
45
- response = self.post("/" + File.join("library", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
49
+ response = self.class.post("/" + File.join("library", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
46
50
  raise ResponseError.new(response) if response.code != 200
47
51
 
48
52
  Mash.new(response.parsed_response)
49
53
  end
50
54
 
51
- def self.unlibrary(show, episodes)
55
+ def unlibrary(show, episodes)
52
56
  data = {
53
- username: Traktr.username, password: Traktr.password,
57
+ username: @client.username, password: @client.password,
54
58
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
55
59
  episodes: episodes.collect{ |e| { season: e.season, episode: e.episode } }
56
60
  }
57
- response = self.post("/" + File.join("unlibrary", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
61
+ response = self.class.post("/" + File.join("unlibrary", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
58
62
  raise ResponseError.new(response) if response.code != 200
59
63
 
60
64
  Mash.new(response.parsed_response)
61
65
  end
62
66
 
63
- def self.seen(show, episodes)
67
+ def seen(show, episodes)
64
68
  data = {
65
- username: Traktr.username, password: Traktr.password,
69
+ username: @client.username, password: @client.password,
66
70
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
67
71
  episodes: episodes.collect{ |e| { season: e.season, episode: e.episode } }
68
72
  }
69
- response = self.post("/" + File.join("seen", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
73
+ response = self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
70
74
  raise ResponseError.new(response) if response.code != 200
71
75
 
72
76
  Mash.new(response.parsed_response)
73
77
  end
74
78
 
75
- def self.unseen(show, episodes)
79
+ def unseen(show, episodes)
76
80
  data = {
77
- username: Traktr.username, password: Traktr.password,
81
+ username: @client.username, password: @client.password,
78
82
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
79
83
  episodes: episodes.collect{ |e| { season: e.season, episode: e.episode } }
80
84
  }
81
- response = self.post("/" + File.join("unseen", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
85
+ response = self.class.post("/" + File.join("unseen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
82
86
  raise ResponseError.new(response) if response.code != 200
83
87
 
84
88
  Mash.new(response.parsed_response)
85
89
  end
86
90
 
87
- def self.watchlist(show, episodes)
91
+ def watchlist(show, episodes)
88
92
  data = {
89
- username: Traktr.username, password: Traktr.password,
93
+ username: @client.username, password: @client.password,
90
94
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
91
95
  episodes: episodes.collect{ |e| { season: e.season, episode: e.episode } }
92
96
  }
93
- response = self.post("/" + File.join("watchlist", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
97
+ response = self.class.post("/" + File.join("watchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
94
98
  raise ResponseError.new(response) if response.code != 200
95
99
 
96
100
  Mash.new(response.parsed_response)
97
101
  end
98
102
 
99
- def self.unwatchlist(show, episodes)
103
+ def unwatchlist(show, episodes)
100
104
  data = {
101
- username: Traktr.username, password: Traktr.password,
105
+ username: @client.username, password: @client.password,
102
106
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
103
107
  episodes: episodes.collect{ |e| { season: e.season, episode: e.episode } }
104
108
  }
105
- response = self.post("/" + File.join("unwatchlist", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
109
+ response = self.class.post("/" + File.join("unwatchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
106
110
  raise ResponseError.new(response) if response.code != 200
107
111
 
108
112
  Mash.new(response.parsed_response)
@@ -1,31 +1,35 @@
1
1
  module Traktr
2
- module Show
3
- module Season
2
+ class Show
3
+ class Season
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::Show.base_uri, "season")
6
6
 
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
7
11
  ##
8
12
  ## show-season POST methods
9
13
  ##
10
- def self.library(show, season)
14
+ def library(show, season)
11
15
  data = {
12
- username: Traktr.username, password: Traktr.password,
16
+ username: @client.username, password: @client.password,
13
17
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
14
18
  season: season
15
19
  }
16
- response = self.post("/" + File.join("library", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
20
+ response = self.class.post("/" + File.join("library", @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
25
 
22
- def self.seen(show, season)
26
+ def seen(show, season)
23
27
  data = {
24
- username: Traktr.username, password: Traktr.password,
28
+ username: @client.username, password: @client.password,
25
29
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
26
30
  season: season
27
31
  }
28
- response = self.post("/" + File.join("seen", Traktr.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
32
+ response = self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
29
33
  raise ResponseError.new(response) if response.code != 200
30
34
 
31
35
  Mash.new(response.parsed_response)
@@ -1,13 +1,17 @@
1
1
  module Traktr
2
- module Shows
2
+ class Shows
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, 'shows')
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 |show|
@@ -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,24 +1,28 @@
1
1
  module Traktr
2
- module User
2
+ class User
3
3
  include HTTParty
4
4
  base_uri File.join(Traktr.base_uri, "user")
5
5
 
6
- def self.lastactivity(user = Traktr.username)
7
- response = self.get("/" + File.join("lastactivity.json", Traktr.api_key, user))
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def lastactivity(user = @client.username)
11
+ response = self.class.get("/" + File.join("lastactivity.json", @client.api_key, user))
8
12
  raise ResponseError.new(response) if response.code != 200
9
13
 
10
14
  Mash.new(response.parsed_response)
11
15
  end
12
16
 
13
- def self.list(slug, user = Traktr.username)
14
- response = self.get("/" + File.join("list.json", Traktr.api_key, user, slug))
17
+ def list(slug, user = @client.username)
18
+ response = self.class.get("/" + File.join("list.json", @client.api_key, user, slug))
15
19
  raise ResponseError.new(response) if response.code != 200
16
20
 
17
21
  Mash.new(response.parsed_response)
18
22
  end
19
23
 
20
- def self.lists(user = Traktr.username)
21
- response = self.get("/" + File.join("lists.json", Traktr.api_key, user))
24
+ def lists(user = @client.username)
25
+ response = self.class.get("/" + File.join("lists.json", @client.api_key, user))
22
26
  raise ResponseError.new(response) if response.code != 200
23
27
 
24
28
  response.parsed_response.collect do |item|
@@ -26,15 +30,15 @@ module Traktr
26
30
  end
27
31
  end
28
32
 
29
- def self.profile(user = Traktr.username)
30
- response = self.get("/" + File.join("profile.json", Traktr.api_key, user))
33
+ def profile(user = @client.username)
34
+ response = self.class.get("/" + File.join("profile.json", @client.api_key, user))
31
35
  raise ResponseError.new(response) if response.code != 200
32
36
 
33
37
  Mash.new(response.parsed_response)
34
38
  end
35
39
 
36
- def self.watching(user = Traktr.username)
37
- response = self.get("/" + File.join("watching.json", Traktr.api_key, user))
40
+ def watching(user = @client.username)
41
+ response = self.class.get("/" + File.join("watching.json", @client.api_key, user))
38
42
  raise ResponseError.new(response) if response.code != 200
39
43
 
40
44
  response.parsed_response.collect do |item|
@@ -44,8 +48,8 @@ module Traktr
44
48
  end
45
49
  end
46
50
 
47
- require 'traktr/user/library'
48
- require 'traktr/user/network'
49
- require 'traktr/user/progress'
50
- require 'traktr/user/ratings'
51
- require 'traktr/user/watchlist'
51
+ #require 'traktr/user/library'
52
+ #require 'traktr/user/network'
53
+ #require 'traktr/user/progress'
54
+ #require 'traktr/user/ratings'
55
+ #require 'traktr/user/watchlist'
@@ -4,9 +4,9 @@ module Traktr
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::User.base_uri, 'calendar')
6
6
 
7
- def self.shows(username = Traktr.username, date = Date.today, days = 7)
7
+ def shows(username = @client.username, date = Date.today, days = 7)
8
8
  date = date.strftime('%Y%m%d') if date.class == Date
9
- response = self.get('/' + File.join('shows.json', Traktr.api_key, username, date, days.to_s))
9
+ response = self.class.get('/' + File.join('shows.json', @client.api_key, username, date, days.to_s))
10
10
  raise ResponseError.new(response) if response.code != 200
11
11
 
12
12
  response.parsed_response.collect do |item|
@@ -5,8 +5,8 @@ module Traktr
5
5
  include HTTParty
6
6
  base_uri File.join(Traktr::User::Library.base_uri, 'movies')
7
7
 
8
- def self.all(username = Traktr.username, extended = :min)
9
- response = self.get('/' + File.join('all.json', Traktr.api_key, username, extended.to_s))
8
+ def all(username = @client.username, extended = :min)
9
+ response = self.class.get('/' + File.join('all.json', @client.api_key, username, extended.to_s))
10
10
  raise ResponseError.new(response) if response.code != 200
11
11
 
12
12
  response.parsed_response.collect do |item|
@@ -14,8 +14,8 @@ module Traktr
14
14
  end
15
15
  end
16
16
 
17
- def self.collection(username = Traktr.username, extended = :min)
18
- response = self.get('/' + File.join('collection.json', Traktr.api_key, username, extended.to_s))
17
+ def collection(username = @client.username, extended = :min)
18
+ response = self.class.get('/' + File.join('collection.json', @client.api_key, username, extended.to_s))
19
19
  raise ResponseError.new(response) if response.code != 200
20
20
 
21
21
  response.parsed_response.collect do |item|
@@ -23,8 +23,8 @@ module Traktr
23
23
  end
24
24
  end
25
25
 
26
- def self.watched(username = Traktr.username, extended = :min)
27
- response = self.get('/' + File.join('watched.json', Traktr.api_key, username, extended.to_s))
26
+ def watched(username = @client.username, extended = :min)
27
+ response = self.class.get('/' + File.join('watched.json', @client.api_key, username, extended.to_s))
28
28
  raise ResponseError.new(response) if response.code != 200
29
29
 
30
30
  response.parsed_response.collect do |item|
@@ -5,8 +5,8 @@ module Traktr
5
5
  include HTTParty
6
6
  base_uri File.join(Traktr::User::Library.base_uri, 'shows')
7
7
 
8
- def self.all(username = Traktr.username, extended = :min)
9
- response = self.get('/' + File.join('all.json', Traktr.api_key, username, extended.to_s))
8
+ def all(username = @client.username, extended = :min)
9
+ response = self.class.get('/' + File.join('all.json', @client.api_key, username, extended.to_s))
10
10
  raise ResponseError.new(response) if response.code != 200
11
11
 
12
12
  response.parsed_response.collect do |item|
@@ -14,8 +14,8 @@ module Traktr
14
14
  end
15
15
  end
16
16
 
17
- def self.collection(username = Traktr.username, extended = :min)
18
- response = self.get('/' + File.join('collection.json', Traktr.api_key, username, extended.to_s))
17
+ def collection(username = @client.username, extended = :min)
18
+ response = self.class.get('/' + File.join('collection.json', @client.api_key, username, extended.to_s))
19
19
  raise ResponseError.new(response) if response.code != 200
20
20
 
21
21
  response.parsed_response.collect do |item|
@@ -23,8 +23,8 @@ module Traktr
23
23
  end
24
24
  end
25
25
 
26
- def self.watched(username = Traktr.username, extended = :min)
27
- response = self.get('/' + File.join('watched.json', Traktr.api_key, username, extended.to_s))
26
+ def watched(username = @client.username, extended = :min)
27
+ response = self.class.get('/' + File.join('watched.json', @client.api_key, username, extended.to_s))
28
28
  raise ResponseError.new(response) if response.code != 200
29
29
 
30
30
  response.parsed_response.collect do |item|
@@ -4,8 +4,8 @@ module Traktr
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::User.base_uri, 'network')
6
6
 
7
- def self.followers(username = Traktr.username)
8
- response = self.get('/' + File.join('followers.json', Traktr.api_key, username))
7
+ def followers(username = @client.username)
8
+ response = self.class.get('/' + File.join('followers.json', @client.api_key, username))
9
9
  raise ResponseError.new(response) if response.code != 200
10
10
 
11
11
  response.parsed_response.collect do |item|
@@ -13,8 +13,8 @@ module Traktr
13
13
  end
14
14
  end
15
15
 
16
- def self.following(username = Traktr.username)
17
- response = self.get('/' + File.join('following.json', Traktr.api_key, username))
16
+ def following(username = @client.username)
17
+ response = self.class.get('/' + File.join('following.json', @client.api_key, username))
18
18
  raise ResponseError.new(response) if response.code != 200
19
19
 
20
20
  response.parsed_response.collect do |item|
@@ -22,8 +22,8 @@ module Traktr
22
22
  end
23
23
  end
24
24
 
25
- def self.friends(username = Traktr.username)
26
- response = self.get('/' + File.join('friends.json', Traktr.api_key, username))
25
+ def friends(username = @client.username)
26
+ response = self.class.get('/' + File.join('friends.json', @client.api_key, username))
27
27
  raise ResponseError.new(response) if response.code != 200
28
28
 
29
29
  response.parsed_response.collect do |item|
@@ -4,8 +4,8 @@ module Traktr
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::User.base_uri, 'progress')
6
6
 
7
- def self.collected(username = Traktr.username, title = :all, sort = :title, extended = :min)
8
- response = self.get('/' + File.join('collected.json', Traktr.api_key, username, title.to_s, sort.to_s, extended.to_s))
7
+ def collected(username = @client.username, title = :all, sort = :title, extended = :min)
8
+ response = self.class.get('/' + File.join('collected.json', @client.api_key, username, title.to_s, sort.to_s, extended.to_s))
9
9
  raise ResponseError.new(response) if response.code != 200
10
10
 
11
11
  response.parsed_response.collect do |item|
@@ -13,8 +13,8 @@ module Traktr
13
13
  end
14
14
  end
15
15
 
16
- def self.watched(username = Traktr.username, title = :all, sort = :title, extended = :min)
17
- response = self.get('/' + File.join('watched.json', Traktr.api_key, username, title.to_s, sort.to_s, extended.to_s))
16
+ def watched(username = @client.username, title = :all, sort = :title, extended = :min)
17
+ response = self.class.get('/' + File.join('watched.json', @client.api_key, username, title.to_s, sort.to_s, extended.to_s))
18
18
  raise ResponseError.new(response) if response.code != 200
19
19
 
20
20
  response.parsed_response.collect do |item|
@@ -4,8 +4,8 @@ module Traktr
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::User.base_uri, 'ratings')
6
6
 
7
- def self.episodes(username = Traktr.username, rating = :all, extended = :min)
8
- response = self.get('/' + File.join('episodes.json', Traktr.api_key, username, rating.to_s, extended.to_s))
7
+ def episodes(username = @client.username, rating = :all, extended = :min)
8
+ response = self.class.get('/' + File.join('episodes.json', @client.api_key, username, rating.to_s, extended.to_s))
9
9
  raise ResponseError.new(response) if response.code != 200
10
10
 
11
11
  response.parsed_response.collect do |item|
@@ -13,8 +13,8 @@ module Traktr
13
13
  end
14
14
  end
15
15
 
16
- def self.movies(username = Traktr.username, rating = :all, extended = :min)
17
- response = self.get('/' + File.join('movies.json', Traktr.api_key, username, rating.to_s, extended.to_s))
16
+ def movies(username = @client.username, rating = :all, extended = :min)
17
+ response = self.class.get('/' + File.join('movies.json', @client.api_key, username, rating.to_s, extended.to_s))
18
18
  raise ResponseError.new(response) if response.code != 200
19
19
 
20
20
  response.parsed_response.collect do |item|
@@ -22,8 +22,8 @@ module Traktr
22
22
  end
23
23
  end
24
24
 
25
- def self.shows(username = Traktr.username, rating = :all, extended = :min)
26
- response = self.get('/' + File.join('shows.json', Traktr.api_key, username, rating.to_s, extended.to_s))
25
+ def shows(username = @client.username, rating = :all, extended = :min)
26
+ response = self.class.get('/' + File.join('shows.json', @client.api_key, username, rating.to_s, extended.to_s))
27
27
  raise ResponseError.new(response) if response.code != 200
28
28
 
29
29
  response.parsed_response.collect do |item|
@@ -4,8 +4,8 @@ module Traktr
4
4
  include HTTParty
5
5
  base_uri File.join(Traktr::User.base_uri, 'watchlist')
6
6
 
7
- def self.episodes(username = Traktr.username)
8
- response = self.get('/' + File.join('episodes.json', Traktr.api_key, username))
7
+ def episodes(username = @client.username)
8
+ response = self.class.get('/' + File.join('episodes.json', @client.api_key, username))
9
9
  raise ResponseError.new(response) if response.code != 200
10
10
 
11
11
  response.parsed_response.collect do |item|
@@ -13,8 +13,8 @@ module Traktr
13
13
  end
14
14
  end
15
15
 
16
- def self.movies(username = Traktr.username)
17
- response = self.get('/' + File.join('movies.json', Traktr.api_key, username))
16
+ def movies(username = @client.username)
17
+ response = self.class.get('/' + File.join('movies.json', @client.api_key, username))
18
18
  raise ResponseError.new(response) if response.code != 200
19
19
 
20
20
  response.parsed_response.collect do |item|
@@ -22,8 +22,8 @@ module Traktr
22
22
  end
23
23
  end
24
24
 
25
- def self.shows(username = Traktr.username)
26
- response = self.get('/' + File.join('shows.json', Traktr.api_key, username))
25
+ def shows(username = @client.username)
26
+ response = self.class.get('/' + File.join('shows.json', @client.api_key, username))
27
27
  raise ResponseError.new(response) if response.code != 200
28
28
 
29
29
  response.parsed_response.collect do |item|