traktr 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -2
- data/lib/traktr.rb +2 -11
- data/lib/traktr/account.rb +11 -8
- data/lib/traktr/client.rb +57 -0
- data/lib/traktr/movie.rb +33 -29
- data/lib/traktr/movies.rb +9 -5
- data/lib/traktr/search.rb +15 -11
- data/lib/traktr/show.rb +53 -37
- data/lib/traktr/show/episode.rb +30 -26
- data/lib/traktr/show/season.rb +12 -8
- data/lib/traktr/shows.rb +9 -5
- data/lib/traktr/user.rb +20 -16
- data/lib/traktr/user/calendar.rb +2 -2
- data/lib/traktr/user/library/movies.rb +6 -6
- data/lib/traktr/user/library/shows.rb +6 -6
- data/lib/traktr/user/network.rb +6 -6
- data/lib/traktr/user/progress.rb +4 -4
- data/lib/traktr/user/ratings.rb +6 -6
- data/lib/traktr/user/watchlist.rb +6 -6
- data/lib/traktr/version.rb +1 -1
- data/spec/account_spec.rb +9 -27
- data/spec/movie_spec.rb +38 -66
- data/spec/movies_spec.rb +9 -11
- data/spec/search_spec.rb +15 -20
- data/spec/show_episode_spec.rb +35 -63
- data/spec/show_season_spec.rb +11 -35
- data/spec/show_spec.rb +47 -76
- data/spec/shows_spec.rb +9 -11
- data/traktr.gemspec +2 -2
- metadata +6 -5
- data/lib/traktr/authentication.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff5530ddf41945252c0fd25a646fa99d0447862b
|
4
|
+
data.tar.gz: 192df29f7c2dfd344b5e2d3928344a372231dc88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cc91fad8010a43a44f6e8656d69dc9147d6721745e262b2d7da4a83cda02d6ed1ee2ec40fba6d2e0e2ef713a9a185912646b4eecc078419ef45067eb8fcbf62
|
7
|
+
data.tar.gz: d48a37bedb5f961f732081c1e057bdf8757f1ad14878dab9cedb9441d9050bdcfe94914acbbcead48d2b6c54f86f13474d59c7134371e128aaade0aac7406253
|
data/README.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Traktr
|
2
2
|
|
3
|
-
|
3
|
+
Traktr is a ruby client API for the trakt.tv RESTful web service. Trakt allows users to:
|
4
|
+
|
5
|
+
1. Automatically track what you're watching
|
6
|
+
2. Track your progress and see what's on tonight
|
7
|
+
3. Catalog your entire media collection
|
8
|
+
4. Submit ratings and reviews, follow other members, and make friends
|
9
|
+
5. Share to your social networks in real time
|
10
|
+
6. Discover new shows and movies
|
11
|
+
7. Organize lists of your favorite shows and movies to make sure you don't forget them
|
12
|
+
|
13
|
+
This client API supports all non-DEV REST methods. (If you need the DEV methods, submit a pull request!)
|
14
|
+
|
15
|
+
The full API documentation can be found at http://trakt.tv/api-docs
|
4
16
|
|
5
17
|
## Installation
|
6
18
|
|
@@ -18,7 +30,29 @@ Or install it yourself as:
|
|
18
30
|
|
19
31
|
## Usage
|
20
32
|
|
21
|
-
|
33
|
+
To interface with the Trakt API, you must create a client instance
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
API_KEY = "abcdefghijklmnopqrstuvwxyz"
|
37
|
+
USERNAME = "john_doe"
|
38
|
+
PASSWORD = "p@ssw0rd"
|
39
|
+
SHA1_PASSWORD = "57b2ad99044d337197c0c39fd3823568ff81e48a"
|
40
|
+
|
41
|
+
# for non-authenticated methods, you can create an instance without supplying
|
42
|
+
# username and password
|
43
|
+
trakt = Traktr::Client.new(API_KEY)
|
44
|
+
|
45
|
+
# if you need to use an authenticated method, you can provide your plaintext
|
46
|
+
# password
|
47
|
+
trakt = Traktr::Client.new(API_KEY, USERNAME, PASSWORD)
|
48
|
+
|
49
|
+
# or the SHA1 hash of your password
|
50
|
+
trakt = Traktr::Client.new(API_KEY, USERNAME, SHA1_PASSWORD, true)
|
51
|
+
```
|
52
|
+
|
53
|
+
From there, just string together method calls that match the Trakt API endpoints!
|
54
|
+
It's that easy (aka, I need to add more documentation here). See the RSpec tests
|
55
|
+
for examples of all of the supported methods.
|
22
56
|
|
23
57
|
## Contributing
|
24
58
|
|
data/lib/traktr.rb
CHANGED
@@ -1,20 +1,11 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
require 'mash'
|
3
2
|
require 'json'
|
4
|
-
require '
|
3
|
+
require 'mash'
|
5
4
|
|
6
5
|
module Traktr
|
7
6
|
include HTTParty
|
8
7
|
base_uri "http://api.trakt.tv"
|
9
8
|
end
|
10
9
|
|
11
|
-
require 'traktr/authentication'
|
12
|
-
require 'traktr/version'
|
13
10
|
|
14
|
-
require 'traktr/
|
15
|
-
require 'traktr/movie'
|
16
|
-
require 'traktr/movies'
|
17
|
-
require 'traktr/search'
|
18
|
-
require 'traktr/show'
|
19
|
-
require 'traktr/shows'
|
20
|
-
require 'traktr/user'
|
11
|
+
require 'traktr/client'
|
data/lib/traktr/account.rb
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
module Traktr
|
2
|
-
|
2
|
+
class Account
|
3
3
|
include HTTParty
|
4
4
|
base_uri File.join(Traktr.base_uri, "account")
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def settings
|
11
|
+
data = { username: @client.username, password: @client.password }
|
12
|
+
response = self.class.post("/" + File.join("settings", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
9
13
|
raise ResponseError.new(response) if response.code != 200
|
10
14
|
|
11
15
|
Mash.new(response.parsed_response)
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
15
|
-
data = { username:
|
16
|
-
response = self.post("/" + File.join("test",
|
18
|
+
def test
|
19
|
+
data = { username: @client.username, password: @client.password }
|
20
|
+
response = self.class.post("/" + File.join("test", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
17
21
|
raise ResponseError.new(response) if response.code != 200
|
18
22
|
|
19
23
|
Mash.new(response.parsed_response)
|
20
24
|
end
|
21
|
-
|
22
25
|
end
|
23
26
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
require 'traktr/account'
|
4
|
+
require 'traktr/movie'
|
5
|
+
require 'traktr/movies'
|
6
|
+
require 'traktr/search'
|
7
|
+
require 'traktr/show'
|
8
|
+
require 'traktr/show/episode'
|
9
|
+
require 'traktr/show/season'
|
10
|
+
require 'traktr/shows'
|
11
|
+
require 'traktr/user'
|
12
|
+
require 'traktr/version'
|
13
|
+
|
14
|
+
|
15
|
+
module Traktr
|
16
|
+
class Client
|
17
|
+
attr_reader :api_key, :username, :password
|
18
|
+
|
19
|
+
def initialize(api_key, username = nil, password = nil, sha1 = false)
|
20
|
+
@api_key = api_key || ""
|
21
|
+
@username = username || ""
|
22
|
+
@password = password ? (sha1 ? password : Digest::SHA1.hexdigest(password)) : ""
|
23
|
+
end
|
24
|
+
|
25
|
+
def account
|
26
|
+
@account ||= Traktr::Account.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def movie
|
30
|
+
@movie ||= Traktr::Movie.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def movies
|
34
|
+
@movies ||= Traktr::Movies.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def search
|
38
|
+
@search ||= Traktr::Search.new(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def show
|
42
|
+
@show ||= Traktr::Show.new(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def shows
|
46
|
+
@shows ||= Traktr::Shows.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def user
|
50
|
+
@user ||= Traktr::User.new(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def version
|
54
|
+
@version ||= Traktr::Version.new(self)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/traktr/movie.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Traktr
|
2
|
-
|
2
|
+
class Movie
|
3
3
|
include HTTParty
|
4
4
|
base_uri File.join(Traktr.base_uri, 'movie')
|
5
5
|
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
6
10
|
##
|
7
11
|
## movie GET methods
|
8
12
|
##
|
9
|
-
def
|
10
|
-
response = self.get('/' + File.join('comments.json',
|
13
|
+
def comments(title, type = :all)
|
14
|
+
response = self.class.get('/' + File.join('comments.json', @client.api_key, title, type.to_s))
|
11
15
|
raise ResponseError.new(response) if response.code != 200
|
12
16
|
|
13
17
|
response.parsed_response.collect do |comment|
|
@@ -15,8 +19,8 @@ module Traktr
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
response = self.get('/' + File.join('related.json',
|
22
|
+
def related(title, hidewatched = false)
|
23
|
+
response = self.class.get('/' + File.join('related.json', @client.api_key, title, hidewatched.to_s))
|
20
24
|
raise ResponseError.new(response) if response.code != 200
|
21
25
|
|
22
26
|
response.parsed_response.collect do |summary|
|
@@ -24,16 +28,16 @@ module Traktr
|
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
28
|
-
response = self.get('/' + File.join('summary.json',
|
31
|
+
def summary(title, extended = :min)
|
32
|
+
response = self.class.get('/' + File.join('summary.json', @client.api_key, title.to_s, extended.to_s))
|
29
33
|
raise ResponseError.new(response) if response.code != 200
|
30
34
|
|
31
35
|
Mash.new(response.parsed_response)
|
32
36
|
end
|
33
37
|
|
34
|
-
def
|
38
|
+
def summaries(titles, extended = :min)
|
35
39
|
titles = [titles] if titles.class == String
|
36
|
-
response = self.get('/' + File.join('summaries.json',
|
40
|
+
response = self.class.get('/' + File.join('summaries.json', @client.api_key, titles.join(','), extended.to_s))
|
37
41
|
raise ResponseError.new(response) if response.code != 200
|
38
42
|
|
39
43
|
response.parsed_response.collect do |summary|
|
@@ -41,8 +45,8 @@ module Traktr
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
def
|
45
|
-
response = self.get('/' + File.join('watchingnow.json',
|
48
|
+
def watchingnow(title)
|
49
|
+
response = self.class.get('/' + File.join('watchingnow.json', @client.api_key, title))
|
46
50
|
raise ResponseError.new(response) if response.code != 200
|
47
51
|
|
48
52
|
response.parsed_response.collect do |user|
|
@@ -53,73 +57,73 @@ module Traktr
|
|
53
57
|
##
|
54
58
|
## movie POST methods
|
55
59
|
##
|
56
|
-
def
|
60
|
+
def library(movies)
|
57
61
|
movies = [ movies ] if movies.class != Array
|
58
62
|
data = {
|
59
|
-
username:
|
63
|
+
username: @client.username, password: @client.password,
|
60
64
|
movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
|
61
65
|
}
|
62
|
-
response = self.post('/' + File.join('library',
|
66
|
+
response = self.class.post('/' + File.join('library', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
63
67
|
raise ResponseError.new(response) if response.code != 200
|
64
68
|
|
65
69
|
Mash.new(JSON.parse(response.parsed_response))
|
66
70
|
end
|
67
71
|
|
68
|
-
def
|
72
|
+
def unlibrary(movies)
|
69
73
|
movies = [ movies ] if movies.class != Array
|
70
74
|
data = {
|
71
|
-
username:
|
75
|
+
username: @client.username, password: @client.password,
|
72
76
|
movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
|
73
77
|
}
|
74
|
-
response = self.post('/' + File.join('unlibrary',
|
78
|
+
response = self.class.post('/' + File.join('unlibrary', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
75
79
|
raise ResponseError.new(response) if response.code != 200
|
76
80
|
|
77
81
|
Mash.new(response.parsed_response)
|
78
82
|
end
|
79
83
|
|
80
|
-
def
|
84
|
+
def watchlist(movies)
|
81
85
|
movies = [ movies ] if movies.class != Array
|
82
86
|
data = {
|
83
|
-
username:
|
87
|
+
username: @client.username, password: @client.password,
|
84
88
|
movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
|
85
89
|
}
|
86
|
-
response = self.post('/' + File.join('watchlist',
|
90
|
+
response = self.class.post('/' + File.join('watchlist', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
87
91
|
raise ResponseError.new(response) if response.code != 200
|
88
92
|
|
89
93
|
Mash.new(JSON.parse(response.parsed_response))
|
90
94
|
end
|
91
95
|
|
92
|
-
def
|
96
|
+
def unwatchlist(movies)
|
93
97
|
movies = [ movies ] if movies.class != Array
|
94
98
|
data = {
|
95
|
-
username:
|
99
|
+
username: @client.username, password: @client.password,
|
96
100
|
movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
|
97
101
|
}
|
98
|
-
response = self.post('/' + File.join('unwatchlist',
|
102
|
+
response = self.class.post('/' + File.join('unwatchlist', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
99
103
|
raise ResponseError.new(response) if response.code != 200
|
100
104
|
|
101
105
|
Mash.new(response.parsed_response)
|
102
106
|
end
|
103
107
|
|
104
|
-
def
|
108
|
+
def seen(movies)
|
105
109
|
movies = [ movies ] if movies.class != Array
|
106
110
|
data = {
|
107
|
-
username:
|
111
|
+
username: @client.username, password: @client.password,
|
108
112
|
movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
|
109
113
|
}
|
110
|
-
response = self.post('/' + File.join('seen',
|
114
|
+
response = self.class.post('/' + File.join('seen', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
111
115
|
raise ResponseError.new(response) if response.code != 200
|
112
116
|
|
113
117
|
Mash.new(JSON.parse(response.parsed_response))
|
114
118
|
end
|
115
119
|
|
116
|
-
def
|
120
|
+
def unseen(movies)
|
117
121
|
movies = [ movies ] if movies.class != Array
|
118
122
|
data = {
|
119
|
-
username:
|
123
|
+
username: @client.username, password: @client.password,
|
120
124
|
movies: movies.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tmdb_id: s.tmdb_id }}
|
121
125
|
}
|
122
|
-
response = self.post('/' + File.join('unseen',
|
126
|
+
response = self.class.post('/' + File.join('unseen', @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
123
127
|
raise ResponseError.new(response) if response.code != 200
|
124
128
|
|
125
129
|
Mash.new(response.parsed_response)
|
data/lib/traktr/movies.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Traktr
|
2
|
-
|
2
|
+
class Movies
|
3
3
|
include HTTParty
|
4
4
|
base_uri File.join(Traktr.base_uri, 'movies')
|
5
5
|
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
6
10
|
##
|
7
11
|
## movies GET methods
|
8
12
|
##
|
9
|
-
def
|
10
|
-
response = self.get('/' + File.join('trending.json',
|
13
|
+
def trending
|
14
|
+
response = self.class.get('/' + File.join('trending.json', @client.api_key))
|
11
15
|
raise ResponseError.new(response) if response.code != 200
|
12
16
|
|
13
17
|
response.parsed_response.collect do |movie|
|
@@ -15,8 +19,8 @@ module Traktr
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
response = self.get('/' + File.join('updated.json',
|
22
|
+
def updated(timestamp)
|
23
|
+
response = self.class.get('/' + File.join('updated.json', @client.api_key, timestamp.to_i.to_s))
|
20
24
|
raise ResponseError.new(response) if response.code != 200
|
21
25
|
|
22
26
|
Mash.new(response.parsed_response)
|
data/lib/traktr/search.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Traktr
|
2
|
-
|
2
|
+
class Search
|
3
3
|
include HTTParty
|
4
4
|
base_uri File.join(Traktr.base_uri, 'search')
|
5
5
|
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
6
10
|
##
|
7
11
|
## search GET methods
|
8
12
|
##
|
9
|
-
def
|
10
|
-
response = self.get('/' + File.join('episodes.json',
|
13
|
+
def episodes(query)
|
14
|
+
response = self.class.get('/' + File.join('episodes.json', @client.api_key, URI::encode(query)))
|
11
15
|
raise ResponseError.new(response) if response.code != 200
|
12
16
|
|
13
17
|
response.parsed_response.collect do |result|
|
@@ -15,8 +19,8 @@ module Traktr
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
response = self.get('/' + File.join('movies.json',
|
22
|
+
def movies(query)
|
23
|
+
response = self.class.get('/' + File.join('movies.json', @client.api_key, URI::encode(query)))
|
20
24
|
raise ResponseError.new(response) if response.code != 200
|
21
25
|
|
22
26
|
response.parsed_response.collect do |result|
|
@@ -24,8 +28,8 @@ module Traktr
|
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
28
|
-
response = self.get('/' + File.join('people.json',
|
31
|
+
def people(query)
|
32
|
+
response = self.class.get('/' + File.join('people.json', @client.api_key, URI::encode(query)))
|
29
33
|
raise ResponseError.new(response) if response.code != 200
|
30
34
|
|
31
35
|
response.parsed_response.collect do |result|
|
@@ -33,8 +37,8 @@ module Traktr
|
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
36
|
-
def
|
37
|
-
response = self.get('/' + File.join('shows.json',
|
40
|
+
def shows(query, limit = 30, seasons = nil)
|
41
|
+
response = self.class.get('/' + File.join('shows.json', @client.api_key, URI::encode(query), limit.to_s, seasons.to_s))
|
38
42
|
raise ResponseError.new(response) if response.code != 200
|
39
43
|
|
40
44
|
response.parsed_response.collect do |result|
|
@@ -42,8 +46,8 @@ module Traktr
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
|
-
def
|
46
|
-
response = self.get('/' + File.join('users.json',
|
49
|
+
def users(query)
|
50
|
+
response = self.class.get('/' + File.join('users.json', @client.api_key, URI::encode(query)))
|
47
51
|
raise ResponseError.new(response) if response.code != 200
|
48
52
|
|
49
53
|
response.parsed_response.collect do |result|
|
data/lib/traktr/show.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
module Traktr
|
2
|
-
|
2
|
+
class Show
|
3
3
|
include HTTParty
|
4
4
|
base_uri File.join(Traktr.base_uri, "show")
|
5
5
|
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def episode
|
11
|
+
@episode ||= Traktr::Show::Episode.new(@client)
|
12
|
+
end
|
13
|
+
|
14
|
+
def season
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
|
6
19
|
##
|
7
20
|
## show GET methods
|
8
21
|
##
|
9
|
-
def
|
10
|
-
response = self.get("/" + File.join("comments.json",
|
22
|
+
def comments(title, type = :all)
|
23
|
+
response = self.class.get("/" + File.join("comments.json", @client.api_key, title, type.to_s))
|
11
24
|
raise ResponseError.new(response) if response.code != 200
|
12
25
|
|
13
26
|
response.parsed_response.collect do |comment|
|
@@ -15,8 +28,8 @@ module Traktr
|
|
15
28
|
end
|
16
29
|
end
|
17
30
|
|
18
|
-
def
|
19
|
-
response = self.get("/" + File.join("related.json",
|
31
|
+
def related(title, hidewatched = false)
|
32
|
+
response = self.class.get("/" + File.join("related.json", @client.api_key, title, hidewatched.to_s))
|
20
33
|
raise ResponseError.new(response) if response.code != 200
|
21
34
|
|
22
35
|
response.parsed_response.collect do |summary|
|
@@ -24,17 +37,23 @@ module Traktr
|
|
24
37
|
end
|
25
38
|
end
|
26
39
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
40
|
+
def season(title = nil, season = nil)
|
41
|
+
if title && season
|
42
|
+
response = self.class.get("/" + File.join("season.json", @client.api_key, title, season.to_s))
|
43
|
+
raise ResponseError.new(response) if response.code != 200
|
44
|
+
|
45
|
+
response.parsed_response.collect do |episode|
|
46
|
+
Mash.new(episode)
|
47
|
+
end
|
48
|
+
elsif !title && !season
|
49
|
+
@season ||= Traktr::Show::Season.new(@client)
|
50
|
+
else
|
51
|
+
raise ArgumentError.new("wrong number of arguments")
|
33
52
|
end
|
34
53
|
end
|
35
54
|
|
36
|
-
def
|
37
|
-
response = self.get("/" + File.join("seasons.json",
|
55
|
+
def seasons(title)
|
56
|
+
response = self.class.get("/" + File.join("seasons.json", @client.api_key, title))
|
38
57
|
raise ResponseError.new(response) if response.code != 200
|
39
58
|
|
40
59
|
response.parsed_response.collect do |season|
|
@@ -42,16 +61,16 @@ module Traktr
|
|
42
61
|
end
|
43
62
|
end
|
44
63
|
|
45
|
-
def
|
46
|
-
response = self.get("/" + File.join("summary.json",
|
64
|
+
def summary(title, extended = :min)
|
65
|
+
response = self.class.get("/" + File.join("summary.json", @client.api_key, title, extended.to_s))
|
47
66
|
raise ResponseError.new(response) if response.code != 200
|
48
67
|
|
49
68
|
Mash.new(response.parsed_response)
|
50
69
|
end
|
51
70
|
|
52
|
-
def
|
71
|
+
def summaries(titles, extended = :min)
|
53
72
|
titles = [titles] if titles.class == String
|
54
|
-
response = self.get("/" + File.join("summaries.json",
|
73
|
+
response = self.class.get("/" + File.join("summaries.json", @client.api_key, titles.join(","), extended.to_s))
|
55
74
|
raise ResponseError.new(response) if response.code != 200
|
56
75
|
|
57
76
|
response.parsed_response.collect do |summary|
|
@@ -59,8 +78,8 @@ module Traktr
|
|
59
78
|
end
|
60
79
|
end
|
61
80
|
|
62
|
-
def
|
63
|
-
response = self.get("/" + File.join("watchingnow.json",
|
81
|
+
def watchingnow(title)
|
82
|
+
response = self.class.get("/" + File.join("watchingnow.json", @client.api_key, title))
|
64
83
|
raise ResponseError.new(response) if response.code != 200
|
65
84
|
|
66
85
|
response.parsed_response.collect do |user|
|
@@ -71,64 +90,61 @@ module Traktr
|
|
71
90
|
##
|
72
91
|
## show POST methods
|
73
92
|
##
|
74
|
-
def
|
93
|
+
def library(show)
|
75
94
|
data = {
|
76
|
-
username:
|
95
|
+
username: @client.username, password: @client.password,
|
77
96
|
title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
|
78
97
|
}
|
79
|
-
response = self.post("/" + File.join("library",
|
98
|
+
response = self.class.post("/" + File.join("library", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
80
99
|
raise ResponseError.new(response) if response.code != 200
|
81
100
|
|
82
101
|
Mash.new(response.parsed_response)
|
83
102
|
end
|
84
103
|
|
85
|
-
def
|
104
|
+
def unlibrary(show)
|
86
105
|
data = {
|
87
|
-
username:
|
106
|
+
username: @client.username, password: @client.password,
|
88
107
|
title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
|
89
108
|
}
|
90
|
-
response = self.post("/" + File.join("unlibrary",
|
109
|
+
response = self.class.post("/" + File.join("unlibrary", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
91
110
|
raise ResponseError.new(response) if response.code != 200
|
92
111
|
|
93
112
|
Mash.new(response.parsed_response)
|
94
113
|
end
|
95
114
|
|
96
|
-
def
|
115
|
+
def watchlist(shows)
|
97
116
|
shows = [ shows ] if shows.class != Array
|
98
117
|
data = {
|
99
|
-
username:
|
118
|
+
username: @client.username, password: @client.password,
|
100
119
|
shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
|
101
120
|
}
|
102
|
-
response = self.post("/" + File.join("watchlist",
|
121
|
+
response = self.class.post("/" + File.join("watchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
103
122
|
raise ResponseError.new(response) if response.code != 200
|
104
123
|
|
105
124
|
Mash.new(JSON.parse(response.parsed_response))
|
106
125
|
end
|
107
126
|
|
108
|
-
def
|
127
|
+
def unwatchlist(shows)
|
109
128
|
shows = [ shows ] if shows.class != Array
|
110
129
|
data = {
|
111
|
-
username:
|
130
|
+
username: @client.username, password: @client.password,
|
112
131
|
shows: shows.collect{ |s| { title: s.title, year: s.year, imdb_id: s.imdb_id, tvdb_id: s.tvdb_id }}
|
113
132
|
}
|
114
|
-
response = self.post("/" + File.join("unwatchlist",
|
133
|
+
response = self.class.post("/" + File.join("unwatchlist", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
115
134
|
raise ResponseError.new(response) if response.code != 200
|
116
135
|
|
117
136
|
Mash.new(response.parsed_response)
|
118
137
|
end
|
119
138
|
|
120
|
-
def
|
139
|
+
def seen(show)
|
121
140
|
data = {
|
122
|
-
username:
|
141
|
+
username: @client.username, password: @client.password,
|
123
142
|
title: show.title, year: show.year, imdb_id: show.imdb_id, tvdb_id: show.tvdb_id,
|
124
143
|
}
|
125
|
-
response = self.post("/" + File.join("seen",
|
144
|
+
response = self.class.post("/" + File.join("seen", @client.api_key), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
|
126
145
|
raise ResponseError.new(response) if response.code != 200
|
127
146
|
|
128
147
|
Mash.new(response.parsed_response)
|
129
148
|
end
|
130
149
|
end
|
131
150
|
end
|
132
|
-
|
133
|
-
require 'traktr/show/episode'
|
134
|
-
require 'traktr/show/season'
|