trakt_api 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +3 -1
  4. data/README.md +21 -209
  5. data/lib/trakt_api.rb +3 -17
  6. data/lib/trakt_api/base.rb +35 -68
  7. data/lib/trakt_api/client.rb +6 -67
  8. data/lib/trakt_api/search.rb +7 -18
  9. data/lib/trakt_api/version.rb +1 -1
  10. data/spec/fixtures/search.json +125 -0
  11. data/spec/functionals/search_spec.rb +23 -0
  12. data/spec/integrations/search_spec.rb +9 -30
  13. data/spec/spec_helper.rb +2 -38
  14. data/spec/support/.keep +0 -0
  15. data/spec/support/trakt_api.rb.example +1 -0
  16. data/trakt_api.gemspec +4 -3
  17. metadata +42 -94
  18. data/lib/generators/templates/trakt_api.rb +0 -5
  19. data/lib/generators/trakt_api/install_generator.rb +0 -12
  20. data/lib/trakt_api/account.rb +0 -16
  21. data/lib/trakt_api/activity.rb +0 -94
  22. data/lib/trakt_api/calendar.rb +0 -17
  23. data/lib/trakt_api/comment.rb +0 -16
  24. data/lib/trakt_api/configuration.rb +0 -7
  25. data/lib/trakt_api/genres.rb +0 -11
  26. data/lib/trakt_api/lists.rb +0 -26
  27. data/lib/trakt_api/movie.rb +0 -86
  28. data/lib/trakt_api/movies.rb +0 -11
  29. data/lib/trakt_api/network.rb +0 -26
  30. data/lib/trakt_api/rate.rb +0 -31
  31. data/lib/trakt_api/recommendations.rb +0 -21
  32. data/lib/trakt_api/server.rb +0 -6
  33. data/lib/trakt_api/show.rb +0 -151
  34. data/lib/trakt_api/shows.rb +0 -11
  35. data/lib/trakt_api/user.rb +0 -116
  36. data/spec/integration_spec_helper.rb +0 -3
  37. data/spec/integrations/account_spec.rb +0 -19
  38. data/spec/integrations/calendar_spec.rb +0 -31
  39. data/spec/integrations/client_spec.rb +0 -173
  40. data/spec/integrations/genres_spec.rb +0 -19
  41. data/spec/integrations/movies_spec.rb +0 -25
  42. data/spec/integrations/network_spec.rb +0 -37
  43. data/spec/integrations/server_spec.rb +0 -13
  44. data/spec/integrations/shows_spec.rb +0 -25
  45. data/spec/integrations/support/trakt_api.rb.example +0 -5
  46. data/spec/trakt_api/account_spec.rb +0 -56
  47. data/spec/trakt_api/activity_spec.rb +0 -243
  48. data/spec/trakt_api/base_spec.rb +0 -140
  49. data/spec/trakt_api/calendar_spec.rb +0 -48
  50. data/spec/trakt_api/client_spec.rb +0 -101
  51. data/spec/trakt_api/comment_spec.rb +0 -69
  52. data/spec/trakt_api/genres_spec.rb +0 -24
  53. data/spec/trakt_api/lists_spec.rb +0 -111
  54. data/spec/trakt_api/movie_spec.rb +0 -345
  55. data/spec/trakt_api/movies_spec.rb +0 -44
  56. data/spec/trakt_api/network_spec.rb +0 -105
  57. data/spec/trakt_api/rate_spec.rb +0 -132
  58. data/spec/trakt_api/recommendations_spec.rb +0 -90
  59. data/spec/trakt_api/search_spec.rb +0 -81
  60. data/spec/trakt_api/server_spec.rb +0 -15
  61. data/spec/trakt_api/show_spec.rb +0 -618
  62. data/spec/trakt_api/shows_spec.rb +0 -44
  63. data/spec/trakt_api/user_spec.rb +0 -489
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f02f863053f9b797654121ba6cd8d24e5e4c9b3
4
- data.tar.gz: f85005692b1ee864416f4e5413cf2a457796e040
3
+ metadata.gz: 57fc329e9fdc3c30dce19c946a54748086a0f144
4
+ data.tar.gz: 36cb6efb77dec44d517bff3bd2ea7036d19b64af
5
5
  SHA512:
