trakt_api 0.0.2

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.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +252 -0
  7. data/Rakefile +1 -0
  8. data/lib/generators/templates/trakt_api.rb +5 -0
  9. data/lib/generators/trakt_api/install_generator.rb +12 -0
  10. data/lib/trakt_api.rb +22 -0
  11. data/lib/trakt_api/account.rb +16 -0
  12. data/lib/trakt_api/activity.rb +109 -0
  13. data/lib/trakt_api/base.rb +93 -0
  14. data/lib/trakt_api/calendar.rb +17 -0
  15. data/lib/trakt_api/client.rb +74 -0
  16. data/lib/trakt_api/comment.rb +16 -0
  17. data/lib/trakt_api/configuration.rb +7 -0
  18. data/lib/trakt_api/genres.rb +11 -0
  19. data/lib/trakt_api/lists.rb +26 -0
  20. data/lib/trakt_api/movie.rb +86 -0
  21. data/lib/trakt_api/movies.rb +11 -0
  22. data/lib/trakt_api/network.rb +26 -0
  23. data/lib/trakt_api/rate.rb +31 -0
  24. data/lib/trakt_api/recommendations.rb +21 -0
  25. data/lib/trakt_api/search.rb +26 -0
  26. data/lib/trakt_api/server.rb +6 -0
  27. data/lib/trakt_api/show.rb +152 -0
  28. data/lib/trakt_api/shows.rb +11 -0
  29. data/lib/trakt_api/user.rb +124 -0
  30. data/lib/trakt_api/version.rb +3 -0
  31. data/spec/integration_spec_helper.rb +3 -0
  32. data/spec/integrations/account_spec.rb +19 -0
  33. data/spec/integrations/calendar_spec.rb +31 -0
  34. data/spec/integrations/client_spec.rb +173 -0
  35. data/spec/integrations/genres_spec.rb +19 -0
  36. data/spec/integrations/movies_spec.rb +25 -0
  37. data/spec/integrations/network_spec.rb +37 -0
  38. data/spec/integrations/search_spec.rb +37 -0
  39. data/spec/integrations/server_spec.rb +13 -0
  40. data/spec/integrations/shows_spec.rb +25 -0
  41. data/spec/integrations/support/trakt_api.rb.example +5 -0
  42. data/spec/spec_helper.rb +43 -0
  43. data/spec/trakt_api/account_spec.rb +56 -0
  44. data/spec/trakt_api/activity_spec.rb +297 -0
  45. data/spec/trakt_api/base_spec.rb +147 -0
  46. data/spec/trakt_api/calendar_spec.rb +48 -0
  47. data/spec/trakt_api/client_spec.rb +101 -0
  48. data/spec/trakt_api/comment_spec.rb +69 -0
  49. data/spec/trakt_api/genres_spec.rb +24 -0
  50. data/spec/trakt_api/lists_spec.rb +111 -0
  51. data/spec/trakt_api/movie_spec.rb +333 -0
  52. data/spec/trakt_api/movies_spec.rb +38 -0
  53. data/spec/trakt_api/network_spec.rb +105 -0
  54. data/spec/trakt_api/rate_spec.rb +132 -0
  55. data/spec/trakt_api/recommendations_spec.rb +90 -0
  56. data/spec/trakt_api/search_spec.rb +81 -0
  57. data/spec/trakt_api/server_spec.rb +15 -0
  58. data/spec/trakt_api/show_spec.rb +588 -0
  59. data/spec/trakt_api/shows_spec.rb +38 -0
  60. data/spec/trakt_api/user_spec.rb +561 -0
  61. data/trakt_api.gemspec +29 -0
  62. metadata +232 -0
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ class ExampleClass < TraktApi::Base
4
+ end
5
+
6
+ describe TraktApi::Base do
7
+ let(:klass) { ExampleClass }
8
+ let(:model) { klass.new(TraktApi::Client.new) }
9
+
10
+ describe '.auth' do
11
+ it 'should set auth' do
12
+ model.auth
13
+
14
+ model.instance_variable_get('@auth').should == true
15
+ end
16
+ end
17
+
18
+ describe '.optionl_auth' do
19
+ it 'should call auth' do
20
+ model.should_receive(:auth)
21
+
22
+ model.optional_auth(auth: true)
23
+ end
24
+ end
25
+
26
+ describe '.store_uri' do
27
+ it 'should set uri' do
28
+ model.stub(:api_key).and_return('API_KEY')
29
+ model.store_uri('http://example.com')
30
+
31
+ model.instance_variable_get('@uri').should == 'http://example.com.json/API_KEY'
32
+ end
33
+ end
34
+
35
+ describe '.get' do
36
+ it 'should call store_uri' do
37
+ model.should_receive(:store_uri)
38
+
39
+ model.get('http://example.com')
40
+ end
41
+
42
+ it 'should set @method to get' do
43
+ model.get('http://example.com')
44
+
45
+ model.instance_variable_get('@method').should == :get
46
+ end
47
+
48
+ it 'should return self' do
49
+ model.get('http://example.com').should == model
50
+ end
51
+ end
52
+
53
+ describe '.post' do
54
+ it 'should call store_uri' do
55
+ model.should_receive(:store_uri)
56
+
57
+ model.post('http://example.com')
58
+ end
59
+
60
+ it 'should set @method to post' do
61
+ model.post('http://example.com')
62
+
63
+ model.instance_variable_get('@method').should == :post
64
+ end
65
+
66
+ it 'should return self' do
67
+ model.post('http://example.com').should == model
68
+ end
69
+ end
70
+
71
+ describe '.params' do
72
+ it 'should set @params' do
73
+ model.params(sample: true)
74
+
75
+ model.instance_variable_get('@params').should == { sample: true }
76
+ end
77
+ end
78
+
79
+ describe '.restful_params' do
80
+ it 'should return correct uri' do
81
+ model.instance_variable_set('@uri', 'URI')
82
+
83
+ model.restful_params({}, [])
84
+
85
+ model.instance_variable_get('@uri').should == 'URI/'
86
+ end
87
+ end
88
+
89
+ describe '.response' do
90
+ it 'should call get klass method' do
91
+ model.instance_variable_set('@method', :get)
92
+ klass.should_receive(:get)
93
+
94
+ model.response
95
+ end
96
+ end
97
+
98
+ describe '.request_options' do
99
+ it 'should return correct keys' do
100
+ model.request_options.keys.sort.should == [:body].sort
101
+ end
102
+ end
103
+
104
+ describe '.auth_hash' do
105
+ it 'should return correct hash' do
106
+ model = klass.new(TraktApi::Client.new(username: 'tester', password: 'qwerty'))
107
+
108
+ model.auth_hash.should == { basic_auth: { username: model.username, password: model.password.to_sha1 } }
109
+ end
110
+ end
111
+
112
+ describe '.series_uri' do
113
+ it 'should use default api_key' do
114
+ klass.new(TraktApi::Client.new(api_key: 'API_KEY')).series_uri('1234').should == 'API_KEY/series/1234/'
115
+ end
116
+ end
117
+
118
+ describe '.api_key' do
119
+ it 'should use default api_key' do
120
+ klass.new(TraktApi::Client.new).api_key.should == TraktApi::Configuration.api_key
121
+ end
122
+
123
+ it 'should set api_key' do
124
+ klass.new(TraktApi::Client.new(api_key: 'API_KEY')).api_key.should == 'API_KEY'
125
+ end
126
+ end
127
+
128
+ describe '.username' do
129
+ it 'should use default username' do
130
+ klass.new(TraktApi::Client.new).username.should == TraktApi::Configuration.username
131
+ end
132
+
133
+ it 'should set username' do
134
+ klass.new(TraktApi::Client.new(username: 'USERNAME')).username.should == 'USERNAME'
135
+ end
136
+ end
137
+
138
+ describe '.password' do
139
+ it 'should use default password' do
140
+ klass.new(TraktApi::Client.new).password.should == TraktApi::Configuration.password
141
+ end
142
+
143
+ it 'should set username' do
144
+ klass.new(TraktApi::Client.new(password: 'PASSWORD')).password.should == 'PASSWORD'
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe TraktApi::Calendar do
4
+ let(:model) { TraktApi::Calendar.new(TraktApi::Client.new) }
5
+ let(:mock_model) { SampleModel.new }
6
+
7
+ describe '.settings' do
8
+ it 'should call optional_auth' do
9
+ model.should_receive(:optional_auth).and_return(mock_model)
10
+
11
+ model.premieres(date: '20130101')
12
+ end
13
+
14
+ it 'should call get with specific params' do
15
+ model.instance_variable_set("@method", :get)
16
+ model.should_receive(:get).with('calendar/premieres').and_return(mock_model)
17
+
18
+ model.premieres(date: '20130101')
19
+ end
20
+
21
+ it 'should call restful_params' do
22
+ model.should_receive(:restful_params).and_return(mock_model)
23
+
24
+ model.premieres(date: '20130101')
25
+ end
26
+ end
27
+
28
+ describe '.shows' do
29
+ it 'should call optional_auth' do
30
+ model.should_receive(:optional_auth).and_return(mock_model)
31
+
32
+ model.shows(date: '20130101')
33
+ end
34
+
35
+ it 'should call get with specific params' do
36
+ model.instance_variable_set("@method", :get)
37
+ model.should_receive(:get).with('calendar/shows').and_return(mock_model)
38
+
39
+ model.shows(date: '20130101')
40
+ end
41
+
42
+ it 'should call restful_params' do
43
+ model.should_receive(:restful_params).and_return(mock_model)
44
+
45
+ model.shows(date: '20130101')
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe TraktApi::Client do
4
+ let(:model) { TraktApi::Client.new }
5
+
6
+ describe '.account' do
7
+ it 'should return account class' do
8
+ model.account.class.should == TraktApi::Account
9
+ end
10
+ end
11
+
12
+ describe '.activity' do
13
+ it 'should return account class' do
14
+ model.activity.class.should == TraktApi::Activity
15
+ end
16
+ end
17
+
18
+ describe '.calendar' do
19
+ it 'should return calendar class' do
20
+ model.calendar.class.should == TraktApi::Calendar
21
+ end
22
+ end
23
+
24
+ describe '.comment' do
25
+ it 'should return comment class' do
26
+ model.comment.class.should == TraktApi::Comment
27
+ end
28
+ end
29
+
30
+ describe '.genres' do
31
+ it 'should return genres class' do
32
+ model.genres.class.should == TraktApi::Genres
33
+ end
34
+ end
35
+
36
+ describe '.lists' do
37
+ it 'should return lists class' do
38
+ model.lists.class.should == TraktApi::Lists
39
+ end
40
+ end
41
+
42
+ describe '.movie' do
43
+ it 'should return movie class' do
44
+ model.movie.class.should == TraktApi::Movie
45
+ end
46
+ end
47
+
48
+ describe '.movies' do
49
+ it 'should return movies class' do
50
+ model.movies.class.should == TraktApi::Movies
51
+ end
52
+ end
53
+
54
+ describe '.network' do
55
+ it 'should return network class' do
56
+ model.network.class.should == TraktApi::Network
57
+ end
58
+ end
59
+
60
+ describe '.rate' do
61
+ it 'should return rate class' do
62
+ model.rate.class.should == TraktApi::Rate
63
+ end
64
+ end
65
+
66
+ describe '.recommendations' do
67
+ it 'should return movies class' do
68
+ model.recommendations.class.should == TraktApi::Recommendations
69
+ end
70
+ end
71
+
72
+ describe '.search' do
73
+ it 'should return search class' do
74
+ model.search.class.should == TraktApi::Search
75
+ end
76
+ end
77
+
78
+ describe '.server' do
79
+ it 'should return server class' do
80
+ model.server.class.should == TraktApi::Server
81
+ end
82
+ end
83
+
84
+ describe '.show' do
85
+ it 'should return show class' do
86
+ model.show.class.should == TraktApi::Show
87
+ end
88
+ end
89
+
90
+ describe '.shows' do
91
+ it 'should return shows class' do
92
+ model.shows.class.should == TraktApi::Shows
93
+ end
94
+ end
95
+
96
+ describe '.user' do
97
+ it 'should return user class' do
98
+ model.user.class.should == TraktApi::User
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe TraktApi::Comment do
4
+ let(:model) { TraktApi::Comment.new(TraktApi::Client.new) }
5
+ let(:mock_model) { SampleModel.new }
6
+
7
+ describe '.episode' do
8
+ it 'should call auth' do
9
+ model.should_receive(:auth).and_return(mock_model)
10
+
11
+ model.episode(sample: true)
12
+ end
13
+
14
+ it 'should call post with specific params' do
15
+ model.instance_variable_set("@method", :post)
16
+ model.should_receive(:post).with('comment/episode').and_return(mock_model)
17
+
18
+ model.episode(sample: true)
19
+ end
20
+
21
+ it 'should call params' do
22
+ model.should_receive(:params).and_return(mock_model)
23
+
24
+ model.episode(sample: true)
25
+ end
26
+ end
27
+
28
+ describe '.movie' do
29
+ it 'should call auth' do
30
+ model.should_receive(:auth).and_return(mock_model)
31
+
32
+ model.movie(sample: true)
33
+ end
34
+
35
+ it 'should call postt with specific params' do
36
+ model.instance_variable_set("@method", :post)
37
+ model.should_receive(:post).with('comment/movie').and_return(mock_model)
38
+
39
+ model.movie(sample: true)
40
+ end
41
+
42
+ it 'should call params' do
43
+ model.should_receive(:params).and_return(mock_model)
44
+
45
+ model.movie(sample: true)
46
+ end
47
+ end
48
+
49
+ describe '.show' do
50
+ it 'should call auth' do
51
+ model.should_receive(:auth).and_return(mock_model)
52
+
53
+ model.show(sample: true)
54
+ end
55
+
56
+ it 'should call post with specific params' do
57
+ model.instance_variable_set("@method", :post)
58
+ model.should_receive(:post).with('comment/show').and_return(mock_model)
59
+
60
+ model.show(sample: true)
61
+ end
62
+
63
+ it 'should call params' do
64
+ model.should_receive(:params).and_return(mock_model)
65
+
66
+ model.show(sample: true)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe TraktApi::Genres do
4
+ let(:model) { TraktApi::Genres.new(TraktApi::Client.new) }
5
+ let(:mock_model) { SampleModel.new }
6
+
7
+ describe '.movies' do
8
+ it 'should call get with specific params' do
9
+ model.instance_variable_set("@method", :get)
10
+ model.should_receive(:get).with('genres/movies').and_return(mock_model)
11
+
12
+ model.movies
13
+ end
14
+ end
15
+
16
+ describe '.shows' do
17
+ it 'should call get with specific params' do
18
+ model.instance_variable_set("@method", :get)
19
+ model.should_receive(:get).with('genres/shows').and_return(mock_model)
20
+
21
+ model.shows
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe TraktApi::Lists do
4
+ let(:model) { TraktApi::Lists.new(TraktApi::Client.new) }
5
+ let(:mock_model) { SampleModel.new }
6
+
7
+ describe '.add' do
8
+ it 'should call auth' do
9
+ model.should_receive(:auth).and_return(mock_model)
10
+
11
+ model.add(name: 'test', privacy: 'private', sample: true)
12
+ end
13
+
14
+ it 'should call post with specific params' do
15
+ model.instance_variable_set("@method", :post)
16
+ model.should_receive(:post).with('lists/add').and_return(mock_model)
17
+
18
+ model.add(name: 'test', privacy: 'private', sample: true)
19
+ end
20
+
21
+ it 'should call params' do
22
+ model.should_receive(:params).and_return(mock_model)
23
+
24
+ model.add(name: 'test', privacy: 'private', sample: true)
25
+ end
26
+ end
27
+
28
+ describe '.delete' do
29
+ it 'should call auth' do
30
+ model.should_receive(:auth).and_return(mock_model)
31
+
32
+ model.delete(slug: 'test')
33
+ end
34
+
35
+ it 'should call post with specific params' do
36
+ model.instance_variable_set("@method", :post)
37
+ model.should_receive(:post).with('lists/delete').and_return(mock_model)
38
+
39
+ model.delete(slug: 'test')
40
+ end
41
+
42
+ it 'should call params' do
43
+ model.should_receive(:params).and_return(mock_model)
44
+
45
+ model.delete(slug: 'test')
46
+ end
47
+ end
48
+
49
+ describe '.items_add' do
50
+ it 'should call auth' do
51
+ model.should_receive(:auth).and_return(mock_model)
52
+
53
+ model.items_add(slug: 'test', items: [])
54
+ end
55
+
56
+ it 'should call post with specific params' do
57
+ model.instance_variable_set("@method", :post)
58
+ model.should_receive(:post).with('lists/items/add').and_return(mock_model)
59
+
60
+ model.items_add(slug: 'test', items: [])
61
+ end
62
+
63
+ it 'should call params' do
64
+ model.should_receive(:params).and_return(mock_model)
65
+
66
+ model.items_add(slug: 'test', items: [])
67
+ end
68
+ end
69
+
70
+ describe '.items_delete' do
71
+ it 'should call auth' do
72
+ model.should_receive(:auth).and_return(mock_model)
73
+
74
+ model.items_delete(slug: 'test', items: [])
75
+ end
76
+
77
+ it 'should call post with specific params' do
78
+ model.instance_variable_set("@method", :post)
79
+ model.should_receive(:post).with('lists/items/delete').and_return(mock_model)
80
+
81
+ model.items_delete(slug: 'test', items: [])
82
+ end
83
+
84
+ it 'should call params' do
85
+ model.should_receive(:params).and_return(mock_model)
86
+
87
+ model.items_delete(slug: 'test', items: [])
88
+ end
89
+ end
90
+
91
+ describe '.update' do
92
+ it 'should call auth' do
93
+ model.should_receive(:auth).and_return(mock_model)
94
+
95
+ model.update(slug: 'test', sample: 1)
96
+ end
97
+
98
+ it 'should call post with specific params' do
99
+ model.instance_variable_set("@method", :post)
100
+ model.should_receive(:post).with('lists/update').and_return(mock_model)
101
+
102
+ model.update(slug: 'test', sample: 1)
103
+ end
104
+
105
+ it 'should call params' do
106
+ model.should_receive(:params).and_return(mock_model)
107
+
108
+ model.update(slug: 'test', sample: 1)
109
+ end
110
+ end
111
+ end