trakt_api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +252 -0
  7. data/Rakefile +1 -0
  8. data/lib/generators/templates/trakt_api.rb +5 -0
  9. data/lib/generators/trakt_api/install_generator.rb +12 -0
  10. data/lib/trakt_api.rb +22 -0
  11. data/lib/trakt_api/account.rb +16 -0
  12. data/lib/trakt_api/activity.rb +109 -0
  13. data/lib/trakt_api/base.rb +93 -0
  14. data/lib/trakt_api/calendar.rb +17 -0
  15. data/lib/trakt_api/client.rb +74 -0
  16. data/lib/trakt_api/comment.rb +16 -0
  17. data/lib/trakt_api/configuration.rb +7 -0
  18. data/lib/trakt_api/genres.rb +11 -0
  19. data/lib/trakt_api/lists.rb +26 -0
  20. data/lib/trakt_api/movie.rb +86 -0
  21. data/lib/trakt_api/movies.rb +11 -0
  22. data/lib/trakt_api/network.rb +26 -0
  23. data/lib/trakt_api/rate.rb +31 -0
  24. data/lib/trakt_api/recommendations.rb +21 -0
  25. data/lib/trakt_api/search.rb +26 -0
  26. data/lib/trakt_api/server.rb +6 -0
  27. data/lib/trakt_api/show.rb +152 -0
  28. data/lib/trakt_api/shows.rb +11 -0
  29. data/lib/trakt_api/user.rb +124 -0
  30. data/lib/trakt_api/version.rb +3 -0
  31. data/spec/integration_spec_helper.rb +3 -0
  32. data/spec/integrations/account_spec.rb +19 -0
  33. data/spec/integrations/calendar_spec.rb +31 -0
  34. data/spec/integrations/client_spec.rb +173 -0
  35. data/spec/integrations/genres_spec.rb +19 -0
  36. data/spec/integrations/movies_spec.rb +25 -0
  37. data/spec/integrations/network_spec.rb +37 -0
  38. data/spec/integrations/search_spec.rb +37 -0
  39. data/spec/integrations/server_spec.rb +13 -0
  40. data/spec/integrations/shows_spec.rb +25 -0
  41. data/spec/integrations/support/trakt_api.rb.example +5 -0
  42. data/spec/spec_helper.rb +43 -0
  43. data/spec/trakt_api/account_spec.rb +56 -0
  44. data/spec/trakt_api/activity_spec.rb +297 -0
  45. data/spec/trakt_api/base_spec.rb +147 -0
  46. data/spec/trakt_api/calendar_spec.rb +48 -0
  47. data/spec/trakt_api/client_spec.rb +101 -0
  48. data/spec/trakt_api/comment_spec.rb +69 -0
  49. data/spec/trakt_api/genres_spec.rb +24 -0
  50. data/spec/trakt_api/lists_spec.rb +111 -0
  51. data/spec/trakt_api/movie_spec.rb +333 -0
  52. data/spec/trakt_api/movies_spec.rb +38 -0
  53. data/spec/trakt_api/network_spec.rb +105 -0
  54. data/spec/trakt_api/rate_spec.rb +132 -0
  55. data/spec/trakt_api/recommendations_spec.rb +90 -0
  56. data/spec/trakt_api/search_spec.rb +81 -0
  57. data/spec/trakt_api/server_spec.rb +15 -0
  58. data/spec/trakt_api/show_spec.rb +588 -0
  59. data/spec/trakt_api/shows_spec.rb +38 -0
  60. data/spec/trakt_api/user_spec.rb +561 -0
  61. data/trakt_api.gemspec +29 -0
  62. metadata +232 -0