6
- metadata.gz: 5abbbedea5d3b6472eb31401fb6278ecf6e7182753abcf2294016d1e517ea19f412990a0c57358254af46c4ed247af70bf367f84b7d527e19defc5d225adccf8
7
- data.tar.gz: a21c16ce803175971c0d4afa4a6b1603f9d889a410d60d5d2efba73d34d0f452b483b33eb6e3b66395cba3cb8bbcad092a8d5819c82b7a10e4245a69feb5fcfe
6
+ metadata.gz: a3f9bd0db3afc61e0a8e99b8ad4afd9cc72e3231cf290d957d460694098b11343039e12aa84f4ecaba85954f75661f0264718c302d7bea36be550a73ff214d40
7
+ data.tar.gz: ace82e63abf2a571a64d208a52455d10bd0ca7c4aed25277dd49f8378c41a828f9bfc6f4325c4235f06d9dd8a21dfeee90fad708dc681aeb23b1d4df5356bfcd
data/.gitignore CHANGED
@@ -16,4 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
 
19
- spec/integrations/support/trakt_api.rb
19
+ spec/support/trakt_api.rb
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
- script: 'bundle exec rspec spec/trakt_api'
2
+ script: 'bundle exec rspec spec/functionals'
3
3
  rvm:
4
+ - 1.9.3
4
5
  - 2.0.0
