traktr 0.5.0 → 0.7.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -0
  3. data/lib/traktr.rb +1 -2
  4. data/lib/traktr/account.rb +5 -18
  5. data/lib/traktr/activity.rb +20 -45
  6. data/lib/traktr/activity/user.rb +12 -27
  7. data/lib/traktr/calendar.rb +13 -0
  8. data/lib/traktr/client.rb +52 -1
  9. data/lib/traktr/comment.rb +18 -0
  10. data/lib/traktr/endpoint.rb +38 -0
  11. data/lib/traktr/genres.rb +11 -0
  12. data/lib/traktr/lists.rb +22 -0
  13. data/lib/traktr/lists/items.rb +15 -0
  14. data/lib/traktr/movie.rb +29 -93
  15. data/lib/traktr/movies.rb +4 -22
  16. data/lib/traktr/network.rb +27 -0
  17. data/lib/traktr/rate.rb +30 -0
  18. data/lib/traktr/recommendations.rb +19 -0
  19. data/lib/traktr/search.rb +11 -46
  20. data/lib/traktr/server.rb +7 -0
  21. data/lib/traktr/show.rb +32 -99
  22. data/lib/traktr/show/episode.rb +13 -54
  23. data/lib/traktr/show/season.rb +3 -20
  24. data/lib/traktr/shows.rb +4 -22
  25. data/lib/traktr/user.rb +33 -36
  26. data/lib/traktr/user/calendar.rb +4 -12
  27. data/lib/traktr/user/library.rb +9 -7
  28. data/lib/traktr/user/library/movies.rb +6 -24
  29. data/lib/traktr/user/library/shows.rb +6 -24
  30. data/lib/traktr/user/network.rb +5 -23
  31. data/lib/traktr/user/progress.rb +4 -17
  32. data/lib/traktr/user/ratings.rb +5 -23
  33. data/lib/traktr/user/watchlist.rb +5 -23
  34. data/lib/traktr/version.rb +1 -1
  35. data/spec/calendar_spec.rb +78 -0
  36. data/spec/comment_spec.rb +65 -0
  37. data/spec/genres_spec.rb +33 -0
  38. data/spec/lists_items_spec.rb +65 -0
  39. data/spec/lists_spec.rb +64 -0
  40. data/spec/movie_spec.rb +8 -0
  41. data/spec/network_spec.rb +94 -0
  42. data/spec/rate_spec.rb +110 -0
  43. data/spec/recommendations_spec.rb +71 -0
  44. data/spec/server_spec.rb +25 -0
  45. data/spec/show_episode_spec.rb +8 -0
  46. data/spec/show_spec.rb +12 -0
  47. data/spec/spec.yaml.sample +11 -4
  48. data/spec/spec_helper.rb +13 -4
  49. data/spec/user_calendar_spec.rb +51 -0
  50. data/spec/user_library_movies_spec.rb +59 -0
  51. data/spec/user_library_shows_spec.rb +59 -0
  52. data/spec/user_network_spec.rb +59 -0
  53. data/spec/user_progress_spec.rb +47 -0
  54. data/spec/user_ratings_spec.rb +59 -0
  55. data/spec/user_spec.rb +115 -0
  56. data/spec/user_watchlist_spec.rb +59 -0
  57. metadata +46 -2
@@ -1,26 +1,13 @@
1
1
  module Traktr
2
2
  class Show
3
- class Season
4
- include HTTParty
5
- base_uri File.join(Traktr::Show.base_uri, "season")
6
-
7
- def initialize(client)
8
- @client = client
9
- end
10
-
11
- ##
12
- ## show-season POST methods
13
- ##
3
+ class Season < Endpoint
14
4
  def library(show, season)
15
5
  data = {
16
6
  username: @client.username, password: @client.password,
17
7
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
18
8
  season: season
19
9
  }
