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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51fdf3bbcf2e850646ad5b135011562e3b1499ba
4
+ data.tar.gz: 99db31861fcd5b3adad40ef9b1975333d11fcce9
5
+ SHA512:
6
+ metadata.gz: f1870bd798113f962fcbbb7cc8dedf485f844502f0700e6c45d532506adb4678f754d2df8e274604e24493653600a8f8e3a58477c4f11ce66c43cb5b088e64b6
7
+ data.tar.gz: 773b03d6166fc576186dbd4c15d6dd41b0668411817e8a29d5f9a9274cbfab776c655265e34cc138040e1adebf5a70e52edab4659386fbd2248b589e836e99f5
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ spec/integrations/support/trakt_api.rb
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: 'bundle exec rspec spec/trakt_api'
3
+ rvm:
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trakt_api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Krzysztof Wawer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,252 @@
1
+ [![Build Status](https://travis-ci.org/wafcio/trakt_api.png?branch=master)](https://travis-ci.org/wafcio/trakt_api)
2
+ [![Dependency Status](https://gemnasium.com/wafcio/trakt_api.png)](https://gemnasium.com/wafcio/trakt_api)
3
+ [![Code Climate](https://codeclimate.com/github/wafcio/trakt_api.png)](https://codeclimate.com/github/wafcio/trakt_api)
4
+ [![Coverage Status](https://coveralls.io/repos/wafcio/trakt_api/badge.png)](https://coveralls.io/r/wafcio/trakt_api)
5
+
6
+ # TraktApi
7
+
8
+ trakt_api is a simple ruby client for trakt.tv API.
9
+
10
+ ## Getting started
11
+
12
+ You can add it to your Gemfile with:
13
+
14
+ ```ruby
15
+ gem 'trakt_api'
16
+ ```
17
+
18
+ Run the bundle command to install it.
19
+
20
+ After you install ThetvdbApi and add it to your Gemfile, you need to run the generator (if you use Ruby on Rails application):
21
+
22
+ ```console
23
+ rails generate trakt_api:install
24
+ ```
25
+
26
+ The generator will install an initializer where you must past your api_key, username and password (not sha1).
27
+
28
+ ## How to use
29
+
30
+ There is one entry point, in initialize you can past hash with api_key, username and password (not sha1) values, or leave empty:
31
+
32
+ ```ruby
33
+ client = TrakApi::Client.new(api_key: '...', username: '...', password: '...')
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ For Authentication this gem use Basic Authentication, so you don't need pass username and password in each api call. If you want active authentication (if authentication is optional) in api call you must pass
39
+ ```ruby
40
+ { auth: true }
41
+ ```
42
+ in options
43
+
44
+ Full documentation is available here: [http://trakt.tv/api-docs](http://trakt.tv/api-docs)
45
+
46
+
47
+ Account API
48
+
49
+ ```ruby
50
+ client.account.create({...})
51
+ client.account.settings
52
+ client.account.test
53
+ ```
54
+
55
+ Activity API
56
+
57
+ ```ruby
58
+ client.activity.community({...})
59
+ client.activity.episodes({...})
60
+ client.activity.friends({...})
61
+ client.activity.movies({...})
62
+ client.activity.seasons({...})
63
+ client.activity.shows({...})
64
+ client.activity.user({...})
65
+ client.activity.user_episodes({...})
66
+ client.activity.user_movies({...})
67
+ client.activity.user_seasons({...})
68
+ client.activity.user_shows({...})
69
+ ```
70
+
71
+ Calendar API
72
+
73
+ ```ruby
74
+ client.calendar.premieres({...})
75
+ client.calendar.shows({...})
76
+ ```
77
+
78
+ Comment API
79
+
80
+ ```ruby
81
+ client.comment.episode({...})
82
+ client.comment.movie({...})
83
+ client.comment.show({...})
84
+ ```
85
+
86
+ Genres API
87
+
88
+ ```ruby
89
+ client.genres.movies({...})
90
+ client.genres.shows({...})
91
+ ```
92
+
93
+ Lists API
94
+
95
+ ```ruby
96
+ client.lists.add({...})
97
+ client.lists.delete({...})
98
+ client.lists.items_add({...})
99
+ client.lists.items_delete({...})
100
+ client.lists.update({...})
101
+ ```
102
+
103
+ Movie API
104
+
105
+ ```ruby
106
+ client.movie.cancel_checkin
107
+ client.movie.cancel_watching
108
+ client.movie.checkin({...})
109
+ client.movie.comments({...})
110
+ client.movie.scrobble({...})
111
+ client.movie.library({...})
112
+ client.movie.related({...})
113
+ client.movie.stats({...})
114
+ client.movie.summary({...})
115
+ client.movie.summaries({...})
116
+ client.movie.unseen({...})
117
+ client.movie.unwatch_list({...})
118
+ client.movie.watching({...})
119
+ client.movie.watching_now({...})
120
+ client.movie.watch_list({...})
121
+ ```
122
+
123
+ Movies API
124
+
125
+ ```ruby
126
+ client.movies.trending({...})
127
+ client.movies.updated({...})
128
+ ```
129
+
130
+ Network API
131
+
132
+ ```ruby
133
+ client.network.approve({...})
134
+ client.network.deny({...})
135
+ client.network.follow({...})
136
+ client.network.requests
137
+ client.network.unfollow({...})
138
+ ```
139
+
140
+ Rate API
141
+
142
+ ```ruby
143
+ client.rate.episode({...})
144
+ client.rate.episodes({...})
145
+ client.rate.movie({...})
146
+ client.rate.movies({...})
147
+ client.rate.show({...})
148
+ client.rate.shows({...})
149
+ ```
150
+
151
+ Recommendations API
152
+
153
+ ```ruby
154
+ client.recommendations.movies({...})
155
+ client.recommendations.movies_dismiss({...})
156
+ client.recommendations.shows({...})
157
+ client.recommendations.shows_dismiss({...})
158
+ ```
159
+
160
+ Search API
161
+
162
+ ```ruby
163
+ client.search.episodes({...})
164
+ client.search.movies({...})
165
+ client.search.people({...})
166
+ client.search.shows({...})
167
+ client.search.users({...})
168
+ ```
169
+
170
+ Server API
171
+
172
+ ```ruby
173
+ client.server.time
174
+ ```
175
+
176
+ Show API
177
+
178
+ ```ruby
179
+ client.show.cancel_checkin
180
+ client.show.cancel_watching
181
+ client.show.check_in({...})
182
+ client.show.comments({...})
183
+ client.show.episode_comments({...})
184
+ client.show.episode_library({...})
185
+ client.show.episode_seen({...})
186
+ client.show.episode_stats({...})
187
+ client.show.episode_summary({...})
188
+ client.show.episode_unlibrary({...})
189
+ client.show.episode_unseen({...})
190
+ client.show.episode_unwatch_list({...})
191
+ client.show.episode_watching_now({...})
192
+ client.show.episode_watch_list({...})
193
+ client.show.library({...})
194
+ client.show.related({...})
195
+ client.show.scrobble({...})
196
+ client.show.season({...})
197
+ client.show.season_library({...})
198
+ client.show.season_seen({...})
199
+ client.show.seasons({...})
200
+ client.show.seen({...})
201
+ client.show.stats({...})
202
+ client.show.summary({...})
203
+ client.show.summaries({...})
204
+ client.show.unlibrary({...})
205
+ client.show.unwatch_list({...})
206
+ client.show.watching({...})
207
+ client.show.watching_now({...})
208
+ client.show.watch_list({...})
209
+ ```
210
+
211
+ Shows API
212
+
213
+ ```ruby
214
+ client.shows.trending({...})
215
+ client.shows.updated({...})
216
+ ```
217
+
218
+ User API
219
+
220
+ ```ruby
221
+ client.user.calendar_shows({...})
222
+ client.user.last_activity({...})
223
+ client.user.library_movies_all({...})
224
+ client.user.library_movies_collection({...})
225
+ client.user.library_movies_watched({...})
226
+ client.user.library_shows_all({...})
227
+ client.user.library_shows_collection({...})
228
+ client.user.library_shows_watched({...})
229
+ client.user.list({...})
230
+ client.user.lists({...})
231
+ client.user.network_followers({...})
232
+ client.user.network_following({...})
233
+ client.user.network_friends({...})
234
+ client.user.profile({...})
235
+ client.user.progress_collected({...})
236
+ client.user.progress_watched({...})
237
+ client.user.ratings_episodes({...})
238
+ client.user.ratings_movies({...})
239
+ client.user.ratings_shows({...})
240
+ client.user.watching({...})
241
+ client.user.watchlist_episode({...})
242
+ client.user.watchlist_movies({...})
243
+ client.user.watchlist_shows({...})
244
+ ```
245
+
246
+ ## Contributing
247
+
248
+ 1. Fork it
249
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
250
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
251
+ 4. Push to the branch (`git push origin my-new-feature`)
252
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ TraktApi::Configuration.configure do |config|
2
+ config.api_key = ''
3
+ config.username = ''
4
+ config.password = ''
5
+ end
@@ -0,0 +1,12 @@
1
+ module TraktApi
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../templates', __FILE__)
5
+
6
+ desc 'Creates a TraktApi::Configuration initializer and copy locale files to your application.'
7
+ def copy_initializer
8
+ template 'trakt_api.rb', 'config/initializers/trakt_api.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ module TraktApi; end
2
+
3
+ require 'trakt_api/version'
4
+ require 'trakt_api/configuration'
5
+ require 'trakt_api/base'
6
+ require 'trakt_api/account'
7
+ require 'trakt_api/activity'
8
+ require 'trakt_api/calendar'
9
+ require 'trakt_api/comment'
10
+ require 'trakt_api/genres'
11
+ require 'trakt_api/lists'
12
+ require 'trakt_api/movie'
13
+ require 'trakt_api/movies'
14
+ require 'trakt_api/network'
15
+ require 'trakt_api/rate'
16
+ require 'trakt_api/recommendations'
17
+ require 'trakt_api/search'
18
+ require 'trakt_api/server'
19
+ require 'trakt_api/show'
20
+ require 'trakt_api/shows'
21
+ require 'trakt_api/user'
22
+ require 'trakt_api/client'
@@ -0,0 +1,16 @@
1
+ class TraktApi::Account < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/account-create
3
+ def create(options = {})
4
+ post('account/create').params(options).response
5
+ end
6
+
7
+ # documentation: http://trakt.tv/api-docs/account-settings
8
+ def settings
9
+ auth.post('account/settings').response
10
+ end
11
+
12
+ # documentation: http://trakt.tv/api-docs/account-test
13
+ def test
14
+ auth.post('account/test').response
15
+ end
16
+ end
@@ -0,0 +1,109 @@
1
+ class TraktApi::Activity < TraktApi::Base
2
+ # documentation: http://trakt.tv/api-docs/activity-community
3
+ def community(options = {})
4
+ optional_auth(options).get('activity/community').restful_params(options, type_fields).
5
+ params(query_params(options, type_fields)).response
6
+ end
7
+
8
+ # documentation: http://trakt.tv/api-docs/activity-episodes
9
+ def episodes(options = {})
10
+ optional_auth(options).get('activity/episodes').restful_params(options, episodes_fields).
11
+ params(query_params(options, episodes_fields)).response
12
+ end
13
+
14
+ # documentation: http://trakt.tv/api-docs/activity-friends
15
+ def friends(options = {})
16
+ auth.post('activity/friends').restful_params(options, type_fields).params(query_params(options, type_fields)).
17
+ response
18
+ end
19
+
20
+ # documentation: http://trakt.tv/api-docs/activity-movies
21
+ def movies(options = {})
22
+ optional_auth(options).get('activity/movies').restful_params(options, title_fields).
23
+ params(query_params(options, title_fields)).response
24
+ end
25
+
26
+ # documentation: http://trakt.tv/api-docs/activity-seasons
27
+ def seasons(options = {})
28
+ optional_auth(options).get('activity/seasons').restful_params(options, seasons_fields).
29
+ params(query_params(options, seasons_fields)).response
30
+ end
31
+
32
+ # documentation: http://trakt.tv/api-docs/activity-shows
33
+ def shows(options = {})
34
+ optional_auth(options).get('activity/shows').restful_params(options, title_fields).
35
+ params(query_params(options, title_fields)).response
36
+ end
37
+
38
+ # documentation: http://trakt.tv/api-docs/activity-user
39
+ def user(options = {})
40
+ optional_auth(options).get('activity/user').restful_params(options, user_fields).
41
+ params(query_params(options, user_fields)).response
42
+ end
43
+
44
+ # documentation: http://trakt.tv/api-docs/activity-user-episodes
45
+ def user_episodes(options = {})
46
+ optional_auth(options).get('activity/user/episodes').restful_params(options, user_episodes_fields).
47
+ params(query_params(options, user_episodes_fields)).response
48
+ end
49
+
50
+ # documentation: http://trakt.tv/api-docs/activity-user-movies
51
+ def user_movies(options = {})
52
+ optional_auth(options).get('activity/user/movies').restful_params(options, user_title_fields).
53
+ params(query_params(options, user_title_fields)).response
54
+ end
55
+
56
+ # documentation: http://trakt.tv/api-docs/activity-user-seasons
57
+ def user_seasons(options = {})
58
+ optional_auth(options).get('activity/user/seasons').restful_params(options, user_seasons_fields).
59
+ params(query_params(options, user_seasons_fields)).response
60
+ end
61
+
62
+ # documentation: http://trakt.tv/api-docs/activity-user-shows
63
+ def user_shows(options = {})
64
+ optional_auth(options).get('activity/user/shows').restful_params(options, user_title_fields).
65
+ params(query_params(options, user_title_fields)).response
66
+ end
67
+
68
+ def query_params(options, fields)
69
+ options.reject{ |option| fields.include?(option) }
70
+ end
71
+
72
+ private
73
+
74
+ def period_fields
75
+ [:start_ts, :end_ts]
76
+ end
77
+
78
+ def type_fields
79
+ [:types, :action] + period_fields
80
+ end
81
+
82
+ def episodes_fields
83
+ [:title, :season, :episode, :action] + period_fields
84
+ end
85
+
86
+ def title_fields
87
+ [:title, :action] + period_fields
88
+ end
89
+
90
+ def seasons_fields
91
+ [:title, :season, :action] + period_fields
92
+ end
93
+
94
+ def user_fields
95
+ [:username] + type_fields
96
+ end
97
+
98
+ def user_episodes_fields
99
+ [:username] + episodes_fields
100
+ end
101
+
102
+ def user_title_fields
103
+ [:username] + title_fields
104
+ end
105
+
106
+ def user_seasons_fields
107
+ [:username] + seasons_fields
108
+ end
109
+ end