6
+ - 2.1.0
data/README.md CHANGED
@@ -1,247 +1,59 @@
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)
1
+ [![Build Status](https://travis-ci.org/tvapi/trakt_api.png?branch=master)](https://travis-ci.org/tvapi/trakt_api)
2
+ [![Dependency Status](https://gemnasium.com/tvapi/trakt_api.png)](https://gemnasium.com/tvapi/trakt_api)
3
+ [![Code Climate](https://codeclimate.com/github/tvapi/trakt_api.png)](https://codeclimate.com/github/tvapi/trakt_api)
4
+ [![Coverage Status](https://coveralls.io/repos/tvapi/trakt_api/badge.png)](https://coveralls.io/r/tvapi/trakt_api)
5
5
  [![Gem Version](https://badge.fury.io/rb/trakt_api.png)](http://badge.fury.io/rb/trakt_api)
6
6
 
7
7
  # TraktApi
8
8
 
9
9
  trakt_api is a simple ruby client for trakt.tv API.
10
10
 
11
- ## Getting started
11
+ ## Installation
12
12
 
13
- You can add it to your Gemfile with:
13
+ With Bundler:
14
14
 
15
15
  ```ruby
16
16
  gem 'trakt_api'
17
17
  ```
18
18
 
19
- Run the bundle command to install it.
20
-
21
- After you install ThetvdbApi and add it to your Gemfile, you need to run the generator (if you use Ruby on Rails application):
22
-
23
- ```console
24
- rails generate trakt_api:install
25
- ```
26
-
27
- The generator will install an initializer where you must past your api_key, username and password (not sha1).
28
-
29
- ## How to use
30
-
31
- There is one entry point, in initialize you can past hash with api_key, username and password (not sha1) values, or leave empty:
32
-
33
- ```ruby
34
- client = TrakApi::Client.new(api_key: '...', username: '...', password: '...')
35
- ```
36
-
37
- ## Usage
38
-
39
- 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
40
- ```ruby
41
- { auth: true }
42
- ```
43
- in options
44
-
45
- Full documentation is available here: [http://trakt.tv/api-docs](http://trakt.tv/api-docs)
46
-
47
-
48
- Account API
49
-
50
- ```ruby
51
- client.account.create({...})
52
- client.account.settings
53
- client.account.test
54
- ```
55
-
56
- Activity API
57
-
58
- ```ruby
59
- client.activity.community({...})
60
- client.activity.episodes({...})
61
- client.activity.friends({...})
62
- client.activity.movies({...})
63
- client.activity.seasons({...})
64
- client.activity.shows({...})
65
- client.activity.user({...})
66
- client.activity.user_episodes({...})
67
- client.activity.user_movies({...})
68
- client.activity.user_seasons({...})
69
- client.activity.user_shows({...})
70
- ```
71
-
72
- Calendar API
73
-
74
- ```ruby
75
- client.calendar.premieres({...})
76
- client.calendar.shows({...})
77
- ```
78
-
79
- Comment API
80
-
81
19
  ```ruby
82
- client.comment.episode({...})
83
- client.comment.movie({...})
84
- client.comment.show({...})
20
+ $ bundle install
85
21
  ```
86
22
 
87
- Genres API
23
+ Otherwhise:
88
24
 
89
25
  ```ruby
90
- client.genres.movies({...})
91
- client.genres.shows({...})
26
+ gem install trakt_api
92
27
  ```
28
+ ## How to use
93
29
 
94
- Lists API
30
+ You have two way for access to api:
95
31
 
96
- ```ruby
97
- client.lists.add({...})
98
- client.lists.delete({...})
99
- client.lists.items_add({...})
100
- client.lists.items_delete({...})
101
- client.lists.update({...})
102
- ```
32
+ * I case (create client class, one entry point)
103
33
 
104
- Movie API
34
+ Language attribute is optional with default value 'en'
105
35
 
106
36
  ```ruby
107
- client.movie.cancel_check_in
108
- client.movie.cancel_watching
109
- client.movie.check_in({...})
110
- client.movie.comments({...})
111
- client.movie.scrobble({...})
112
- client.movie.library({...})
113
- client.movie.related({...})
114
- client.movie.stats({...})
115
- client.movie.summary({...})
116
- client.movie.summaries({...})
117
- client.movie.unseen({...})
118
- client.movie.unwatch_list({...})
119
- client.movie.watching({...})
120
- client.movie.watching_now({...})
121
- client.movie.watch_list({...})
37
+ client = TraktApi::Client.new(api_key: '...')
38
+ client.search({..})
122
39
  ```
123
40
 
124
- Movies API
41
+ * II case (direct access to api class, many entry points)
125
42
 
126
- ```ruby
127
- client.movies.trending({...})
128
- client.movies.updated({...})
129
- ```
130
-
131
- Network API
43
+ Language attribute is required
132
44
 
133
45
  ```ruby
134
- client.network.approve({...})
135
- client.network.deny({...})
136
- client.network.follow({...})
137
- client.network.requests
138
- client.network.unfollow({...})
46
+ ThetvdbApi::Search.new(api_key: '...').call({...})
139
47
  ```
140
48
 
141
- Rate API
142
-
143
- ```ruby
144
- client.rate.episode({...})
145
- client.rate.episodes({...})
146
- client.rate.movie({...})
147
- client.rate.movies({...})
148
- client.rate.show({...})
149
- client.rate.shows({...})
150
- ```
49
+ ## Usage
151
50
 
152
- Recommendations API
153
-
154
- ```ruby
155
- client.recommendations.movies({...})
156
- client.recommendations.movies_dismiss({...})
157
- client.recommendations.shows({...})
158
- client.recommendations.shows_dismiss({...})
159
- ```
51
+ Full documentation is available here: [http://docs.trakt.apiary.io](http://docs.trakt.apiary.io)
160
52
 
161
53
  Search API
162
54
 
163
55
  ```ruby
164
- client.search.episodes({...})
165
- client.search.movies({...})
166
- client.search.people({...})
167
- client.search.shows({...})
168
- client.search.users({...})
169
- ```
170
-
171
- Server API
172
-
173
- ```ruby
174
- client.server.time
175
- ```
176
-
177
- Show API
178
-
179
- ```ruby
180
- client.show.cancel_check_in
181
- client.show.cancel_watching
182
- client.show.check_in({...})
183
- client.show.comments({...})
184
- client.show.episode_comments({...})
185
- client.show.episode_library({...})
186
- client.show.episode_seen({...})
187
- client.show.episode_stats({...})
188
- client.show.episode_summary({...})
189
- client.show.episode_unlibrary({...})
190
- client.show.episode_unseen({...})
191
- client.show.episode_unwatch_list({...})
192
- client.show.episode_watching_now({...})
193
- client.show.episode_watch_list({...})
194
- client.show.library({...})
195
- client.show.related({...})
196
- client.show.scrobble({...})
197
- client.show.season({...})
198
- client.show.season_library({...})
199
- client.show.season_seen({...})
200
- client.show.seasons({...})
201
- client.show.seen({...})
202
- client.show.stats({...})
203
- client.show.summary({...})
204
- client.show.summaries({...})
205
- client.show.unlibrary({...})
206
- client.show.unwatch_list({...})
207
- client.show.watching({...})
208
- client.show.watching_now({...})
209
- client.show.watch_list({...})
210
- ```
211
-
212
- Shows API
213
-
214
- ```ruby
215
- client.shows.trending({...})
216
- client.shows.updated({...})
217
- ```
218
-
219
- User API
220
-
221
- ```ruby
222
- client.user.calendar_shows({...})
223
- client.user.last_activity({...})
224
- client.user.library_movies_all({...})
225
- client.user.library_movies_collection({...})
226
- client.user.library_movies_watched({...})
227
- client.user.library_shows_all({...})
228
- client.user.library_shows_collection({...})
229
- client.user.library_shows_watched({...})
230
- client.user.list({...})
231
- client.user.lists({...})
232
- client.user.network_followers({...})
233
- client.user.network_following({...})
234
- client.user.network_friends({...})
235
- client.user.profile({...})
236
- client.user.progress_collected({...})
237
- client.user.progress_watched({...})
238
- client.user.ratings_episodes({...})
239
- client.user.ratings_movies({...})
240
- client.user.ratings_shows({...})
241
- client.user.watching({...})
242
- client.user.watch_list_episode({...})
243
- client.user.watch_list_movies({...})
244
- client.user.watch_list_shows({...})
56
+ client.search({...})
245
57
  ```
246
58
 
247
59
  ## Contributing
@@ -1,22 +1,8 @@
1
+ require 'ov'
2
+
1
3
  module TraktApi; end
2
4
 
3
5
  require 'trakt_api/version'
4
- require 'trakt_api/configuration'
5
6
  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
7
  require 'trakt_api/client'
8
+ require 'trakt_api/search'
@@ -1,89 +1,56 @@
1
- require 'httparty'
1
+ require 'service_api'
2
2
  require 'string_to_sha1'
3
3
 
4
4
  class TraktApi::Base
5
- include HTTParty
6
- base_uri 'http://api.trakt.tv//'
5
+ include ServiceApi::BaseFaraday
7
6
 
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 store_uri(uri)
22
- @uri = "#{uri}.json/#{api_key}"
23
- end
24
-
25
- def get(uri)
26
- store_uri(uri)
27
- @method = :get
28
-
29
- self
30
- end
31
-
32
- def post(uri)
33
- store_uri(uri)
34
- @method = :post
35
-
36
- self
7
+ %w[get post put delete].each do |method|
8
+ define_method method do
9
+ connection.headers = headers
10
+ connection.send(method, uri, query_params)
11
+ end
37
12
  end
38
13
 
39
14
  def params(options)
40
- @params = options
41
- auth if options.delete(:auth)
42
-
43
- self
44
- end
45
-
46
- def restful_params(fields = [])
47
- restful_params_string = ''
48
- fields.each do |field|
49
- value = @params.delete(field)
50
- restful_params_string += "/#{value}" if value
51
- end
52
- @uri = "#{@uri}#{restful_params_string}"
53
-
54
- self
55
- end
15
+ @token = options.delete(:token)
56
16
 
57
- def response
58
- self.class.send(@method, @uri, request_options)
17
+ super
59
18
  end
60
19
 
61
- def request_options
62
- { body: @params }.merge(@auth ? auth_hash : {})
63
- end
20
+ private
64
21
 
65
- def auth_hash
66
- {
67
- basic_auth: {
68
- username: username,
69
- password: password.to_sha1
70
- }
22
+ def headers
23
+ headers = {
24
+ 'Content-Type' => 'application/json',
25
+ 'trakt-api-key' => @config[:api_key],
26
+ 'trakt-api-version' => '2'
71
27
  }
72
- end
73
28
 
74
- def series_uri(series_id)
75
- "#{api_key}/series/#{series_id}/"
29
+ @token ? headers.merge('Authorization' => "Bearer #{@token}") : headers
76
30
  end
77
31
 
78
- def api_key
79
- @client.api_key
32
+ def connection
33
+ @connection ||= Faraday.new(url: base_url, ssl: { verify: false }) do |builder|
34
+ builder.request :json
35
+ builder.response :json, content_type: /\bjson$/
36
+
37
+ if @config[:adapter] == :test
38
+ builder.adapter @config[:adapter], @config[:adapter_options]
39
+ else
40
+ builder.adapter @config[:adapter] || :net_http
41
+ end
42
+ end
80
43
  end
81
44
 
82
- def username
83
- @client.username
45
+ def uri_kind
46
+ :colon
84
47
  end
85
48
 
86
- def password
87
- @client.password
49
+ def base_url
50
+ if @config[:sandbox]
51
+ 'https://api.staging.trakt.tv'
52
+ else
53
+ 'https://api.trakt.tv'
54
+ end
88
55
  end
89
56
  end
@@ -1,74 +1,13 @@
1
1
  class TraktApi::Client
2
- attr_reader :api_key, :username, :password
2
+ attr_reader :config
3
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
4
+ def initialize(config = {})
5
+ @config = config
66
6
 
67
- def shows
68
- @shows ||= TraktApi::Shows.new(self)
7
+ @config[:adapter] ||= :net_http
69
8
  end
70
9
 
71
- def user
72
- @user ||= TraktApi::User.new(self)
10
+ def search(options)
11
+ @search ||= TraktApi::Search.new(config).call(options)
73
12
  end
74
13
  end