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
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::Recommendations do
4
+ context 'POST methods' do
5
+ context 'with valid api_key and auth credentials' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
8
+ end
9
+
10
+ it '#movies' do
11
+ expect( @trakt.recommendations.movies.class ).to eql(Array)
12
+ end
13
+
14
+ it '#shows' do
15
+ expect( @trakt.recommendations.shows.class ).to eql(Array)
16
+ end
17
+
18
+ it '#movies_dismiss' do
19
+ expect( @trakt.recommendations.movies_dismiss({:imdb_id => "tt0435761"}).status ).to eql("success")
20
+ end
21
+
22
+ it '#shows_dismiss' do
23
+ expect( @trakt.recommendations.shows_dismiss({:tvdb_id => "80348"}).status ).to eql("success")
24
+ end
25
+ end
26
+
27
+ context 'without valid api_key' do
28
+ before :all do
29
+ @trakt = Traktr::Client.new(nil)
30
+ end
31
+
32
+ it '#movies' do
33
+ expect{ @trakt.recommendations.movies.class }.to raise_error(Traktr::ResponseError)
34
+ end
35
+
36
+ it '#shows' do
37
+ expect{ @trakt.recommendations.shows.class }.to raise_error(Traktr::ResponseError)
38
+ end
39
+
40
+ it '#movies_dismiss' do
41
+ expect{ @trakt.recommendations.movies_dismiss({:imdb_id => "tt0435761"}).status }.to raise_error(Traktr::ResponseError)
42
+ end
43
+
44
+ it '#shows_dismiss' do
45
+ expect{ @trakt.recommendations.shows_dismiss({:tvdb_id => "80348"}).status }.to raise_error(Traktr::ResponseError)
46
+ end
47
+ end
48
+
49
+ context 'without auth credentials' do
50
+ before :all do
51
+ @trakt = Traktr::Client.new(API_KEY)
52
+ end
53
+
54
+ it '#movies' do
55
+ expect{ @trakt.recommendations.movies.class }.to raise_error(Traktr::ResponseError)
56
+ end
57
+
58
+ it '#shows' do
59
+ expect{ @trakt.recommendations.shows.class }.to raise_error(Traktr::ResponseError)
60
+ end
61
+
62
+ it '#movies_dismiss' do
63
+ expect{ @trakt.recommendations.movies_dismiss({:imdb_id => "tt0435761"}).status }.to raise_error(Traktr::ResponseError)
64
+ end
65
+
66
+ it '#shows_dismiss' do
67
+ expect{ @trakt.recommendations.shows_dismiss({:tvdb_id => "80348"}).status }.to raise_error(Traktr::ResponseError)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::Server do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY)
8
+ end
9
+
10
+ it '#time' do
11
+ expect( @trakt.server.time ).to be
12
+ end
13
+ end
14
+
15
+ context 'without valid api_key' do
16
+ before :all do
17
+ @trakt = Traktr::Client.new(nil)
18
+ end
19
+
20
+ it '#movies' do
21
+ expect { @trakt.server.time }.to raise_error(Traktr::ResponseError)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -23,6 +23,10 @@ describe Traktr::Show::Episode do
23
23
  expect( @trakt.show.episode.comments(@show, @season, @episode).size ).to be > 0
24
24
  end
25
25
 
26
+ it '#stats' do
27
+ expect( @trakt.show.episode.stats(@show, @season, @episode).keys.size ).to eql(8)
28
+ end
29
+
26
30
  it '#summary' do
27
31
  expect( @trakt.show.episode.summary(@show, @season, @episode).show.imdb_id ).to eql('tt1520211')
28
32
  end
@@ -41,6 +45,10 @@ describe Traktr::Show::Episode do
41
45
  expect { @trakt.show.episode.comments(@show, @season, @episode) }.to raise_error(Traktr::ResponseError)
42
46
  end
43
47
 
48
+ it '#stats' do
49
+ expect { @trakt.show.episode.stats(@show, @season, @episode) }.to raise_error(Traktr::ResponseError)
50
+ end
51
+
44
52
  it '#summary' do