@@ -0,0 +1,93 @@
1
+ require 'httparty'
2
+ require 'string_to_sha1'
3
+
4
+ class TraktApi::Base
5
+ include HTTParty
6
+ base_uri 'http://api.trakt.tv//'
7
+
8
+ def initialize(client)
9
+ @client = client
10
+
11
+ @auth = false
12
+ @params = {}
13
+ end
14
+
15
+ def auth
16
+ @auth = true
17
+
18
+ self
19
+ end
20
+
21
+ def optional_auth(options)
22
+ auth if options[:auth]
23
+
24
+ self
25
+ end
26
+
27
+ def store_uri(uri)
28
+ @uri = "#{uri}.json/#{api_key}"
29
+ end
30
+
31
+ def get(uri)
32
+ store_uri(uri)
33
+ @method = :get
34
+
35
+ self
36
+ end
37
+
38
+ def post(uri)
39
+ store_uri(uri)
40
+ @method = :post
41
+
42
+ self
43
+ end
44
+
45
+ def params(options)
46
+ @params = options
47
+
48
+ self
49
+ end
50
+
51
+ def restful_params(options, fields)
52
+ restful_params_string = ''
53
+ fields.each do |field|
54
+ restful_params_string += "/#{options[field]}" if options[field]
55
+ end
56
+ @uri = "#{@uri}/#{restful_params_string}"
57
+
58
+ self
59
+ end
60
+
61
+ def response
62
+ self.class.send(@method, @uri, request_options)
63
+ end
64
+
65
+ def request_options
66
+ { body: @params }.merge(@auth ? auth_hash : {})
67
+ end
68
+
69
+ def auth_hash
70
+ {
71
+ basic_auth: {
72
+ username: username,
73
+ password: password.to_sha1
74
+ }
75
+ }
76
+ end
77
+
78
+ def series_uri(series_id)
79
+ "#{api_key}/series/#{series_id}/"
80
+ end
81
+
82
+ def api_key
83
+ @client.api_key
84
+ end
85
+
86
+ def username
87
+ @client.username
88
+ end
89
+
90
+ def password
91
+ @client.password
92
+ end
93
+ end
@@ -0,0 +1,17 @@
1
+ class TraktApi::Calendar < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/calendar-premieres
3
+ def premieres(options = {})
4
+ optional_auth(options).get('calendar/premieres').restful_params(options, fields).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/calendar-shows
8
+ def shows(options = {})
9
+ optional_auth(options).get('calendar/shows').restful_params(options, fields).response
10
+ end
11
+
12
+ private
13
+
14
+ def fields
15
+ [:date, :days]
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ class TraktApi::Client
2
+ attr_reader :api_key, :username, :password
3
+
4
+ def initialize(options = {})
5
+ [:api_key, :username, :password]. each do |key|
6
+ value = options[key] ? options[key] : TraktApi::Configuration.send(key)
7
+ instance_variable_set("@#{key}", value)
8
+ end
9
+ end
10
+
11
+ def account
12
+ @account ||= TraktApi::Account.new(self)
13
+ end
14
+
15
+ def activity
16
+ @activity ||= TraktApi::Activity.new(self)
17
+ end
18
+
19
+ def calendar
20
+ @calendar ||= TraktApi::Calendar.new(self)
21
+ end
22
+
23
+ def comment
24
+ @comment ||= TraktApi::Comment.new(self)
25
+ end
26
+
27
+ def genres
28
+ @genres ||= TraktApi::Genres.new(self)
29
+ end
30
+
31
+ def lists
32
+ @lists ||= TraktApi::Lists.new(self)
33
+ end
34
+
35
+ def movie
36
+ @movie ||= TraktApi::Movie.new(self)
37
+ end
38
+
39
+ def movies
40
+ @movies ||= TraktApi::Movies.new(self)
41
+ end
42
+
43
+ def network
44
+ @network ||= TraktApi::Network.new(self)
45
+ end
46
+
47
+ def rate
48
+ @rate ||= TraktApi::Rate.new(self)
49
+ end
50
+
51
+ def recommendations
52
+ @recommendations ||= TraktApi::Recommendations.new(self)
53
+ end
54
+
55
+ def search
56
+ @search ||= TraktApi::Search.new(self)
57
+ end
58
+
59
+ def server
60
+ @server ||= TraktApi::Server.new(self)
61
+ end
62
+
63
+ def show
64
+ @server ||= TraktApi::Show.new(self)
65
+ end
66
+
67
+ def shows
68
+ @shows ||= TraktApi::Shows.new(self)
69
+ end
70
+
71
+ def user
72
+ @user ||= TraktApi::User.new(self)
73
+ end
74
+ end
@@ -0,0 +1,16 @@
1
+ class TraktApi::Comment < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/comment-episode
3
+ def episode(options = {})
4
+ auth.post('comment/episode').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/comment-movie
8
+ def movie(options = {})
9
+ auth.post('comment/movie').params(options).response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/comment-show
13
+ def show(options = {})
14
+ auth.post('comment/show').params(options).response
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require 'confiture'
2
+
3
+ class TraktApi::Configuration
4
+ include Confiture::Configuration
5
+
6
+ confiture_allowed_keys(:api_key, :username, :password)
7
+ end
@@ -0,0 +1,11 @@
1
+ class TraktApi::Genres < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/genres-movies
3
+ def movies
4
+ get('genres/movies').response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/genres-shows
8
+ def shows
9
+ get('genres/shows').response
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ class TraktApi::Lists < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/lists-add
3
+ def add(options = {})
4
+ auth.post('lists/add').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/lists-delete
8
+ def delete(options = {})
9
+ auth.post('lists/delete').params(options).response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/lists-items-add
13
+ def items_add(options = {})
14
+ auth.post('lists/items/add').params(options).response
15
+ end
16
+
17
+ # documentation: http://trakt.tv/api-docs/lists-items-delete
18
+ def items_delete(options = {})
19
+ auth.post('lists/items/delete').params(options).response
20
+ end
21
+
22
+ # documentation: http://trakt.tv/api-docs/lists-update
23
+ def update(options = {})
24
+ auth.post('lists/update').params(options).response
25
+ end
26
+ end
@@ -0,0 +1,86 @@
1
+ class TraktApi::Movie < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/movie-cancelcheckin
3
+ def cancel_checkin
4
+ auth.post('movie/cancelcheckin').response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/movie-cancelwatching
8
+ def cancel_watching
9
+ auth.post('movie/cancelwatching').response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/movie-checkin
13
+ def checkin(options = {})
14
+ auth.post('movie/checkin').params(options).response
15
+ end
16
+
17
+ # documentation: http://trakt.tv/api-docs/movie-comments
18
+ def comments(options = {})
19
+ get('movie/comments').restful_params(options, [:title, :type]).response
20
+ end
21
+
22
+ # documentation: http://trakt.tv/api-docs/movie-scrobble
23
+ def scrobble(options = {})
24
+ auth.post('movie/scrobble').params(options).response
25
+ end
26
+
27
+ # documentation: http://trakt.tv/api-docs/movie-seen
28
+ def seen(options = {})
29
+ auth.post('movie/seen').params(options).response
30
+ end
31
+
32
+ # documentation: http://trakt.tv/api-docs/movie-library
33
+ def library(options = {})
34
+ auth.post('movie/library').params(options).response
35
+ end
36
+
37
+ # documentation: http://trakt.tv/api-docs/movie-related
38
+ def related(options = {})
39
+ optional_auth(options).get('movie/related').restful_params(options, [:title, :hidewatched]).response
40
+ end
41
+
42
+ # documentation: http://trakt.tv/api-docs/movie-stats
43
+ def stats(options = {})
44
+ get('movie/stats').restful_params(options, [:title]).response
45
+ end
46
+
47
+ # documentation: http://trakt.tv/api-docs/movie-summary
48
+ def summary(options = {})
49
+ optional_auth(options).get('movie/summary').restful_params(options, [:title]).response
50
+ end
51
+
52
+ # documentation: http://trakt.tv/api-docs/movie-summaries
53
+ def summaries(options = {})
54
+ get('movie/summaries').restful_params(options, [:title, :extended]).response
55
+ end
56
+
57
+ # documentation: http://trakt.tv/api-docs/movie-unlibrary
58
+ def unlibrary(options = {})
59
+ auth.post('movie/unlibrary').params(options).response
60
+ end
61
+
62
+ # documentation: http://trakt.tv/api-docs/movie-unseen
63
+ def unseen(options = {})
64
+ auth.post('movie/unseen').params(options).response
65
+ end
66
+
67
+ # documentation: http://trakt.tv/api-docs/movie-unwatchlist
68
+ def unwatch_list(options = {})
69
+ auth.post('movie/unwatchlist').params(options).response
70
+ end
71
+
72
+ # documentation: http://trakt.tv/api-docs/movie-watching
73
+ def watching(options = {})
74
+ auth.post('movie/watching').params(options).response
75
+ end
76
+
77
+ # documentation: http://trakt.tv/api-docs/movie-watchingnow
78
+ def watching_now(options = {})
79
+ optional_auth(options).get('movie/watchingnow').restful_params(options, [:title]).response
80
+ end
81
+
82
+ # documentation: http://trakt.tv/api-docs/movie-watchlist
83
+ def watch_list(options = {})
84
+ auth.post('movie/watchlist').params(options).response
85
+ end
86
+ end
@@ -0,0 +1,11 @@
1
+ class TraktApi::Movies < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/movies-trending
3
+ def trending(options = {})
4
+ optional_auth(options).get('movies/trending').response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/movies-updated
8
+ def updated(options = {})
9
+ get('movies/updated').restful_params(options, [:timestamp]).response
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ class TraktApi::Network < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/network-approve
3
+ def approve(options = {})
4
+ auth.post('network/approve').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/network-deny
8
+ def deny(options = {})
9
+ auth.post('network/deny').params(options).response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/network-follow
13
+ def follow(options = {})
14
+ auth.post('network/follow').params(options).response
15
+ end
16
+
17
+ # documentation: http://trakt.tv/api-docs/network-requests
18
+ def requests
19
+ auth.post('network/requests').response
20
+ end
21
+
22
+ # documentation: http://trakt.tv/api-docs/network-unfollow
23
+ def unfollow(options = {})
24
+ auth.post('network/unfollow').params(options).response
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ class TraktApi::Rate < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/rate-episode
3
+ def episode(options)
4
+ auth.post('rate/episode').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/rate-episodes
8
+ def episodes(options)
9
+ auth.post('rate/episodes').params(options).response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/rate-movie
13
+ def movie(options)
14
+ auth.post('rate/movie').params(options).response
15
+ end
16
+
17
+ # documentation: http://trakt.tv/api-docs/rate-movies
18
+ def movies(options)
19
+ auth.post('rate/movies').params(options).response
20
+ end
21
+
22
+ # documentation: http://trakt.tv/api-docs/rate-show
23
+ def show(options)
24
+ auth.post('rate/show').params(options).response
25
+ end
26
+
27
+ # documentation: http://trakt.tv/api-docs/rate-shows
28
+ def shows(options)
29
+ auth.post('rate/shows').params(options).response
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ class TraktApi::Recommendations < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/recommendations-movies
3
+ def movies(options)
4
+ auth.post('recommendations/movies').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/recommendations-movies-dismiss
8
+ def movies_dismiss(options)
9
+ auth.post('recommendations/movies/dismiss').params(options).response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/recommendations-shows
13
+ def shows(options)
14
+ auth.post('recommendations/shows').params(options).response
15
+ end
16
+
17
+ # documentation: http://trakt.tv/api-docs/recommendations-shows-dismiss
18
+ def shows_dismiss(options)
19
+ auth.post('recommendations/shows/dismiss').params(options).response
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ class TraktApi::Search < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/search-episodes
3
+ def episodes(options = {})
4
+ get('search/episodes').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/search-movies
8
+ def movies(options = {})
9
+ get('search/movies').params(options).response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/search-people
13
+ def people(options = {})
14
+ get('search/people').params(options).response
15
+ end
16
+
17
+ # documentation: http://trakt.tv/api-docs/search-shows
18
+ def shows(options = {})
19
+ get('search/shows').params(options).response
20
+ end
21
+
22
+ # documentation: http://trakt.tv/api-docs/search-users
23
+ def users(options = {})
24
+ get('search/users').params(options).response
25
+ end
26
+ end