20
- response = self.class.post("/" + File.join("library", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
21
- raise ResponseError.new(response) if response.code != 200
22
-
23
- Mash.new(response.parsed_response)
10
+ parse_response self.class.post("/" + File.join("library", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
24
11
  end
25
12
 
26
13
  def seen(show, season)
@@ -29,12 +16,8 @@ module Traktr
29
16
  title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
30
17
  season: season
31
18
  }
32
- response = self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
33
- raise ResponseError.new(response) if response.code != 200
34
-
35
- Mash.new(response.parsed_response)
19
+ parse_response self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
36
20
  end
37
-
38
21
  end
39
22
  end
40
23
  end
@@ -1,30 +1,12 @@
1
1
  module Traktr
2
- class Shows
3
- include HTTParty
4
- base_uri File.join(Traktr.base_uri, 'shows')
5
-
6
- def initialize(client)
7
- @client = client
8
- end
9
-
10
- ##
11
- ## movies GET methods
12
- ##
2
+ class Shows < Endpoint
13
3
  def trending
14
- response = self.class.get('/' + File.join('trending.json', @client.api_key))
15
- raise ResponseError.new(response) if response.code != 200
16
-
17
- response.parsed_response.collect do |show|
18
- Mash.new(show)
19
- end
4
+ parse_response self.class.get('/' + File.join('trending.json', @client.api_key), :basic_auth => @auth)
20
5
  end
21
6
 
22
7
  def updated(timestamp)
23
- response = self.class.get('/' + File.join('updated.json', @client.api_key, timestamp.to_i.to_s))
24
- raise ResponseError.new(response) if response.code != 200
25
-
26
- Mash.new(response.parsed_response)
8
+ timestamp = timestamp.class == Time ? timestamp.to_i.to_s : timestamp.to_s
9
+ parse_response self.class.get('/' + File.join('updated.json', @client.api_key, timestamp))
27
10
  end
28
-
29
11
  end
30
12
  end
@@ -1,55 +1,52 @@
1
1
  module Traktr
2
- class User
3
- include HTTParty
4
- base_uri File.join(Traktr.base_uri, "user")
5
-
6
- def initialize(client)
7
- @client = client
2
+ class User < Endpoint
3
+ def lastactivity(user = @client.username)
4
+ parse_response self.class.get("/" + File.join("lastactivity.json", @client.api_key, user), :basic_auth => @auth)
8
5
  end
9
6
 
10
- def lastactivity(user = @client.username)
11
- response = self.class.get("/" + File.join("lastactivity.json", @client.api_key, user))
12
- raise ResponseError.new(response) if response.code != 200
7
+ def list(slug, user = @client.username)
8
+ parse_response self.class.get("/" + File.join("list.json", @client.api_key, user, slug), :basic_auth => @auth)
9
+ end
13
10
 
14
- Mash.new(response.parsed_response)
11
+ def lists(user = @client.username)
12
+ parse_response self.class.get("/" + File.join("lists.json", @client.api_key, user), :basic_auth => @auth)
15
13
  end
16
14
 
17
- def list(slug, user = @client.username)
18
- response = self.class.get("/" + File.join("list.json", @client.api_key, user, slug))
19
- raise ResponseError.new(response) if response.code != 200
15
+ def profile(user = @client.username)
16
+ parse_response self.class.get("/" + File.join("profile.json", @client.api_key, user), :basic_auth => @auth)
17
+ end
20
18
 
21
- Mash.new(response.parsed_response)
19
+ def watching(user = @client.username)
20
+ #
21
+ # TODO : When the user is protected or not currently watching anything, this
22
+ # returns an empty array. However, Trakt's documentation makes it seem
23
+ # like an empty object will be returned
24
+ #
25
+ parse_response self.class.get("/" + File.join("watching.json", @client.api_key, user), :basic_auth => @auth)
22
26
  end
23
27
 
24
- def lists(user = @client.username)
25
- response = self.class.get("/" + File.join("lists.json", @client.api_key, user))
26
- raise ResponseError.new(response) if response.code != 200
28
+ def calendar
29
+ @calendar ||= Traktr::User::Calendar.new(@client)
30
+ end
27
31
 
28
- response.parsed_response.collect do |item|
29
- Mash.new(item)
30
- end
32
+ def library
33
+ @library ||= Traktr::User::Library.new(@client)
31
34
  end
32
35
 
33
- def profile(user = @client.username)
34
- response = self.class.get("/" + File.join("profile.json", @client.api_key, user))
35
- raise ResponseError.new(response) if response.code != 200
36
+ def network
37
+ @network ||= Traktr::User::Network.new(@client)
38
+ end
36
39
 
37
- Mash.new(response.parsed_response)
40
+ def progress
41
+ @progress ||= Traktr::User::Progress.new(@client)
38
42
  end
39
43
 
40
- def watching(user = @client.username)
41
- response = self.class.get("/" + File.join("watching.json", @client.api_key, user))
42
- raise ResponseError.new(response) if response.code != 200
44
+ def ratings
45
+ @ratings ||= Traktr::User::Ratings.new(@client)
46
+ end
43
47
 
44
- response.parsed_response.collect do |item|
45
- Mash.new(item)
46
- end
48
+ def watchlist
49
+ @watchlist ||= Traktr::User::Watchlist.new(@client)
47
50
  end
48
51
  end
49
52
  end
50
-
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'
@@ -1,17 +1,9 @@
1
1
  module Traktr
2
- module User
3
- module Calendar
4
- include HTTParty
5
- base_uri File.join(Traktr::User.base_uri, 'calendar')
6
-
2
+ class User
3
+ class Calendar < Endpoint
7
4
  def shows(username = @client.username, date = Date.today, days = 7)
8
- date = date.strftime('%Y%m%d') if date.class == Date
9
- response = self.class.get('/' + File.join('shows.json', @client.api_key, username, date, days.to_s))
10
- raise ResponseError.new(response) if response.code != 200
11
-
12
- response.parsed_response.collect do |item|
13
- Mash.new(item)
14
- end
5
+ date = date.class == Date ? date.strftime("%Y%m%d") : date.to_s
6
+ parse_response self.class.get('/' + File.join('shows.json', @client.api_key, username, date, days.to_s), :basic_auth => @auth)
15
7
  end
16
8
  end
17
9
  end
@@ -1,11 +1,13 @@
1
1
  module Traktr
2
- module User
3
- module Library
4
- include HTTParty
5
- base_uri File.join(Traktr::User.base_uri, 'library')
2
+ class User
3
+ class Library < Endpoint
4
+ def movies
5
+ @movies ||= Traktr::User::Library::Movies.new(@client)
6
+ end
7
+
8
+ def shows
9
+ @shows ||= Traktr::User::Library::Shows.new(@client)
10
+ end
6
11
  end
7
12
  end
8
13
  end
9
-
10
- require 'traktr/user/library/movies'
11
- require 'traktr/user/library/shows'
@@ -1,35 +1,17 @@
1
1
  module Traktr
2
- module User
3
- module Library
4
- module Movies
5
- include HTTParty
6
- base_uri File.join(Traktr::User::Library.base_uri, 'movies')
7
-
2
+ class User
3
+ class Library
4
+ class Movies < Endpoint
8
5
  def all(username = @client.username, extended = :min)
9
- response = self.class.get('/' + File.join('all.json', @client.api_key, username, extended.to_s))
10
- raise ResponseError.new(response) if response.code != 200
11
-
12
- response.parsed_response.collect do |item|
13
- Mash.new(item)
14
- end
6
+ parse_response self.class.get('/' + File.join('all.json', @client.api_key, username, extended.to_s))
15
7
  end
16
8
 
17
9
  def collection(username = @client.username, extended = :min)
18
- response = self.class.get('/' + File.join('collection.json', @client.api_key, username, extended.to_s))
19
- raise ResponseError.new(response) if response.code != 200
20
-
21
- response.parsed_response.collect do |item|
22
- Mash.new(item)
23
- end
10
+ parse_response self.class.get('/' + File.join('collection.json', @client.api_key, username, extended.to_s))
24
11
  end
25
12
 
26
13
  def watched(username = @client.username, extended = :min)
27
- response = self.class.get('/' + File.join('watched.json', @client.api_key, username, extended.to_s))
28
- raise ResponseError.new(response) if response.code != 200
29
-
30
- response.parsed_response.collect do |item|
31
- Mash.new(item)
32
- end
14
+ parse_response self.class.get('/' + File.join('watched.json', @client.api_key, username, extended.to_s))
33
15
  end
34
16
  end
35
17
  end
@@ -1,35 +1,17 @@
1
1
  module Traktr
2
- module User
3
- module Library
4
- module Shows
5
- include HTTParty
6
- base_uri File.join(Traktr::User::Library.base_uri, 'shows')
7
-
2
+ class User
3
+ class Library
4
+ class Shows < Endpoint
8
5
  def all(username = @client.username, extended = :min)
9
- response = self.class.get('/' + File.join('all.json', @client.api_key, username, extended.to_s))
10
- raise ResponseError.new(response) if response.code != 200
11
-
12
- response.parsed_response.collect do |item|
13
- Mash.new(item)
14
- end
6
+ parse_response self.class.get('/' + File.join('all.json', @client.api_key, username, extended.to_s))
15
7
  end
16
8
 
17
9
  def collection(username = @client.username, extended = :min)
18
- response = self.class.get('/' + File.join('collection.json', @client.api_key, username, extended.to_s))
19
- raise ResponseError.new(response) if response.code != 200
20
-
21
- response.parsed_response.collect do |item|
22
- Mash.new(item)
23
- end
10
+ parse_response self.class.get('/' + File.join('collection.json', @client.api_key, username, extended.to_s))
24
11
  end
25
12
 
26
13
  def watched(username = @client.username, extended = :min)
27
- response = self.class.get('/' + File.join('watched.json', @client.api_key, username, extended.to_s))
28
- raise ResponseError.new(response) if response.code != 200
29
-
30
- response.parsed_response.collect do |item|
31
- Mash.new(item)
32
- end
14
+ parse_response self.class.get('/' + File.join('watched.json', @client.api_key, username, extended.to_s))
33
15
  end
34
16
  end
35
17
  end
@@ -1,34 +1,16 @@
1
1
  module Traktr
2
- module User
3
- module Network
4
- include HTTParty
5
- base_uri File.join(Traktr::User.base_uri, 'network')
6
-
2
+ class User
3
+ class Network < Endpoint
7
4
  def followers(username = @client.username)
8
- response = self.class.get('/' + File.join('followers.json', @client.api_key, username))
9
- raise ResponseError.new(response) if response.code != 200
10
-
11
- response.parsed_response.collect do |item|
12
- Mash.new(item)
13
- end
5
+ parse_response self.class.get('/' + File.join('followers.json', @client.api_key, username))
14
6
  end
15
7
 
16
8
  def following(username = @client.username)
17
- response = self.class.get('/' + File.join('following.json', @client.api_key, username))
18
- raise ResponseError.new(response) if response.code != 200
19
-
20
- response.parsed_response.collect do |item|
21
- Mash.new(item)
22
- end
9
+ parse_response self.class.get('/' + File.join('following.json', @client.api_key, username))
23
10
  end
24
11
 
25
12
  def friends(username = @client.username)
26
- response = self.class.get('/' + File.join('friends.json', @client.api_key, username))
27
- raise ResponseError.new(response) if response.code != 200
28
-
29
- response.parsed_response.collect do |item|
30
- Mash.new(item)
31
- end
13
+ parse_response self.class.get('/' + File.join('friends.json', @client.api_key, username))
32
14
  end
33
15
  end
34
16
  end
@@ -1,25 +1,12 @@
1
1
  module Traktr
2
- module User
3
- module Progress
4
- include HTTParty
5
- base_uri File.join(Traktr::User.base_uri, 'progress')
6
-
2
+ class User
3
+ class Progress < Endpoint
7
4
  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
- raise ResponseError.new(response) if response.code != 200
10
-
11
- response.parsed_response.collect do |item|
12
- Mash.new(item)
13
- end
5
+ parse_response self.class.get('/' + File.join('collected.json', @client.api_key, username, title.to_s, sort.to_s, extended.to_s))
14
6
  end
15
7
 
16
8
  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
- raise ResponseError.new(response) if response.code != 200
19
-
20
- response.parsed_response.collect do |item|
21
- Mash.new(item)
22
- end
9
+ parse_response self.class.get('/' + File.join('watched.json', @client.api_key, username, title.to_s, sort.to_s, extended.to_s))
23
10
  end
24
11
  end
25
12
  end
@@ -1,34 +1,16 @@
1
1
  module Traktr
2
- module User
3
- module Ratings
4
- include HTTParty
5
- base_uri File.join(Traktr::User.base_uri, 'ratings')
6
-
2
+ class User
3
+ class Ratings < Endpoint
7
4
  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
- raise ResponseError.new(response) if response.code != 200
10
-
11
- response.parsed_response.collect do |item|
12
- Mash.new(item)
13
- end
5
+ parse_response self.class.get('/' + File.join('episodes.json', @client.api_key, username, rating.to_s, extended.to_s))
14
6
  end
15
7
 
16
8
  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
- raise ResponseError.new(response) if response.code != 200
19
-
20
- response.parsed_response.collect do |item|
21
- Mash.new(item)
22
- end
9
+ parse_response self.class.get('/' + File.join('movies.json', @client.api_key, username, rating.to_s, extended.to_s))
23
10
  end
24
11
 
25
12
  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
- raise ResponseError.new(response) if response.code != 200
28
-
29
- response.parsed_response.collect do |item|
30
- Mash.new(item)
31
- end
13
+ parse_response self.class.get('/' + File.join('shows.json', @client.api_key, username, rating.to_s, extended.to_s))
32
14
  end
33
15
  end
34
16
  end
@@ -1,34 +1,16 @@
1
1
  module Traktr
2
- module User
3
- module Watchlist
4
- include HTTParty
5
- base_uri File.join(Traktr::User.base_uri, 'watchlist')
6
-
2
+ class User
3
+ class Watchlist < Endpoint
7
4
  def episodes(username = @client.username)
8
- response = self.class.get('/' + File.join('episodes.json', @client.api_key, username))
9
- raise ResponseError.new(response) if response.code != 200
10
-
11
- response.parsed_response.collect do |item|
12
- Mash.new(item)
13
- end
5
+ parse_response self.class.get('/' + File.join('episodes.json', @client.api_key, username))
14
6
  end
15
7
 
16
8
  def movies(username = @client.username)
17
- response = self.class.get('/' + File.join('movies.json', @client.api_key, username))
18
- raise ResponseError.new(response) if response.code != 200
19
-
20
- response.parsed_response.collect do |item|
21
- Mash.new(item)
22
- end
9
+ parse_response self.class.get('/' + File.join('movies.json', @client.api_key, username))
23
10
  end
24
11
 
25
12
  def shows(username = @client.username)
26
- response = self.class.get('/' + File.join('shows.json', @client.api_key, username))
27
- raise ResponseError.new(response) if response.code != 200
28
-
29
- response.parsed_response.collect do |item|
30
- Mash.new(item)
31
- end
13
+ parse_response self.class.get('/' + File.join('shows.json', @client.api_key, username))
32
14
  end
33
15
  end
34
16
  end