trakt 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +77 -0
- data/Rakefile +6 -0
- data/lib/trakt.rb +61 -0
- data/lib/trakt/account.rb +13 -0
- data/lib/trakt/activity.rb +32 -0
- data/lib/trakt/calendar.rb +11 -0
- data/lib/trakt/connection.rb +52 -0
- data/lib/trakt/friends.rb +29 -0
- data/lib/trakt/list.rb +35 -0
- data/lib/trakt/movie.rb +50 -0
- data/lib/trakt/movies.rb +8 -0
- data/lib/trakt/search.rb +25 -0
- data/lib/trakt/show.rb +35 -0
- data/lib/trakt/version.rb +3 -0
- data/spec/account_spec.rb +21 -0
- data/spec/activity_spec.rb +19 -0
- data/spec/calendar_spec.rb +25 -0
- data/spec/friends_spec.rb +18 -0
- data/spec/list_spec.rb +65 -0
- data/spec/movie_spec.rb +23 -0
- data/spec/search_spec.rb +42 -0
- data/spec/spec_helper.rb +9 -0
- data/trakt.gemspec +22 -0
- metadata +127 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Daniel Bretoi
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= Trakt
|
2
|
+
|
3
|
+
This is a Ruby API for the http://trakt.tv movie, tvshow service.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'trakt'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install trakt
|
18
|
+
|
19
|
+
== Usage
|
20
|
+
|
21
|
+
All calls return an JSON structure.
|
22
|
+
|
23
|
+
This is a typical default setup
|
24
|
+
|
25
|
+
require 'trakt'
|
26
|
+
trakt = Trakt.new
|
27
|
+
trakt.apikey = 'your_api_key'
|
28
|
+
trakt.username = 'your_username'
|
29
|
+
trakt.password = 'your_password'
|
30
|
+
|
31
|
+
|
32
|
+
=== Settings
|
33
|
+
|
34
|
+
trakt.account.settings
|
35
|
+
|
36
|
+
=== Searching
|
37
|
+
|
38
|
+
trakt.search.movies "the shawshank redemption"
|
39
|
+
trakt.search.shows "death note"
|
40
|
+
|
41
|
+
== Examples
|
42
|
+
|
43
|
+
=== Adding all your seen movies from a text file.
|
44
|
+
|
45
|
+
Adding movies from a text file is a bit hit and miss, so it's best if you
|
46
|
+
create a list to add the movies to. You'll have to make a list manually in
|
47
|
+
advance since creation isn't supported yet. The list takes a rather odd name.
|
48
|
+
The one in the exaple here was created as "From my file".
|
49
|
+
|
50
|
+
list = trakt.list.add('from-my-file');
|
51
|
+
IO.readlines(ENV['HOME']+"/misc/movies.txt").each do |movie|
|
52
|
+
result = trakt.search.movies(movie)
|
53
|
+
next unless result
|
54
|
+
movie = result.first
|
55
|
+
next unless movie
|
56
|
+
list.add_item(type: :movie, imdb_id: movie['imdb_id'])
|
57
|
+
end
|
58
|
+
|
59
|
+
=== Marking shows unseen
|
60
|
+
|
61
|
+
Example making all episodes of season 4 of winnie the pooh unseen. (You can use
|
62
|
+
Trakt::Search.shows("the new adventures of winnie the pooh").first to get the
|
63
|
+
imdb_id)
|
64
|
+
|
65
|
+
episodes = []
|
66
|
+
1.upto(11) { |n|
|
67
|
+
episodes << { "season" => 4, "episode" => n }
|
68
|
+
}
|
69
|
+
Trakt::Show.episode_unseen("imdb_id" => "tt0165052", episodes: episodes)
|
70
|
+
|
71
|
+
== Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/trakt.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "trakt/version"
|
2
|
+
require 'awesome_print'
|
3
|
+
require "json"
|
4
|
+
require "excon"
|
5
|
+
require "digest"
|
6
|
+
require "trakt/connection"
|
7
|
+
require "trakt/account"
|
8
|
+
require "trakt/list"
|
9
|
+
require "trakt/movie"
|
10
|
+
require "trakt/search"
|
11
|
+
require "trakt/activity"
|
12
|
+
require "trakt/calendar"
|
13
|
+
require "trakt/show"
|
14
|
+
require "trakt/friends"
|
15
|
+
require "trakt/movies"
|
16
|
+
require "trakt/genres"
|
17
|
+
|
18
|
+
module Trakt
|
19
|
+
class Error < RuntimeError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
module Trakt
|
23
|
+
def self.new(*a)
|
24
|
+
Trakt.new(*a)
|
25
|
+
end
|
26
|
+
class Trakt
|
27
|
+
attr_accessor :username, :password, :apikey
|
28
|
+
def initialize(args={})
|
29
|
+
@username = args[:username]
|
30
|
+
@password = args[:password]
|
31
|
+
@apikey = args[:apikey]
|
32
|
+
end
|
33
|
+
def account
|
34
|
+
@account ||= Account.new self
|
35
|
+
end
|
36
|
+
def calendar
|
37
|
+
@calendar ||= Calendar.new self
|
38
|
+
end
|
39
|
+
def friends
|
40
|
+
@calendar ||= Calendar.new self
|
41
|
+
end
|
42
|
+
def search
|
43
|
+
@search ||= Search.new self
|
44
|
+
end
|
45
|
+
def list
|
46
|
+
@list ||= List.new self
|
47
|
+
end
|
48
|
+
def movie
|
49
|
+
@movie ||= Movie.new self
|
50
|
+
end
|
51
|
+
def activity
|
52
|
+
@activity ||= Activity.new self
|
53
|
+
end
|
54
|
+
def genres
|
55
|
+
@genres ||= Genres.new self
|
56
|
+
end
|
57
|
+
def show
|
58
|
+
@show ||= Show.new self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Trakt
|
2
|
+
# Refer to the api doc on what parameters these functions take. http://trakt.tv/api-docs/activity-community
|
3
|
+
# For eaxmple, the current description for community reads:
|
4
|
+
#
|
5
|
+
# http://api.trakt.tv/activity/community.format/apikey/types/actions/start_ts/end_ts
|
6
|
+
#
|
7
|
+
# So you just do: <tt>trakt.activity.community(<types>,<actions>,<start_ts>,<end_ts>)</tt>
|
8
|
+
class Activity
|
9
|
+
include Connection
|
10
|
+
def community(*args)
|
11
|
+
get_with_args('/activity/community.json/', *args)
|
12
|
+
end
|
13
|
+
def episodes(*args)
|
14
|
+
get_with_args('/activity/episodes.json/', *args)
|
15
|
+
end
|
16
|
+
def friends(*args)
|
17
|
+
get_with_args('/activity/friends.json/', *args)
|
18
|
+
end
|
19
|
+
def movies(*args)
|
20
|
+
get_with_args('/activity/movies.json/', *args)
|
21
|
+
end
|
22
|
+
def seasons(*args)
|
23
|
+
get_with_args('/activity/seasons.json/', *args)
|
24
|
+
end
|
25
|
+
def shows(*args)
|
26
|
+
get_with_args('/activity/shows.json/', *args)
|
27
|
+
end
|
28
|
+
def user(*args)
|
29
|
+
get_with_args('/activity/user.json/', *args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Trakt
|
2
|
+
module Connection
|
3
|
+
attr_reader :trakt
|
4
|
+
def initialize(trakt)
|
5
|
+
@trakt = trakt
|
6
|
+
end
|
7
|
+
def connection
|
8
|
+
@connection ||= Excon.new("http://api.trakt.tv");
|
9
|
+
end
|
10
|
+
def require_settings(required)
|
11
|
+
required.each do |setting|
|
12
|
+
raise "Required setting #{setting} is missing." unless trakt.send(setting)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def post(path,body={})
|
16
|
+
# all posts have username/password
|
17
|
+
body.merge!({
|
18
|
+
'username' => trakt.username,
|
19
|
+
'password' => trakt.password,
|
20
|
+
})
|
21
|
+
path << '/' unless path[-1] == '/'
|
22
|
+
result = connection.post(:path => path + trakt.apikey, :body => body.to_json)
|
23
|
+
parse(result)
|
24
|
+
end
|
25
|
+
def parse(result)
|
26
|
+
parsed = JSON.parse result.body
|
27
|
+
if parsed.kind_of? Hash and parsed['status'] and parsed['status'] == 'failure'
|
28
|
+
raise Error.new(parsed['error'])
|
29
|
+
end
|
30
|
+
return parsed
|
31
|
+
end
|
32
|
+
def clean_query(query)
|
33
|
+
query.gsub(/[()]/,'').
|
34
|
+
gsub(' ','+').
|
35
|
+
gsub('&','and').
|
36
|
+
gsub('!','').
|
37
|
+
chomp
|
38
|
+
end
|
39
|
+
def get(path,query)
|
40
|
+
full_path = File.join(path,trakt.apikey, query);
|
41
|
+
full_path.gsub!(%r{/*$},'')
|
42
|
+
result = connection.get(:path => full_path)
|
43
|
+
parse(result)
|
44
|
+
end
|
45
|
+
def get_with_args(path,*args)
|
46
|
+
require_settings %w|apikey|
|
47
|
+
arg_path = *args.compact.map { |t| t.to_s}
|
48
|
+
get(path, File.join(arg_path))
|
49
|
+
end
|
50
|
+
private :get_with_args, :get, :post, :parse, :clean_query, :require, :connection
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Trakt
|
2
|
+
class Friends
|
3
|
+
include Connection
|
4
|
+
def add(username)
|
5
|
+
require_settings %w|username password apikey|
|
6
|
+
post "friends/#{__method__}/", 'friend' => username
|
7
|
+
end
|
8
|
+
def all
|
9
|
+
require_settings %w|username password apikey|
|
10
|
+
post 'friends/all/'
|
11
|
+
end
|
12
|
+
def approve(username)
|
13
|
+
require_settings %w|username password apikey|
|
14
|
+
post "friends/#{__method__}/", 'friend' => username
|
15
|
+
end
|
16
|
+
def delete(username)
|
17
|
+
require_settings %w|username password apikey|
|
18
|
+
post "friends/#{__method__}/", 'friend' => username
|
19
|
+
end
|
20
|
+
def deny
|
21
|
+
require_settings %w|username password apikey|
|
22
|
+
post "friends/#{__method__}/", 'friend' => username
|
23
|
+
end
|
24
|
+
def requests(username)
|
25
|
+
require_settings %w|username password apikey|
|
26
|
+
post 'friends/requests/'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/trakt/list.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Trakt
|
2
|
+
class List
|
3
|
+
include Connection
|
4
|
+
# TODO options should be the various options at some point
|
5
|
+
attr_accessor :slug, :add_info
|
6
|
+
def add(name,options={})
|
7
|
+
result = post 'lists/add/', options.merge(:name => name)
|
8
|
+
@slug = result['slug']
|
9
|
+
@add_info = result
|
10
|
+
return self
|
11
|
+
end
|
12
|
+
def get(slug)
|
13
|
+
@slug = slug
|
14
|
+
return self
|
15
|
+
end
|
16
|
+
def add_item(data)
|
17
|
+
add_items([data])
|
18
|
+
end
|
19
|
+
def add_items(data)
|
20
|
+
post("lists/items/add/", 'slug' => slug, 'items' => data)
|
21
|
+
end
|
22
|
+
def item_delete(data)
|
23
|
+
items_delete([data])
|
24
|
+
end
|
25
|
+
def items_delete(data)
|
26
|
+
post("lists/items/delete/", 'slug' => slug, 'items' => data)
|
27
|
+
end
|
28
|
+
def delete
|
29
|
+
post "lists/delete/", 'slug' => slug
|
30
|
+
end
|
31
|
+
def update(options)
|
32
|
+
post "lists/update/", options.merge('slug' => slug)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/trakt/movie.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Trakt
|
2
|
+
class Movie
|
3
|
+
include Connection
|
4
|
+
def cancelcheckin
|
5
|
+
post("/movie/cancelcheckin")
|
6
|
+
end
|
7
|
+
def cancelwatching
|
8
|
+
post("/movie/cancelwatching")
|
9
|
+
end
|
10
|
+
def checkin(options = {})
|
11
|
+
post("/movie/checkin", options)
|
12
|
+
end
|
13
|
+
def scrobble(options = {})
|
14
|
+
post("/movie/scrobble", options)
|
15
|
+
end
|
16
|
+
def seen(options = {})
|
17
|
+
post("/movie/seen", options)
|
18
|
+
end
|
19
|
+
def library(options = {})
|
20
|
+
post("/movie/library", options)
|
21
|
+
end
|
22
|
+
def related(*args)
|
23
|
+
get_with_args('/search/related.json/', *args)
|
24
|
+
end
|
25
|
+
def shouts(*args)
|
26
|
+
get_with_args('/search/shouts.json/', *args)
|
27
|
+
end
|
28
|
+
def summary(*args)
|
29
|
+
get_with_args('/search/summary.json/', *args)
|
30
|
+
end
|
31
|
+
def unlibrary(options = {})
|
32
|
+
post("/movie/unlibrary", options)
|
33
|
+
end
|
34
|
+
def unseen(options = {})
|
35
|
+
post("/movie/unseen", options)
|
36
|
+
end
|
37
|
+
def unwatchlist(options = {})
|
38
|
+
post("/movie/unwatchlist", options)
|
39
|
+
end
|
40
|
+
def watching(options = {})
|
41
|
+
post("/movie/watching", options)
|
42
|
+
end
|
43
|
+
def watchingnow(*args)
|
44
|
+
get_with_args('/search/watchingnow.json/', *args)
|
45
|
+
end
|
46
|
+
def watchlist(options = {})
|
47
|
+
post("/movie/watchlist", options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/trakt/movies.rb
ADDED
data/lib/trakt/search.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Trakt
|
2
|
+
class Search
|
3
|
+
include Connection
|
4
|
+
def movies(query)
|
5
|
+
require_settings %w|apikey|
|
6
|
+
get('/search/movies.json/',clean_query(query))
|
7
|
+
end
|
8
|
+
def shows(query)
|
9
|
+
require_settings %w|apikey|
|
10
|
+
get('/search/shows.json/',clean_query(query))
|
11
|
+
end
|
12
|
+
def episode(query)
|
13
|
+
require_settings %w|apikey|
|
14
|
+
get('/search/episodes.json/',clean_query(query))
|
15
|
+
end
|
16
|
+
def people(query)
|
17
|
+
require_settings %w|apikey|
|
18
|
+
get('/search/people.json/',clean_query(query))
|
19
|
+
end
|
20
|
+
def users(query)
|
21
|
+
require_settings %w|apikey|
|
22
|
+
get('/search/users.json/',clean_query(query))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/trakt/show.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Trakt
|
2
|
+
class Show
|
3
|
+
include Connection
|
4
|
+
def episode_unseen(data)
|
5
|
+
require_settings %w|username password apikey|
|
6
|
+
post('show/episode/unseen/', data)
|
7
|
+
end
|
8
|
+
def episode_seen(data)
|
9
|
+
require_settings %w|username password apikey|
|
10
|
+
post('show/episode/seen/', data)
|
11
|
+
end
|
12
|
+
def seen(data)
|
13
|
+
require_settings %w|username password apikey|
|
14
|
+
post('show/seen/', data)
|
15
|
+
end
|
16
|
+
# need to use thetvdb id here since the slug can't be used for unseen
|
17
|
+
def unseen(title)
|
18
|
+
all = seasons title
|
19
|
+
episodes_per_season = {}
|
20
|
+
episodes_to_remove = []
|
21
|
+
all.each do |season_info|
|
22
|
+
season_num = season_info['season']
|
23
|
+
next if season_num == 0 # dont need to remove specials
|
24
|
+
episodes = season_info['episodes']
|
25
|
+
1.upto(episodes) do |episode|
|
26
|
+
episodes_to_remove << { season: season_num, episode: episode }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
episode_unseen tvdb_id: title, episodes: episodes_to_remove
|
30
|
+
end
|
31
|
+
def seasons(title)
|
32
|
+
get('show/seasons.json/', title)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::Account do
|
5
|
+
let(:trakt) do
|
6
|
+
details = get_account_details
|
7
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
8
|
+
:username => details['username'],
|
9
|
+
:password => details['password']
|
10
|
+
trakt
|
11
|
+
end
|
12
|
+
it "should get account info" do
|
13
|
+
result = trakt.account.settings
|
14
|
+
result['message'].should == "All settings for #{trakt.username}"
|
15
|
+
end
|
16
|
+
it "should preform an account test" do
|
17
|
+
result = trakt.account.test
|
18
|
+
result['message'].should == "all good!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::Activity do
|
5
|
+
let(:trakt) do
|
6
|
+
details = get_account_details
|
7
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
8
|
+
:username => details['username'],
|
9
|
+
:password => details['password']
|
10
|
+
trakt
|
11
|
+
end
|
12
|
+
context "community" do
|
13
|
+
it "should get community activity" do
|
14
|
+
result = trakt.activity.community("movie","watching", (Time.now - 300).to_i)
|
15
|
+
result['activity'].count.should > 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::Calendar do
|
5
|
+
let(:trakt) do
|
6
|
+
details = get_account_details
|
7
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
8
|
+
:username => details['username'],
|
9
|
+
:password => details['password']
|
10
|
+
trakt
|
11
|
+
end
|
12
|
+
context "premieres" do
|
13
|
+
it "should get premieres" do
|
14
|
+
result = trakt.calendar.premieres(20110421, 1)
|
15
|
+
result.first['episodes'].first['show']['title'].should == "24 Hour Restaurant Battle"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
context "shows" do
|
19
|
+
it "should get shows" do
|
20
|
+
result = trakt.calendar.shows(20110416, 1)
|
21
|
+
result.first['episodes'].first['show']['title'].should == "Gosick"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::Friends do
|
5
|
+
let(:trakt) do
|
6
|
+
details = get_account_details
|
7
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
8
|
+
:username => details['username'],
|
9
|
+
:password => details['password']
|
10
|
+
trakt
|
11
|
+
end
|
12
|
+
it "add username" do
|
13
|
+
pending
|
14
|
+
result = trakt.friends.add 'snowfall'
|
15
|
+
result['message'].should == "snowfall added, pending their approval"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/list_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::List do
|
5
|
+
before do
|
6
|
+
list = trakt.list.get("testlist")
|
7
|
+
list.delete rescue nil
|
8
|
+
end
|
9
|
+
let(:trakt) do
|
10
|
+
details = get_account_details
|
11
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
12
|
+
:username => details['username'],
|
13
|
+
:password => details['password']
|
14
|
+
trakt
|
15
|
+
end
|
16
|
+
it "should add a list" do
|
17
|
+
list = trakt.list.add("test-list")
|
18
|
+
list.add_info['status'].should == 'success'
|
19
|
+
lambda { trakt.list.add("test-list") }.should raise_error("a list already exists with this name")
|
20
|
+
end
|
21
|
+
it "should get a list" do
|
22
|
+
list = trakt.list.get("testlist")
|
23
|
+
list.slug.should == 'testlist'
|
24
|
+
end
|
25
|
+
it "should add a movie" do
|
26
|
+
list = trakt.list.add("test-list")
|
27
|
+
result = list.add_item :type => :movie, :imdb_id => 'tt0098554'
|
28
|
+
result['status'].should == 'success'
|
29
|
+
result['inserted'].should == 1
|
30
|
+
end
|
31
|
+
it "should add movies" do
|
32
|
+
list = trakt.list.add("test-list")
|
33
|
+
result = list.add_items [{:type => :movie, :imdb_id => 'tt0098554'}, {:type => :movie, :imdb_id => 'tt0111161'}]
|
34
|
+
result['status'].should == 'success'
|
35
|
+
result['inserted'].should == 2
|
36
|
+
end
|
37
|
+
it "should delete list" do
|
38
|
+
list = trakt.list.add("test-list")
|
39
|
+
result = list.delete
|
40
|
+
result['status'].should == 'success'
|
41
|
+
result['message'].should == 'list and items deleted'
|
42
|
+
end
|
43
|
+
it "should delete an item" do
|
44
|
+
list = trakt.list.add("test-list")
|
45
|
+
list.add_items [{:type => :movie, :imdb_id => 'tt0098554'}, {:type => :movie, :imdb_id => 'tt0111161'}]
|
46
|
+
result = list.item_delete :type => :movie, :imdb_id => 'tt0098554'
|
47
|
+
result['status'].should == 'success'
|
48
|
+
result['message'].should == '1 items deleted'
|
49
|
+
end
|
50
|
+
it "should delete items" do
|
51
|
+
list = trakt.list.add("test-list")
|
52
|
+
list.add_items [{:type => :movie, :imdb_id => 'tt0098554'}, {:type => :movie, :imdb_id => 'tt0111161'}]
|
53
|
+
result = list.items_delete [{:type => :movie, :imdb_id => 'tt0098554'}, {:type => :movie, :imdb_id => 'tt0111161'}]
|
54
|
+
result['status'].should == 'success'
|
55
|
+
result['message'].should == '2 items deleted'
|
56
|
+
end
|
57
|
+
it "should update list" do
|
58
|
+
list = trakt.list.add("test-list", 'show_numbers' => true)
|
59
|
+
list.add_info['show_numbers'].should == true
|
60
|
+
result = list.update('show_numbers' => false)
|
61
|
+
result['status'].should == 'success'
|
62
|
+
result['show_numbers'].should == false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/movie_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::Movie do
|
5
|
+
let(:trakt) do
|
6
|
+
details = get_account_details
|
7
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
8
|
+
:username => details['username'],
|
9
|
+
:password => details['password']
|
10
|
+
trakt
|
11
|
+
end
|
12
|
+
it "should mark twelve monkeys" do
|
13
|
+
result = trakt.movie.seen movies: [{
|
14
|
+
imdb_id: "tt0114746",
|
15
|
+
title: "Twelve Monkeys",
|
16
|
+
year: 1995,
|
17
|
+
plays: 1,
|
18
|
+
last_played: 1255960578
|
19
|
+
}]
|
20
|
+
result['status'].should == 'success'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/search_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Trakt do
|
4
|
+
describe Trakt::Search do
|
5
|
+
let(:trakt) do
|
6
|
+
details = get_account_details
|
7
|
+
trakt = Trakt.new :apikey => details['apikey'],
|
8
|
+
:username => details['username'],
|
9
|
+
:password => details['password']
|
10
|
+
trakt
|
11
|
+
end
|
12
|
+
it "should find movie uncle buck" do
|
13
|
+
result = trakt.search.movies("uncle buck").first
|
14
|
+
result['title'].should == 'Uncle Buck'
|
15
|
+
result['year'].should == 1989
|
16
|
+
result['imdb_id'].should == 'tt0098554'
|
17
|
+
end
|
18
|
+
it "should find show cowboy bebop" do
|
19
|
+
result = trakt.search.shows("cowboy bebop").first
|
20
|
+
result['title'].should == 'Cowboy Bebop'
|
21
|
+
result['year'].should == 1998
|
22
|
+
result['imdb_id'].should == 'tt0213338'
|
23
|
+
end
|
24
|
+
it "should find episode Lisa the Vegetarian" do
|
25
|
+
result = trakt.search.episode("lisa the vegetarian").first
|
26
|
+
result['show']['title'].should == 'The Simpsons'
|
27
|
+
result['episode']['title'].should == 'Lisa the Vegetarian'
|
28
|
+
result['show']['year'].should == 1989
|
29
|
+
result['show']['imdb_id'].should == 'tt0096697'
|
30
|
+
end
|
31
|
+
it "should find actor Eric Bana" do
|
32
|
+
result = trakt.search.people("eric bana").first
|
33
|
+
result['name'].should == 'Eric Bana'
|
34
|
+
result['birthplace'].should == 'Melbourne, Australia'
|
35
|
+
end
|
36
|
+
it "should find user infodump" do
|
37
|
+
result = trakt.search.users("infodump").first
|
38
|
+
result['username'].should == 'infodump'
|
39
|
+
result['joined'].should == 1320907373
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/trakt.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trakt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "trakt"
|
8
|
+
gem.version = Trakt::VERSION
|
9
|
+
gem.authors = ["Daniel Bretoi"]
|
10
|
+
gem.email = ["daniel@bretoi.com"]
|
11
|
+
gem.description = %q{API for trakt.tv service}
|
12
|
+
gem.summary = %q{API for trakt.tv service}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
gem.add_development_dependency "awesome_print"
|
21
|
+
gem.add_dependency "excon"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trakt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Bretoi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: awesome_print
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: excon
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: API for trakt.tv service
|
63
|
+
email:
|
64
|
+
- daniel@bretoi.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.rdoc
|
73
|
+
- Rakefile
|
74
|
+
- lib/trakt.rb
|
75
|
+
- lib/trakt/account.rb
|
76
|
+
- lib/trakt/activity.rb
|
77
|
+
- lib/trakt/calendar.rb
|
78
|
+
- lib/trakt/connection.rb
|
79
|
+
- lib/trakt/friends.rb
|
80
|
+
- lib/trakt/list.rb
|
81
|
+
- lib/trakt/movie.rb
|
82
|
+
- lib/trakt/movies.rb
|
83
|
+
- lib/trakt/search.rb
|
84
|
+
- lib/trakt/show.rb
|
85
|
+
- lib/trakt/version.rb
|
86
|
+
- spec/account_spec.rb
|
87
|
+
- spec/activity_spec.rb
|
88
|
+
- spec/calendar_spec.rb
|
89
|
+
- spec/friends_spec.rb
|
90
|
+
- spec/list_spec.rb
|
91
|
+
- spec/movie_spec.rb
|
92
|
+
- spec/search_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- trakt.gemspec
|
95
|
+
homepage: ''
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.24
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: API for trakt.tv service
|
119
|
+
test_files:
|
120
|
+
- spec/account_spec.rb
|
121
|
+
- spec/activity_spec.rb
|
122
|
+
- spec/calendar_spec.rb
|
123
|
+
- spec/friends_spec.rb
|
124
|
+
- spec/list_spec.rb
|
125
|
+
- spec/movie_spec.rb
|
126
|
+
- spec/search_spec.rb
|
127
|
+
- spec/spec_helper.rb
|