45
53
  expect { @trakt.show.episode.summary(@show, @season, @episode) }.to raise_error(Traktr::ResponseError)
46
54
  end
@@ -35,6 +35,10 @@ describe Traktr::Show do
35
35
  it '#related' do
36
36
  expect( @trakt.show.related('dexter').size ).to eql(10)
37
37
  end
38
+
39
+ it '#stats' do
40
+ expect( @trakt.show.stats('dexter').size ).to eql(8)
41
+ end
38
42
  end
39
43
 
40
44
  context 'with invalid query' do
@@ -66,6 +70,10 @@ describe Traktr::Show do
66
70
  it '#related' do
67
71
  expect { @trakt.show.related('blah') }.to raise_error(Traktr::ResponseError)
68
72
  end
73
+
74
+ it '#stats' do
75
+ expect { @trakt.show.stats('blah') }.to raise_error(Traktr::ResponseError)
76
+ end
69
77
  end
70
78
 
71
79
  end
@@ -102,6 +110,10 @@ describe Traktr::Show do
102
110
  it '#related' do
103
111
  expect { @trakt.show.related('the-walking-dead') }.to raise_error(Traktr::ResponseError)
104
112
  end
113
+
114
+ it '#stats' do
115
+ expect { @trakt.show.stats('the-walking-dead') }.to raise_error(Traktr::ResponseError)
116
+ end
105
117
  end
106
118
  end
107
119
 
@@ -1,7 +1,14 @@
1
1
  #
2
- # WARNING: This account is used for automated unit testing.
2
+ # WARNING: These accounts are used for automated unit testing.
3
3
  # Do not use your normal Trakt user account!
4
4
  #
5
- api_key: "<TRAKT_API_KEY>"
6
- username: "<TRAKT_USERNAME>"
7
- password: "<TRAKT_PASSWORD>"
5
+ # The first account is used for all unit tests
6
+ # The second account is needed to test the "network" endpoints
7
+ #
8
+ users:
9
+ - api_key: "<TRAKT_API_KEY>"
10
+ username: "<TRAKT_USERNAME>"
11
+ password: "<TRAKT_PASSWORD>"
12
+ - api_key: "<SECONDARY_API_KEY>"
13
+ username: "<SECONDARY_USERNAME>"
14
+ password: "<SECONDARY_PASSWORD>"
@@ -8,9 +8,18 @@ require 'traktr'
8
8
 
9
9
  if File.exist?(File.join(File.dirname(__FILE__), "spec.yaml"))
10
10
  config = YAML.load_file(File.join(File.dirname(__FILE__), "spec.yaml"))
11
- API_KEY = config["api_key"]
12
- USERNAME = config["username"]
13
- PASSWORD = config["password"]
11
+ if config["users"].class == Array && config["users"].size == 2
12
+ API_KEY = config["users"][0]["api_key"]
13
+ USERNAME = config["users"][0]["username"]
14
+ PASSWORD = config["users"][0]["password"]
15
+
16
+ API_KEY_2 = config["users"][1]["api_key"]
17
+ USERNAME_2 = config["users"][1]["username"]
18
+ PASSWORD_2 = config["users"][1]["password"]
19
+ else
20
+ $stderr.puts "ERROR: Your spec file must match the format shown in 'spec.yaml.sample' in the spec directory!"
21
+ exit 1
22
+ end
14
23
  else
15
24
  $stderr.puts "ERROR: You must configure the 'spec.yaml' file in the spec directory!"
16
25
  exit 1
@@ -20,7 +29,7 @@ end
20
29
  RSpec.configure do |config|
21
30
  config.treat_symbols_as_metadata_keys_with_true_values = true
22
31
  config.run_all_when_everything_filtered = true
23
- # config.filter_run :focus
32
+ config.filter_run_excluding :misbehaving => true
24
33
 
25
34
  # Run specs in random order to surface order dependencies. If you find an
