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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +3 -1
- data/README.md +21 -209
- data/lib/trakt_api.rb +3 -17
- data/lib/trakt_api/base.rb +35 -68
- data/lib/trakt_api/client.rb +6 -67
- data/lib/trakt_api/search.rb +7 -18
- data/lib/trakt_api/version.rb +1 -1
- data/spec/fixtures/search.json +125 -0
- data/spec/functionals/search_spec.rb +23 -0
- data/spec/integrations/search_spec.rb +9 -30
- data/spec/spec_helper.rb +2 -38
- data/spec/support/.keep +0 -0
- data/spec/support/trakt_api.rb.example +1 -0
- data/trakt_api.gemspec +4 -3
- metadata +42 -94
- data/lib/generators/templates/trakt_api.rb +0 -5
- data/lib/generators/trakt_api/install_generator.rb +0 -12
- data/lib/trakt_api/account.rb +0 -16
- data/lib/trakt_api/activity.rb +0 -94
- data/lib/trakt_api/calendar.rb +0 -17
- data/lib/trakt_api/comment.rb +0 -16
- data/lib/trakt_api/configuration.rb +0 -7
- data/lib/trakt_api/genres.rb +0 -11
- data/lib/trakt_api/lists.rb +0 -26
- data/lib/trakt_api/movie.rb +0 -86
- data/lib/trakt_api/movies.rb +0 -11
- data/lib/trakt_api/network.rb +0 -26
- data/lib/trakt_api/rate.rb +0 -31
- data/lib/trakt_api/recommendations.rb +0 -21
- data/lib/trakt_api/server.rb +0 -6
- data/lib/trakt_api/show.rb +0 -151
- data/lib/trakt_api/shows.rb +0 -11
- data/lib/trakt_api/user.rb +0 -116
- data/spec/integration_spec_helper.rb +0 -3
- data/spec/integrations/account_spec.rb +0 -19
- data/spec/integrations/calendar_spec.rb +0 -31
- data/spec/integrations/client_spec.rb +0 -173
- data/spec/integrations/genres_spec.rb +0 -19
- data/spec/integrations/movies_spec.rb +0 -25
- data/spec/integrations/network_spec.rb +0 -37
- data/spec/integrations/server_spec.rb +0 -13
- data/spec/integrations/shows_spec.rb +0 -25
- data/spec/integrations/support/trakt_api.rb.example +0 -5
- data/spec/trakt_api/account_spec.rb +0 -56
- data/spec/trakt_api/activity_spec.rb +0 -243
- data/spec/trakt_api/base_spec.rb +0 -140
- data/spec/trakt_api/calendar_spec.rb +0 -48
- data/spec/trakt_api/client_spec.rb +0 -101
- data/spec/trakt_api/comment_spec.rb +0 -69
- data/spec/trakt_api/genres_spec.rb +0 -24
- data/spec/trakt_api/lists_spec.rb +0 -111
- data/spec/trakt_api/movie_spec.rb +0 -345
- data/spec/trakt_api/movies_spec.rb +0 -44
- data/spec/trakt_api/network_spec.rb +0 -105
- data/spec/trakt_api/rate_spec.rb +0 -132
- data/spec/trakt_api/recommendations_spec.rb +0 -90
- data/spec/trakt_api/search_spec.rb +0 -81
- data/spec/trakt_api/server_spec.rb +0 -15
- data/spec/trakt_api/show_spec.rb +0 -618
- data/spec/trakt_api/shows_spec.rb +0 -44
- data/spec/trakt_api/user_spec.rb +0 -489
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57fc329e9fdc3c30dce19c946a54748086a0f144
|
4
|
+
data.tar.gz: 36cb6efb77dec44d517bff3bd2ea7036d19b64af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3f9bd0db3afc61e0a8e99b8ad4afd9cc72e3231cf290d957d460694098b11343039e12aa84f4ecaba85954f75661f0264718c302d7bea36be550a73ff214d40
|
7
|
+
data.tar.gz: ace82e63abf2a571a64d208a52455d10bd0ca7c4aed25277dd49f8378c41a828f9bfc6f4325c4235f06d9dd8a21dfeee90fad708dc681aeb23b1d4df5356bfcd
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,247 +1,59 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/
|
2
|
-
[![Dependency Status](https://gemnasium.com/
|
3
|
-
[![Code Climate](https://codeclimate.com/github/
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/
|
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
|
-
##
|
11
|
+
## Installation
|
12
12
|
|
13
|
-
|
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
|
-
|
83
|
-
client.comment.movie({...})
|
84
|
-
client.comment.show({...})
|
20
|
+
$ bundle install
|
85
21
|
```
|
86
22
|
|
87
|
-
|
23
|
+
Otherwhise:
|
88
24
|
|
89
25
|
```ruby
|
90
|
-
|
91
|
-
client.genres.shows({...})
|
26
|
+
gem install trakt_api
|
92
27
|
```
|
28
|
+
## How to use
|
93
29
|
|
94
|
-
|
30
|
+
You have two way for access to api:
|
95
31
|
|
96
|
-
|
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
|
-
|
34
|
+
Language attribute is optional with default value 'en'
|
105
35
|
|
106
36
|
```ruby
|
107
|
-
client.
|
108
|
-
client.
|
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
|
-
|
41
|
+
* II case (direct access to api class, many entry points)
|
125
42
|
|
126
|
-
|
127
|
-
client.movies.trending({...})
|
128
|
-
client.movies.updated({...})
|
129
|
-
```
|
130
|
-
|
131
|
-
Network API
|
43
|
+
Language attribute is required
|
132
44
|
|
133
45
|
```ruby
|
134
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
data/lib/trakt_api.rb
CHANGED
@@ -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'
|
data/lib/trakt_api/base.rb
CHANGED
@@ -1,89 +1,56 @@
|
|
1
|
-
require '
|
1
|
+
require 'service_api'
|
2
2
|
require 'string_to_sha1'
|
3
3
|
|
4
4
|
class TraktApi::Base
|
5
|
-
include
|
6
|
-
base_uri 'http://api.trakt.tv//'
|
5
|
+
include ServiceApi::BaseFaraday
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
@
|
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
|
-
|
58
|
-
self.class.send(@method, @uri, request_options)
|
17
|
+
super
|
59
18
|
end
|
60
19
|
|
61
|
-
|
62
|
-
{ body: @params }.merge(@auth ? auth_hash : {})
|
63
|
-
end
|
20
|
+
private
|
64
21
|
|
65
|
-
def
|
66
|
-
{
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
75
|
-
"#{api_key}/series/#{series_id}/"
|
29
|
+
@token ? headers.merge('Authorization' => "Bearer #{@token}") : headers
|
76
30
|
end
|
77
31
|
|
78
|
-
def
|
79
|
-
@
|
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
|
83
|
-
|
45
|
+
def uri_kind
|
46
|
+
:colon
|
84
47
|
end
|
85
48
|
|
86
|
-
def
|
87
|
-
@
|
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
|
data/lib/trakt_api/client.rb
CHANGED
@@ -1,74 +1,13 @@
|
|
1
1
|
class TraktApi::Client
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :config
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
|
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
|
-
|
68
|
-
@shows ||= TraktApi::Shows.new(self)
|
7
|
+
@config[:adapter] ||= :net_http
|
69
8
|
end
|
70
9
|
|
71
|
-
def
|
72
|
-
@
|
10
|
+
def search(options)
|
11
|
+
@search ||= TraktApi::Search.new(config).call(options)
|
73
12
|
end
|
74
13
|
end
|