traktr 0.1.0

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.
@@ -0,0 +1,37 @@
1
+ module Traktr
2
+ module User
3
+ module Library
4
+ module Shows
5
+ include HTTParty
6
+ base_uri File.join(Traktr::User::Library.base_uri, 'shows')
7
+
8
+ def self.all(username = Traktr.username, extended = :min)
9
+ response = self.get('/' + File.join('all.json', Traktr.api_key, username, extended.to_s))
10
+ raise ResponseError.new(response) if response.code != 200
11
+
12
+ response.parsed_response.collect do |item|
13
+ Mash.new(item)
14
+ end
15
+ end
16
+
17
+ def self.collection(username = Traktr.username, extended = :min)
18
+ response = self.get('/' + File.join('collection.json', Traktr.api_key, username, extended.to_s))
19
+ raise ResponseError.new(response) if response.code != 200
20
+
21
+ response.parsed_response.collect do |item|
22
+ Mash.new(item)
23
+ end
24
+ end
25
+
26
+ def self.watched(username = Traktr.username, extended = :min)
27
+ response = self.get('/' + File.join('watched.json', Traktr.api_key, username, extended.to_s))
28
+ raise ResponseError.new(response) if response.code != 200
29
+
30
+ response.parsed_response.collect do |item|
31
+ Mash.new(item)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ module Traktr
2
+ module User
3
+ module Library
4
+ include HTTParty
5
+ base_uri File.join(Traktr::User.base_uri, 'library')
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'traktr/user/library/movies'
11
+ require 'traktr/user/library/shows'
@@ -0,0 +1,35 @@
1
+ module Traktr
2
+ module User
3
+ module Network
4
+ include HTTParty
5
+ base_uri File.join(Traktr::User.base_uri, 'network')
6
+
7
+ def self.followers(username = Traktr.username)
8
+ response = self.get('/' + File.join('followers.json', Traktr.api_key, username))
9
+ raise ResponseError.new(response) if response.code != 200
10
+
11
+ response.parsed_response.collect do |item|
12
+ Mash.new(item)
13
+ end
14
+ end
15
+
16
+ def self.following(username = Traktr.username)
17
+ response = self.get('/' + File.join('following.json', Traktr.api_key, username))
18
+ raise ResponseError.new(response) if response.code != 200
19
+
20
+ response.parsed_response.collect do |item|
21
+ Mash.new(item)
22
+ end
23
+ end
24
+
25
+ def self.friends(username = Traktr.username)
26
+ response = self.get('/' + File.join('friends.json', Traktr.api_key, username))
27
+ raise ResponseError.new(response) if response.code != 200
28
+
29
+ response.parsed_response.collect do |item|
30
+ Mash.new(item)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module Traktr
2
+ module User
3
+ module Progress
4
+ include HTTParty
5
+ base_uri File.join(Traktr::User.base_uri, 'progress')
6
+
7
+ def self.collected(username = Traktr.username, title = :all, sort = :title, extended = :min)
8
+ response = self.get('/' + File.join('collected.json', Traktr.api_key, username, title.to_s, sort.to_s, extended.to_s))
9
+ raise ResponseError.new(response) if response.code != 200
10
+
11
+ response.parsed_response.collect do |item|
12
+ Mash.new(item)
13
+ end
14
+ end
15
+
16
+ def self.watched(username = Traktr.username, title = :all, sort = :title, extended = :min)
17
+ response = self.get('/' + File.join('watched.json', Traktr.api_key, username, title.to_s, sort.to_s, extended.to_s))
18
+ raise ResponseError.new(response) if response.code != 200
19
+
20
+ response.parsed_response.collect do |item|
21
+ Mash.new(item)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ module Traktr
2
+ module User
3
+ module Ratings
4
+ include HTTParty
5
+ base_uri File.join(Traktr::User.base_uri, 'ratings')
6
+
7
+ def self.episodes(username = Traktr.username, rating = :all, extended = :min)
8
+ response = self.get('/' + File.join('episodes.json', Traktr.api_key, username, rating.to_s, extended.to_s))
9
+ raise ResponseError.new(response) if response.code != 200
10
+
11
+ response.parsed_response.collect do |item|
12
+ Mash.new(item)
13
+ end
14
+ end
15
+
16
+ def self.movies(username = Traktr.username, rating = :all, extended = :min)
17
+ response = self.get('/' + File.join('movies.json', Traktr.api_key, username, rating.to_s, extended.to_s))
18
+ raise ResponseError.new(response) if response.code != 200
19
+
20
+ response.parsed_response.collect do |item|
21
+ Mash.new(item)
22
+ end
23
+ end
24
+
25
+ def self.shows(username = Traktr.username, rating = :all, extended = :min)
26
+ response = self.get('/' + File.join('shows.json', Traktr.api_key, username, rating.to_s, extended.to_s))
27
+ raise ResponseError.new(response) if response.code != 200
28
+
29
+ response.parsed_response.collect do |item|
30
+ Mash.new(item)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Traktr
2
+ module User
3
+ module Watchlist
4
+ include HTTParty
5
+ base_uri File.join(Traktr::User.base_uri, 'watchlist')
6
+
7
+ def self.episodes(username = Traktr.username)
8
+ response = self.get('/' + File.join('episodes.json', Traktr.api_key, username))
9
+ raise ResponseError.new(response) if response.code != 200
10
+
11
+ response.parsed_response.collect do |item|
12
+ Mash.new(item)
13
+ end
14
+ end
15
+
16
+ def self.movies(username = Traktr.username)
17
+ response = self.get('/' + File.join('movies.json', Traktr.api_key, username))
18
+ raise ResponseError.new(response) if response.code != 200
19
+
20
+ response.parsed_response.collect do |item|
21
+ Mash.new(item)
22
+ end
23
+ end
24
+
25
+ def self.shows(username = Traktr.username)
26
+ response = self.get('/' + File.join('shows.json', Traktr.api_key, username))
27
+ raise ResponseError.new(response) if response.code != 200
28
+
29
+ response.parsed_response.collect do |item|
30
+ Mash.new(item)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ module Traktr
2
+ module User
3
+ include HTTParty
4
+ base_uri File.join(Traktr.base_uri, "user")
5
+
6
+ def self.lastactivity(user = Traktr.username)
7
+ response = self.get("/" + File.join("lastactivity.json", Traktr.api_key, user))
8
+ raise ResponseError.new(response) if response.code != 200
9
+
10
+ Mash.new(response.parsed_response)
11
+ end
12
+
13
+ def self.list(slug, user = Traktr.username)
14
+ response = self.get("/" + File.join("list.json", Traktr.api_key, user, slug))
15
+ raise ResponseError.new(response) if response.code != 200
16
+
17
+ Mash.new(response.parsed_response)
18
+ end
19
+
20
+ def self.lists(user = Traktr.username)
21
+ response = self.get("/" + File.join("lists.json", Traktr.api_key, user))
22
+ raise ResponseError.new(response) if response.code != 200
23
+
24
+ response.parsed_response.collect do |item|
25
+ Mash.new(item)
26
+ end
27
+ end
28
+
29
+ def self.profile(user = Traktr.username)
30
+ response = self.get("/" + File.join("profile.json", Traktr.api_key, user))
31
+ raise ResponseError.new(response) if response.code != 200
32
+
33
+ Mash.new(response.parsed_response)
34
+ end
35
+
36
+ def self.watching(user = Traktr.username)
37
+ response = self.get("/" + File.join("watching.json", Traktr.api_key, user))
38
+ raise ResponseError.new(response) if response.code != 200
39
+
40
+ response.parsed_response.collect do |item|
41
+ Mash.new(item)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ require 'traktr/user/library'
48
+ require 'traktr/user/network'
49
+ require 'traktr/user/progress'
50
+ require 'traktr/user/ratings'
51
+ require 'traktr/user/watchlist'
@@ -0,0 +1,3 @@
1
+ module Traktr
2
+ VERSION = "0.1.0"
3
+ end
data/lib/traktr.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'httparty'
2
+ require 'mash'
3
+ require 'json'
4
+ require 'uri'
5
+
6
+ module Traktr
7
+ include HTTParty
8
+ base_uri "http://api.trakt.tv"
9
+ end
10
+
11
+ require 'traktr/authentication'
12
+ require 'traktr/version'
13
+
14
+ require 'traktr/account'
15
+ require 'traktr/movie'
16
+ require 'traktr/search'
17
+ require 'traktr/show'
18
+ require 'traktr/user'
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::Account do
4
+ context 'POST methods' do
5
+ context 'with valid api_key and auth credentials' do
6
+ before :all do
7
+ Traktr.api_key = API_KEY
8
+ Traktr.username = USERNAME
9
+ Traktr.password = PASSWORD
10
+ end
11
+
12
+ after :all do
13
+ Traktr.api_key = ''
14
+ Traktr.username = ''
15
+ Traktr.password = ''
16
+ end
17
+
18
+ it '#settings' do
19
+ expect(Traktr::Account.settings.status).to eql('success')
20
+ end
21
+
22
+ it '#test' do
23
+ expect(Traktr::Account.test.status).to eql('success')
24
+ end
25
+ end
26
+
27
+ context 'without valid api_key' do
28
+ before :all do
29
+ Traktr.username = USERNAME
30
+ Traktr.password = PASSWORD
31
+ end
32
+
33
+ after :all do
34
+ Traktr.username = ''
35
+ Traktr.password = ''
36
+ end
37
+
38
+ it '#settings' do
39
+ expect { comments = Traktr::Account.settings }.to raise_error(Traktr::ResponseError)
40
+ end
41
+
42
+ it '#test' do
43
+ expect { summary = Traktr::Account.test }.to raise_error(Traktr::ResponseError)
44
+ end
45
+ end
46
+
47
+ context 'without valid auth credentials' do
48
+ before :all do
49
+ Traktr.api_key = API_KEY
50
+ end
51
+
52
+ after :all do
53
+ Traktr.api_key = ''
54
+ end
55
+
56
+ it '#settings' do
57
+ expect { comments = Traktr::Account.settings }.to raise_error(Traktr::ResponseError)
58
+ end
59
+
60
+ it '#test' do
61
+ expect { summary = Traktr::Account.test }.to raise_error(Traktr::ResponseError)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::Movie do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ Traktr.api_key = API_KEY
8
+ end
9
+
10
+ after :all do
11
+ Traktr.api_key = ''
12
+ end
13
+
14
+ it '#comments' do
15
+ comments = Traktr::Movie.comments('the-dark-knight-2008')
16
+ expect(comments.size).to be > 0
17
+ end
18
+
19
+ it '#summary' do
20
+ summary = Traktr::Movie.summary('the-dark-knight-2008')
21
+ expect(summary.imdb_id).to eql('tt0468569')
22
+ end
23
+
24
+ it '#summaries' do
25
+ summaries = Traktr::Movie.summaries(['the-dark-knight-2008', 'the-social-network-2010'])
26
+ expect(summaries.size).to eql(2)
27
+ end
28
+
29
+ it '#watchingnow' do
30
+ watchingnow = Traktr::Movie.watchingnow('the-dark-knight-2008')
31
+ expect(watchingnow.size).to be >= 0
32
+ end
33
+
34
+ it '#related' do
35
+ related = Traktr::Movie.related('the-dark-knight-2008')
36
+ expect(related.size).to eql(10)
37
+ end
38
+ end
39
+
40
+ context 'without valid api_key' do
41
+ it '#comments' do
42
+ expect { comments = Traktr::Movie.comments('the-dark-knight-2008') }.to raise_error(Traktr::ResponseError)
43
+ end
44
+
45
+ it '#summary' do
46
+ expect {Traktr::Movie.summary('the-dark-knight-2008') }.to raise_error(Traktr::ResponseError)
47
+ end
48
+
49
+ it '#summaries' do
50
+ expect { summaries = Traktr::Movie.summaries(['the-dark-knight-2008', 'the-social-network-2010']) }.to raise_error(Traktr::ResponseError)
51
+ end
52
+
53
+ it '#watchingnow' do
54
+ expect { watchingnow = Traktr::Movie.watchingnow('the-dark-knight-2008') }.to raise_error(Traktr::ResponseError)
55
+ end
56
+
57
+ it '#related' do
58
+ expect { related = Traktr::Movie.related('the-dark-knight-2008') }.to raise_error(Traktr::ResponseError)
59
+ end
60
+ end
61
+ end
62
+ context 'POST methods' do
63
+ before :all do
64
+ Traktr.api_key = API_KEY
65
+ @movie = Traktr::Movie.summary('the-dark-knight-2008')
66
+ Traktr.api_key = ''
67
+ end
68
+
69
+ after :all do
70
+ @movie = nil
71
+ end
72
+
73
+ context 'with valid api_key and auth credentials' do
74
+ before :all do
75
+ Traktr.api_key = API_KEY
76
+ Traktr.username = USERNAME
77
+ Traktr.password = PASSWORD
78
+ end
79
+
80
+ after :all do
81
+ Traktr.api_key = ''
82
+ Traktr.username = ''
83
+ Traktr.password = ''
84
+ end
85
+
86
+ it '#library' do
87
+ expect(Traktr::Movie.library(@movie).status).to eql('success')
88
+ end
89
+
90
+ it '#unlibrary' do
91
+ expect(Traktr::Movie.unlibrary(@movie).status).to eql('success')
92
+ end
93
+
94
+ it '#watchlist' do
95
+ expect(Traktr::Movie.watchlist(@movie).status).to eql('success')
96
+ end
97
+
98
+ it '#unwatchlist' do
99
+ expect(Traktr::Movie.unwatchlist(@movie).status).to eql('success')
100
+ end
101
+
102
+ it '#seen' do
103
+ expect(Traktr::Movie.seen(@movie).status).to eql('success')
104
+ end
105
+
106
+ it '#unseen' do
107
+ expect(Traktr::Movie.unseen(@movie).status).to eql('success')
108
+ end
109
+ end
110
+
111
+ context 'without valid api_key' do
112
+ before :all do
113
+ Traktr.username = USERNAME
114
+ Traktr.password = PASSWORD
115
+ end
116
+
117
+ after :all do
118
+ Traktr.username = ''
119
+ Traktr.password = ''
120
+ end
121
+
122
+ it '#library' do
123
+ expect {Traktr::Movie.library(@movie) }.to raise_error(Traktr::ResponseError)
124
+ end
125
+
126
+ it '#unlibrary' do
127
+ expect {Traktr::Movie.unlibrary(@movie) }.to raise_error(Traktr::ResponseError)
128
+ end
129
+
130
+ it '#watchlist' do
131
+ expect {Traktr::Movie.watchlist(@movie) }.to raise_error(Traktr::ResponseError)
132
+ end
133
+
134
+ it '#unwatchlist' do
135
+ expect {Traktr::Movie.unwatchlist(@movie) }.to raise_error(Traktr::ResponseError)
136
+ end
137
+
138
+ it '#seen' do
139
+ expect {Traktr::Movie.seen(@movie) }.to raise_error(Traktr::ResponseError)
140
+ end
141
+
142
+ it '#unseen' do
143
+ expect {Traktr::Movie.unseen(@movie) }.to raise_error(Traktr::ResponseError)
144
+ end
145
+ end
146
+
147
+ context 'without valid auth credentials' do
148
+ before :all do
149
+ Traktr.api_key = API_KEY
150
+ end
151
+
152
+ after :all do
153
+ Traktr.api_key = ''
154
+ end
155
+
156
+ it '#library' do
157
+ expect {Traktr::Movie.library(@movie) }.to raise_error(Traktr::ResponseError)
158
+ end
159
+
160
+ it '#unlibrary' do
161
+ expect {Traktr::Movie.unlibrary(@movie) }.to raise_error(Traktr::ResponseError)
162
+ end
163
+
164
+ it '#watchlist' do
165
+ expect {Traktr::Movie.watchlist(@movie) }.to raise_error(Traktr::ResponseError)
166
+ end
167
+
168
+ it '#unwatchlist' do
169
+ expect {Traktr::Movie.unwatchlist(@movie) }.to raise_error(Traktr::ResponseError)
170
+ end
171
+
172
+ it '#seen' do
173
+ expect {Traktr::Movie.seen(@movie) }.to raise_error(Traktr::ResponseError)
174
+ end
175
+
176
+ it '#unseen' do
177
+ expect {Traktr::Movie.unseen(@movie) }.to raise_error(Traktr::ResponseError)
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Traktr::Search do
4
+ context 'GET methods' do
5
+ context 'with valid api_key' do
6
+ before :all do
7
+ Traktr.api_key = API_KEY
8
+ end
9
+
10
+ after :all do
11
+ Traktr.api_key = ''
12
+ end
13
+
14
+ it '#episodes' do
15
+ results = Traktr::Search.episodes('warfare')
16
+ expect(results.size).to eql(30)
17
+ end
18
+
19
+ it '#movies' do
20
+ results = Traktr::Search.movies('Batman')
21
+ expect(results.size).to eql(29)
22
+ end
23
+
24
+ it '#people' do
25
+ results = Traktr::Search.people('christian bale')
26
+ expect(results.size).to eql(30)
27
+ end
28
+
29
+ it '#shows' do
30
+ results = Traktr::Search.shows('big bang theory')
31
+ expect(results.size).to eql(29)
32
+ end
33
+
34
+ it '#users' do
35
+ results = Traktr::Search.users('justin')
36
+ expect(results.size).to eql(22)
37
+ end
38
+ end
39
+
40
+ context 'without valid api_key' do
41
+ it '#episodes' do
42
+ expect { Traktr::Search.episodes('warfare') }.to raise_error(Traktr::ResponseError)
43
+ end
44
+
45
+ it '#movies' do
46
+ expect { Traktr::Search.movies('Batman') }.to raise_error(Traktr::ResponseError)
47
+ end
48
+
49
+ it '#people' do
50
+ expect { Traktr::Search.people('christian bale') }.to raise_error(Traktr::ResponseError)
51
+ end
52
+
53
+ it '#shows' do
54
+ expect { Traktr::Search.shows('big bang theory') }.to raise_error(Traktr::ResponseError)
55
+ end
56
+
57
+ it '#users' do
58
+ expect { Traktr::Search.users('justin') }.to raise_error(Traktr::ResponseError)
59
+ end
60
+ end
61
+ end
62
+ end