26
35
  # order dependency and want to debug it, you can fix the order by providing
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::User::Calendar do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY)
8
+ end
9
+
10
+ it '#shows' do
11
+ shows = @trakt.user.calendar.shows(USERNAME)
12
+ expect( shows.class ).to eql(Array)
13
+ end
14
+ end
15
+
16
+ context 'with valid api_key and auth credentials' do
17
+ before :all do
18
+ @trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
19
+ end
20
+
21
+ it '#shows' do
22
+ shows = @trakt.user.calendar.shows
23
+ expect( shows.class ).to eql(Array)
24
+ shows.each do |day|
25
+ day.episodes.each do |episode|
26
+ expect( episode.show.rating ).not_to eql(nil)
27
+ expect( episode.show.rating_advanced ).not_to eql(nil)
28
+ expect( episode.show.in_watchlist ).not_to eql(nil)
29
+
30
+ expect( episode.episode.watched ).not_to eql(nil)
31
+ expect( episode.episode.plays ).not_to eql(nil)
32
+ expect( episode.episode.in_watchlist ).not_to eql(nil)
33
+ expect( episode.episode.in_collection ).not_to eql(nil)
34
+ expect( episode.episode.rating ).not_to eql(nil)
35
+ expect( episode.episode.rating_advanced ).not_to eql(nil)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'without valid api_key' do
42
+ before :all do
43
+ @trakt = Traktr::Client.new(nil)
44
+ end
45
+
46
+ it '#shows' do
47
+ expect { @trakt.user.calendar.shows }.to raise_error(Traktr::ResponseError)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::User::Library::Movies do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY)
8
+ end
9
+
10
+ it '#all' do
11
+ expect( @trakt.user.library.movies.all("traktr").size ).to be >= 0
12
+ end
13
+
14
+ it '#collection' do
15
+ expect( @trakt.user.library.movies.collection("traktr").size ).to be >= 0
16
+ end
17
+
18
+ it '#watched' do
19
+ expect( @trakt.user.library.movies.watched("traktr").size ).to be >= 0
20
+ end
21
+ end
22
+
23
+ context 'with valid api_key and auth credentials' do
24
+ before :all do
25
+ @trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
26
+ end
27
+
28
+ it '#all' do
29
+ expect( @trakt.user.library.movies.all.size ).to be >= 0
30
+ end
31
+
32
+ it '#collection' do
33
+ expect( @trakt.user.library.movies.collection.size ).to be >= 0
34
+ end
35
+
36
+ it '#watched' do
37
+ expect( @trakt.user.library.movies.watched.size ).to be >= 0
38
+ end
39
+ end
40
+
41
+ context 'without valid api_key' do
42
+ before :all do
43
+ @trakt = Traktr::Client.new(nil)
44
+ end
45
+
46
+ it '#all' do
47
+ expect{ @trakt.user.library.movies.all("traktr").size }.to raise_error(Traktr::ResponseError)
48
+ end
49
+
50
+ it '#collection' do
51
+ expect{ @trakt.user.library.movies.collection("traktr").size }.to raise_error(Traktr::ResponseError)
52
+ end
53
+
54
+ it '#watched' do
55
+ expect{ @trakt.user.library.movies.watched("traktr").size }.to raise_error(Traktr::ResponseError)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::User::Library::Shows do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY)
8
+ end
9
+
10
+ it '#all' do
11
+ expect( @trakt.user.library.shows.all("traktr").size ).to be >= 0
12
+ end
13
+
14
+ it '#collection' do
15
+ expect( @trakt.user.library.shows.collection("traktr").size ).to be >= 0
16
+ end
17
+
18
+ it '#watched' do
19
+ expect( @trakt.user.library.shows.watched("traktr").size ).to be >= 0
20
+ end
21
+ end
22
+
23
+ context 'with valid api_key and auth credentials' do
24
+ before :all do
25
+ @trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
26
+ end
27
+
28
+ it '#all' do
29
+ expect( @trakt.user.library.shows.all.size ).to be >= 0
30
+ end
31
+
32
+ it '#collection' do
33
+ expect( @trakt.user.library.shows.collection.size ).to be >= 0
34
+ end
35
+
36
+ it '#watched' do
37
+ expect( @trakt.user.library.shows.watched.size ).to be >= 0
38
+ end
39
+ end
40
+
41
+ context 'without valid api_key' do
42
+ before :all do
43
+ @trakt = Traktr::Client.new(nil)
44
+ end
45
+
46
+ it '#all' do
47
+ expect{ @trakt.user.library.shows.all("traktr").size }.to raise_error(Traktr::ResponseError)
48
+ end
49
+
50
+ it '#collection' do
51
+ expect{ @trakt.user.library.shows.collection("traktr").size }.to raise_error(Traktr::ResponseError)
52
+ end
53
+
54
+ it '#watched' do
55
+ expect{ @trakt.user.library.shows.watched("traktr").size }.to raise_error(Traktr::ResponseError)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::User::Network do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY)
8
+ end
9
+
10
+ it '#followers' do
11
+ expect( @trakt.user.network.followers("traktr").size ).to be >= 0
12
+ end
13
+
14
+ it '#following' do
15
+ expect( @trakt.user.network.following("traktr").size ).to be >= 0
16
+ end
17
+
18
+ it '#friends' do
19
+ expect( @trakt.user.network.friends("traktr").size ).to be >= 0
20
+ end
21
+ end
22
+
23
+ context 'with valid api_key and auth credentials' do
24
+ before :all do
25
+ @trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
26
+ end
27
+
28
+ it '#followers' do
29
+ expect( @trakt.user.network.followers.size ).to be >= 0
30
+ end
31
+
32
+ it '#following' do
33
+ expect( @trakt.user.network.following.size ).to be >= 0
34
+ end
35
+
36
+ it '#friends' do
37
+ expect( @trakt.user.network.friends.size ).to be >= 0
38
+ end
39
+ end
40
+
41
+ context 'without valid api_key' do
42
+ before :all do
43
+ @trakt = Traktr::Client.new(nil)
44
+ end
45
+
46
+ it '#followers' do
47
+ expect{ @trakt.user.network.followers("traktr").size }.to raise_error(Traktr::ResponseError)
48
+ end
49
+
50
+ it '#following' do
51
+ expect{ @trakt.user.network.following("traktr").size }.to raise_error(Traktr::ResponseError)
52
+ end
53
+
54
+ it '#friends' do
55
+ expect{ @trakt.user.network.friends("traktr").size }.to raise_error(Traktr::ResponseError)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::User::Progress do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ @trakt = Traktr::Client.new(API_KEY)
8
+ end
9
+
10
+ it '#collected' do
11
+ expect( @trakt.user.progress.collected("traktr").size ).to be >= 0
12
+ end
13
+
14
+ it '#watched' do
15
+ expect( @trakt.user.progress.watched("traktr").size ).to be >= 0
16
+ end
17
+ end
18
+
19
+ context 'with valid api_key and auth credentials' do
20
+ before :all do
21
+ @trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
22
+ end
23
+
24
+ it '#collected' do
25
+ expect( @trakt.user.progress.collected.size ).to be >= 0
26
+ end
27
+
28
+ it '#watched' do
29
+ expect( @trakt.user.progress.watched.size ).to be >= 0
30
+ end
31
+ end
32
+
33
+ context 'without valid api_key' do
34
+ before :all do
35
+ @trakt = Traktr::Client.new(nil)
36
+ end
37
+
38
+ it '#collected' do
39
+ expect{ @trakt.user.progress.collected("traktr").size }.to raise_error(Traktr::ResponseError)
40
+ end
41
+
42
+ it '#watched' do
43
+ expect{ @trakt.user.progress.watched("traktr").size }.to raise_error(Traktr::ResponseError)
44
+ end
45
+ end
46
+ end
47
+ end