enceladus 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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/enceladus.gemspec +29 -0
- data/lib/enceladus/configuration/api.rb +60 -0
- data/lib/enceladus/configuration/image.rb +83 -0
- data/lib/enceladus/exceptions.rb +5 -0
- data/lib/enceladus/models/account.rb +143 -0
- data/lib/enceladus/models/api_paginated_collection.rb +76 -0
- data/lib/enceladus/models/api_resource.rb +25 -0
- data/lib/enceladus/models/cast.rb +9 -0
- data/lib/enceladus/models/genre.rb +4 -0
- data/lib/enceladus/models/guest_account.rb +15 -0
- data/lib/enceladus/models/movie.rb +162 -0
- data/lib/enceladus/models/movie_collection.rb +3 -0
- data/lib/enceladus/models/production_company.rb +4 -0
- data/lib/enceladus/models/production_country.rb +4 -0
- data/lib/enceladus/models/release.rb +4 -0
- data/lib/enceladus/models/spoken_language.rb +4 -0
- data/lib/enceladus/models/you_tube_trailer.rb +9 -0
- data/lib/enceladus/requester.rb +68 -0
- data/lib/enceladus/version.rb +3 -0
- data/lib/enceladus.rb +43 -0
- data/spec/enceladus/configuration/api_spec.rb +59 -0
- data/spec/enceladus/configuration/image_spec.rb +200 -0
- data/spec/enceladus/enceladus_spec.rb +53 -0
- data/spec/enceladus/models/account_spec.rb +176 -0
- data/spec/enceladus/models/cast_spec.rb +18 -0
- data/spec/enceladus/models/guest_account_spec.rb +19 -0
- data/spec/enceladus/models/movie_collection_spec.rb +217 -0
- data/spec/enceladus/models/movie_spec.rb +469 -0
- data/spec/enceladus/models/you_tube_trailer_spec.rb +16 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/responses/account_response.rb +27 -0
- data/spec/support/responses/authentication_response.rb +19 -0
- data/spec/support/responses/configuration_response.rb +32 -0
- data/spec/support/responses/credits_collection_response.rb +19 -0
- data/spec/support/responses/credits_response.rb +29 -0
- data/spec/support/responses/error_response.rb +12 -0
- data/spec/support/responses/guest_account_response.rb +21 -0
- data/spec/support/responses/movie_collection_resource_response.rb +36 -0
- data/spec/support/responses/movie_collection_response.rb +20 -0
- data/spec/support/responses/movie_response.rb +67 -0
- data/spec/support/responses/request_token_response.rb +21 -0
- data/spec/support/responses/session_response.rb +19 -0
- metadata +239 -0
@@ -0,0 +1,469 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enceladus::Movie do
|
4
|
+
|
5
|
+
describe "#find" do
|
6
|
+
subject(:movie) { Enceladus::Movie.find(id) }
|
7
|
+
let(:id) { 777 }
|
8
|
+
let(:movie_response) { MovieResponse.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
stub_request(:get, /api.themoviedb.org\/3\/movie\/777/).
|
12
|
+
to_return(status: 200, body: movie_response.to_json)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set the attribute adult" do
|
16
|
+
expect(movie.adult).to eq(movie_response.adult)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should set the attribute adult" do
|
20
|
+
expect(movie.adult).to eq(movie_response.adult)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set the attribute backdrop_path" do
|
24
|
+
expect(movie.backdrop_path).to eq(movie_response.backdrop_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set the attribute belongs_to_collection" do
|
28
|
+
expect(movie.belongs_to_collection).to eq(movie_response.belongs_to_collection)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set the attribute budget" do
|
32
|
+
expect(movie.budget).to eq(movie_response.budget)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set the attribute homepage" do
|
36
|
+
expect(movie.homepage).to eq(movie_response.homepage)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set the attribute id" do
|
40
|
+
expect(movie.id).to eq(movie_response.id)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should set the attribute imdb_id" do
|
44
|
+
expect(movie.imdb_id).to eq(movie_response.imdb_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the attribute original_title" do
|
48
|
+
expect(movie.original_title).to eq(movie_response.original_title)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set the attribute overview" do
|
52
|
+
expect(movie.overview).to eq(movie_response.overview)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should set the attribute popularity" do
|
56
|
+
expect(movie.popularity).to eq(movie_response.popularity)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set the attribute poster_path" do
|
60
|
+
expect(movie.poster_path).to eq(movie_response.poster_path)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set the attribute release_date" do
|
64
|
+
expect(movie.release_date).to eq(movie_response.release_date)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set the attribute revenue" do
|
68
|
+
expect(movie.revenue).to eq(movie_response.revenue)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should set the attribute runtime" do
|
72
|
+
expect(movie.runtime).to eq(movie_response.runtime)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should set the attribute status" do
|
76
|
+
expect(movie.status).to eq(movie_response.status)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should set the attribute tagline" do
|
80
|
+
expect(movie.tagline).to eq(movie_response.tagline)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set the attribute title" do
|
84
|
+
expect(movie.title).to eq(movie_response.title)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should set the attribute vote_average" do
|
88
|
+
expect(movie.vote_average).to eq(movie_response.vote_average)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should set the attribute vote_count" do
|
92
|
+
expect(movie.vote_count).to eq(movie_response.vote_count)
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#genres" do
|
96
|
+
subject { movie.genres }
|
97
|
+
let(:genre) { movie.genres.first }
|
98
|
+
let(:genre_from_response) { movie_response.genres.first }
|
99
|
+
|
100
|
+
it { is_expected.to be_kind_of Array }
|
101
|
+
|
102
|
+
it "should set the attribute id" do
|
103
|
+
expect(genre.id).to eq(genre_from_response[:id])
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should set the attribute name" do
|
107
|
+
expect(genre.name).to eq(genre_from_response[:name])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#production_companies" do
|
112
|
+
subject { movie.production_companies }
|
113
|
+
let(:production_company) { movie.production_companies.first }
|
114
|
+
let(:production_company_from_response) { movie_response.production_companies.first }
|
115
|
+
|
116
|
+
it { is_expected.to be_kind_of Array }
|
117
|
+
|
118
|
+
it "should set the attribute id" do
|
119
|
+
expect(production_company.id).to eq(production_company_from_response[:id])
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should set the attribute name" do
|
123
|
+
expect(production_company.name).to eq(production_company_from_response[:name])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#production_countries" do
|
128
|
+
subject { movie.production_countries }
|
129
|
+
let(:production_country) { movie.production_countries.first }
|
130
|
+
let(:production_country_from_response) { movie_response.production_countries.first }
|
131
|
+
|
132
|
+
it { is_expected.to be_kind_of Array }
|
133
|
+
|
134
|
+
it "should set the attribute iso_3166_1" do
|
135
|
+
expect(production_country.iso_3166_1).to eq(production_country_from_response[:iso_3166_1])
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should set the attribute name" do
|
139
|
+
expect(production_country.name).to eq(production_country_from_response[:name])
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#spoken_languages" do
|
144
|
+
subject { movie.spoken_languages }
|
145
|
+
let(:spoken_language) { movie.spoken_languages.first }
|
146
|
+
let(:spoken_language_from_response) { movie_response.spoken_languages.first }
|
147
|
+
|
148
|
+
it { is_expected.to be_kind_of Array }
|
149
|
+
|
150
|
+
it "should set the attribute iso_639_1" do
|
151
|
+
expect(spoken_language.iso_639_1).to eq(spoken_language_from_response[:iso_639_1])
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should set the attribute name" do
|
155
|
+
expect(spoken_language.name).to eq(spoken_language_from_response[:name])
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#releases" do
|
160
|
+
subject { movie.releases }
|
161
|
+
let(:release) { movie.releases.first }
|
162
|
+
let(:release_from_response) { movie_response.releases[:countries].first }
|
163
|
+
|
164
|
+
it { is_expected.to be_kind_of Array }
|
165
|
+
|
166
|
+
it "should set the attribute iso_3166_1" do
|
167
|
+
expect(release.iso_3166_1).to eq(release_from_response[:iso_3166_1])
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should set the attribute certification" do
|
171
|
+
expect(release.certification).to eq(release_from_response[:certification])
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should set the attribute release_date" do
|
175
|
+
expect(release.release_date).to eq(release_from_response[:release_date])
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "#youtube_trailers" do
|
180
|
+
subject { movie.youtube_trailers }
|
181
|
+
let(:youtube_trailer) { movie.youtube_trailers.first }
|
182
|
+
let(:youtube_trailer_from_response) { movie_response.trailers[:youtube].first }
|
183
|
+
|
184
|
+
it { is_expected.to be_kind_of Array }
|
185
|
+
|
186
|
+
it "should set the attribute name" do
|
187
|
+
expect(youtube_trailer.name).to eq(youtube_trailer_from_response[:name])
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should set the attribute size" do
|
191
|
+
expect(youtube_trailer.size).to eq(youtube_trailer_from_response[:size])
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should set the attribute source" do
|
195
|
+
expect(youtube_trailer.source).to eq(youtube_trailer_from_response[:source])
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should set the attribute type" do
|
199
|
+
expect(youtube_trailer.type).to eq(youtube_trailer_from_response[:type])
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
[:upcoming, :now_playing, :popular, :top_rated].each do |endpoint|
|
205
|
+
describe ".#{endpoint}" do
|
206
|
+
subject(:movies) { Enceladus::Movie.send(endpoint) }
|
207
|
+
let(:response) { MovieCollectionResponse.new }
|
208
|
+
|
209
|
+
before do
|
210
|
+
stub_request(:get, /api.themoviedb.org\/3\/movie\/#{endpoint}/).to_return(status: 200, body: response.to_json)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should return a Enceladus::MovieCollection" do
|
214
|
+
is_expected.to be_kind_of(Enceladus::MovieCollection)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should fetch #{endpoint} movies" do
|
218
|
+
movie = response.results.first
|
219
|
+
expect(movies.all.map(&:id)).to include movie.id
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "#similar" do
|
225
|
+
subject(:movies) { movie.similar }
|
226
|
+
let(:response) { MovieCollectionResponse.new }
|
227
|
+
let(:movie) { Enceladus::Movie.new }
|
228
|
+
|
229
|
+
before do
|
230
|
+
movie.id = 123
|
231
|
+
stub_request(:get, /api.themoviedb.org\/3\/movie\/#{movie.id}\/similar/).to_return(status: 200, body: response.to_json)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should return a Enceladus::MovieCollection" do
|
235
|
+
is_expected.to be_kind_of(Enceladus::MovieCollection)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should fetch similar movies" do
|
239
|
+
movie = response.results.first
|
240
|
+
expect(movies.all.map(&:id)).to include response.results.first.id
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe ".find_by_title" do
|
245
|
+
subject(:movies) { Enceladus::Movie.find_by_title(title) }
|
246
|
+
let(:response) { MovieCollectionResponse.new }
|
247
|
+
let(:title) { "Banana" }
|
248
|
+
|
249
|
+
before do
|
250
|
+
stub_request(:get, "https://api.themoviedb.org/3/search/movie?api_key=token&page=1&query=#{title}")
|
251
|
+
.to_return(status: 200, body: response.to_json)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should return a Enceladus::MovieCollection" do
|
255
|
+
is_expected.to be_kind_of(Enceladus::MovieCollection)
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should fetch movies by title" do
|
259
|
+
movie = response.results.first
|
260
|
+
expect(movies.all.map(&:id)).to include movie.id
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "#reload" do
|
265
|
+
subject(:reload) { movie.reload }
|
266
|
+
|
267
|
+
let(:movie) { Enceladus::Movie.new }
|
268
|
+
let(:movie_id) { 1234 }
|
269
|
+
let(:response) { MovieResponse.new }
|
270
|
+
|
271
|
+
before do
|
272
|
+
movie.id = movie_id
|
273
|
+
stub_request(:get, /api.themoviedb.org\/3\/movie\/#{movie_id}/)
|
274
|
+
.to_return(status: 200, body: response.to_json)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should return a Enceladus::Movie" do
|
278
|
+
is_expected.to be_kind_of(Enceladus::Movie)
|
279
|
+
end
|
280
|
+
|
281
|
+
[:adult, :backdrop_path, :belongs_to_collection, :budget, :homepage, :id, :imdb_id, :original_title, :overview, :popularity,
|
282
|
+
:poster_path, :release_date, :revenue, :runtime, :status, :tagline, :title, :vote_average, :vote_count].each do |attr|
|
283
|
+
|
284
|
+
it "should fetch the movie##{attr}" do
|
285
|
+
reload
|
286
|
+
expect(movie.send(attr)).to eq(response.send(attr))
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should fetch movie genres" do
|
291
|
+
reload
|
292
|
+
genre = movie.genres.first
|
293
|
+
genre_from_response = response.genres.first
|
294
|
+
|
295
|
+
expect(genre.id).to eq(genre_from_response[:id])
|
296
|
+
expect(genre.name).to eq(genre_from_response[:name])
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should fetch movie production companies" do
|
300
|
+
reload
|
301
|
+
production_company = movie.production_companies.first
|
302
|
+
production_company_from_response = response.production_companies.first
|
303
|
+
|
304
|
+
expect(production_company.id).to eq(production_company_from_response[:id])
|
305
|
+
expect(production_company.name).to eq(production_company_from_response[:name])
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should fetch movie production countries" do
|
309
|
+
reload
|
310
|
+
production_country = movie.production_countries.first
|
311
|
+
production_country_from_response = response.production_countries.first
|
312
|
+
|
313
|
+
expect(production_country.iso_3166_1).to eq(production_country_from_response[:iso_3166_1])
|
314
|
+
expect(production_country.name).to eq(production_country_from_response[:name])
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should fetch movie spoken languages" do
|
318
|
+
reload
|
319
|
+
spoken_language = movie.spoken_languages.first
|
320
|
+
spoken_language_from_response = response.spoken_languages.first
|
321
|
+
|
322
|
+
expect(spoken_language.iso_639_1).to eq(spoken_language_from_response[:iso_639_1])
|
323
|
+
expect(spoken_language.name).to eq(spoken_language_from_response[:name])
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should fetch movie releases" do
|
327
|
+
reload
|
328
|
+
release = movie.releases.first
|
329
|
+
release_from_response = response.releases[:countries].first
|
330
|
+
|
331
|
+
expect(release.iso_3166_1).to eq(release_from_response[:iso_3166_1])
|
332
|
+
expect(release.certification).to eq(release_from_response[:certification])
|
333
|
+
expect(release.release_date).to eq(release_from_response[:release_date])
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should fetch movie trailers" do
|
337
|
+
reload
|
338
|
+
trailer = movie.youtube_trailers.first
|
339
|
+
trailer_from_response = response.trailers[:youtube].first
|
340
|
+
|
341
|
+
expect(trailer.name).to eq(trailer_from_response[:name])
|
342
|
+
expect(trailer.size).to eq(trailer_from_response[:size])
|
343
|
+
expect(trailer.source).to eq(trailer_from_response[:source])
|
344
|
+
expect(trailer.type).to eq(trailer_from_response[:type])
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
describe "#rate!" do
|
349
|
+
subject(:make_request) { movie.rate!(account, rating) }
|
350
|
+
let(:movie) { Enceladus::Movie.new }
|
351
|
+
let(:rating) { 7.3 }
|
352
|
+
|
353
|
+
before { movie.id = 111 }
|
354
|
+
|
355
|
+
context "when rating with permanent account" do
|
356
|
+
let(:account) { Enceladus::Account.new(username, password) }
|
357
|
+
let(:request_token_response) { RequestTokenResponse.new }
|
358
|
+
let(:authentication_response) { AuthenticationResponse.new }
|
359
|
+
let(:session_response) { SessionResponse.new }
|
360
|
+
let(:account_response) { AccountResponse.new }
|
361
|
+
let(:username) { "ashlynn_brooke" }
|
362
|
+
let(:password) { "corinthians" }
|
363
|
+
|
364
|
+
before do
|
365
|
+
stub_request(:get, "https://api.themoviedb.org/3/authentication/token/new?api_key=token").
|
366
|
+
to_return(status: 200, body: request_token_response.to_json)
|
367
|
+
|
368
|
+
stub_request(:get, "https://api.themoviedb.org/3/authentication/token/validate_with_login?api_key=token&password=#{password}&request_token=#{request_token_response.request_token}&username=#{username}").
|
369
|
+
to_return(status: 200, body: authentication_response.to_json)
|
370
|
+
|
371
|
+
stub_request(:get, "https://api.themoviedb.org/3/authentication/session/new?api_key=token&request_token=#{request_token_response.request_token}").
|
372
|
+
to_return(status: 200, body: session_response.to_json)
|
373
|
+
|
374
|
+
stub_request(:get, "https://api.themoviedb.org/3/account?api_key=token&session_id=#{session_response.session_id}").
|
375
|
+
to_return(status: 200, body: account_response.to_json)
|
376
|
+
end
|
377
|
+
|
378
|
+
it "should post a request to favorite movie" do
|
379
|
+
request = stub_request(:post, "https://api.themoviedb.org/3/movie/#{movie.id}/rating?api_key=token&session_id=#{session_response.session_id}").
|
380
|
+
with(body: "{\"value\":7.5}").
|
381
|
+
to_return(status: 200, body: "{ \"success\": 1 }")
|
382
|
+
make_request
|
383
|
+
expect(request).to have_been_requested
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
context "when rating with guest account" do
|
388
|
+
let(:account) { Enceladus::GuestAccount.new }
|
389
|
+
let(:guest_account_response) { GuestAccountResponse.new }
|
390
|
+
|
391
|
+
before do
|
392
|
+
stub_request(:get, "https://api.themoviedb.org/3/authentication/guest_session/new?api_key=token").
|
393
|
+
to_return(status: 200, body: guest_account_response.to_json)
|
394
|
+
end
|
395
|
+
|
396
|
+
it "should post a request to favorite movie" do
|
397
|
+
request = stub_request(:post, "https://api.themoviedb.org/3/movie/#{movie.id}/rating?api_key=token&guest_session_id=#{guest_account_response.guest_session_id}").
|
398
|
+
with(body: "{\"value\":7.5}").
|
399
|
+
to_return(status: 200, body: "{ \"success\": 1 }")
|
400
|
+
make_request
|
401
|
+
expect(request).to have_been_requested
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
context "when provided account is not an Enceladus::Account or Enceladus::GuestAccount" do
|
406
|
+
let(:account) { nil }
|
407
|
+
|
408
|
+
it { expect{ subject }.to raise_error(Enceladus::Exception::ArgumentError) }
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
describe "#cast" do
|
413
|
+
subject(:cast) { movie.cast }
|
414
|
+
let(:movie) { Enceladus::Movie.new }
|
415
|
+
let(:movie_id) { 123 }
|
416
|
+
let(:response) { CreditsCollectionResponse.new }
|
417
|
+
let(:cast_response) { response.cast.first }
|
418
|
+
|
419
|
+
before do
|
420
|
+
movie.id = movie_id
|
421
|
+
stub_request(:get, "https://api.themoviedb.org/3/movie/#{movie_id}/credits?api_key=token").
|
422
|
+
to_return(status: 200, body: response.to_json)
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should return an array of Enceladus::Cast" do
|
426
|
+
expect(cast.map(&:class)).to eq([Enceladus::Cast])
|
427
|
+
end
|
428
|
+
|
429
|
+
describe "single cast resource" do
|
430
|
+
subject { cast.first }
|
431
|
+
|
432
|
+
[:cast_id, :character, :credit_id, :id, :name, :order, :profile_path].each do |attr|
|
433
|
+
it "should set cast #{attr}" do
|
434
|
+
expect(subject.send(attr)).to eq(cast_response.send(attr))
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
describe "#backdrop_urls" do
|
441
|
+
subject { movie.backdrop_urls }
|
442
|
+
let(:movie) { Enceladus::Movie.new }
|
443
|
+
|
444
|
+
before do
|
445
|
+
movie.backdrop_path = "/pamela_butt.jpeg"
|
446
|
+
stub_request(:get, /api.themoviedb.org\/3\/configuration/).to_return(status: 200, body: ConfigurationResponse.new.to_json)
|
447
|
+
Enceladus::Configuration::Image.instance.setup!
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should return profile url" do
|
451
|
+
is_expected.to eq(["http://test.com/w300#{movie.backdrop_path}", "http://test.com/w780#{movie.backdrop_path}", "http://test.com/w1280#{movie.backdrop_path}", "http://test.com/original#{movie.backdrop_path}"])
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
describe "#poster_urls" do
|
456
|
+
subject { movie.poster_urls }
|
457
|
+
let(:movie) { Enceladus::Movie.new }
|
458
|
+
|
459
|
+
before do
|
460
|
+
movie.poster_path = "/vivi_fernandes.jpeg"
|
461
|
+
stub_request(:get, /api.themoviedb.org\/3\/configuration/).to_return(status: 200, body: ConfigurationResponse.new.to_json)
|
462
|
+
Enceladus::Configuration::Image.instance.setup!
|
463
|
+
end
|
464
|
+
|
465
|
+
it "should return profile url" do
|
466
|
+
is_expected.to eq(["http://test.com/w92#{movie.poster_path}", "http://test.com/w154#{movie.poster_path}", "http://test.com/w185#{movie.poster_path}", "http://test.com/w342#{movie.poster_path}", "http://test.com/w500#{movie.poster_path}", "http://test.com/w780#{movie.poster_path}", "http://test.com/original#{movie.poster_path}"])
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enceladus::YouTubeTrailer do
|
4
|
+
describe "#link" do
|
5
|
+
subject { youtube_trailer.link }
|
6
|
+
|
7
|
+
let(:youtube_trailer) { Enceladus::YouTubeTrailer.new }
|
8
|
+
let(:source) { "dDc5H-WIn6M" }
|
9
|
+
|
10
|
+
before { youtube_trailer.source = source }
|
11
|
+
|
12
|
+
it "should return an instance of URI representing the YouTube video of the trailer" do
|
13
|
+
is_expected.to eq(URI("https://www.youtube.com/watch?v=#{source}"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear! do
|
3
|
+
add_filter "/support/responses"
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rspec'
|
7
|
+
require 'json'
|
8
|
+
require 'webmock/rspec'
|
9
|
+
require 'byebug'
|
10
|
+
require 'enceladus'
|
11
|
+
|
12
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |file| require file }
|
13
|
+
|
14
|
+
RSpec.configure do |c|
|
15
|
+
c.mock_with :rspec
|
16
|
+
|
17
|
+
c.before do
|
18
|
+
Enceladus::Configuration::Api.instance.send(:api_key=, "token")
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class AccountResponse
|
2
|
+
attr_accessor :id, :include_adult, :iso_3166_1, :iso_639_1, :name, :username
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.id = "36"
|
6
|
+
self.include_adult = false
|
7
|
+
self.iso_3166_1 = "US"
|
8
|
+
self.iso_639_1 = "en"
|
9
|
+
self.name = "John Doe"
|
10
|
+
self.username = "johndoe"
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_hash
|
14
|
+
{
|
15
|
+
id: id,
|
16
|
+
include_adult: include_adult,
|
17
|
+
iso_3166_1: iso_3166_1,
|
18
|
+
iso_639_1: iso_639_1,
|
19
|
+
name: name,
|
20
|
+
username: username
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json
|
25
|
+
to_hash.to_json
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class AuthenticationResponse
|
2
|
+
attr_accessor :request_token, :success
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.request_token = "641bf16c663db167c6cffcdff41126039d4445bf"
|
6
|
+
self.success = true
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
{
|
11
|
+
request_token: request_token,
|
12
|
+
success: success
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_json
|
17
|
+
to_hash.to_json
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ConfigurationResponse
|
2
|
+
attr_accessor :base_url, :secure_base_url, :backdrop_sizes, :logo_sizes, :poster_sizes, :profile_sizes, :still_sizes, :change_keys
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.base_url = "http://test.com/"
|
6
|
+
self.secure_base_url = "https://test.com/"
|
7
|
+
self.backdrop_sizes = [ "w300", "w780", "w1280", "original" ]
|
8
|
+
self.logo_sizes = [ "w45", "w92", "w154", "w185", "w300", "w500", "original" ]
|
9
|
+
self.poster_sizes = [ "w92", "w154", "w185", "w342", "w500", "w780", "original" ]
|
10
|
+
self.profile_sizes = [ "w45", "w185", "h632", "original" ]
|
11
|
+
self.still_sizes = [ "w92", "w185", "w300", "original" ]
|
12
|
+
self.change_keys = [ "adult", "also_known_as", "alternative_titles", "biography", "birthday", "budget", "cast",
|
13
|
+
"character_names", "crew", "deathday", "general", "genres", "homepage", "images", "imdb_id", "name", "original_title",
|
14
|
+
"overview", "plot_keywords", "production_companies", "production_countries", "releases", "revenue", "runtime",
|
15
|
+
"spoken_languages", "status", "tagline", "title", "trailers", "translations" ]
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json
|
19
|
+
{
|
20
|
+
images: {
|
21
|
+
base_url: base_url,
|
22
|
+
secure_base_url: secure_base_url,
|
23
|
+
backdrop_sizes: backdrop_sizes,
|
24
|
+
logo_sizes: logo_sizes,
|
25
|
+
poster_sizes: poster_sizes,
|
26
|
+
profile_sizes: profile_sizes,
|
27
|
+
still_sizes: still_sizes
|
28
|
+
},
|
29
|
+
change_keys: change_keys
|
30
|
+
}.to_json
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreditsCollectionResponse
|
2
|
+
attr_accessor :id, :cast
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.id = 550
|
6
|
+
self.cast = [CreditsResponse.new]
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
{
|
11
|
+
id: id,
|
12
|
+
cast: cast.map(&:to_hash)
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_json
|
17
|
+
to_hash.to_json
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class CreditsResponse
|
2
|
+
attr_accessor :cast_id, :character, :credit_id, :id, :name, :order, :profile_path
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.cast_id = 4
|
6
|
+
self.character = "The Narrator"
|
7
|
+
self.credit_id = "52fe4250c3a36847f80149f3"
|
8
|
+
self.id = 819
|
9
|
+
self.name = "Edward Norton"
|
10
|
+
self.order = 0
|
11
|
+
self.profile_path = "/iUiePUAQKN4GY6jorH9m23cbVli.jpg"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_hash
|
15
|
+
{
|
16
|
+
cast_id: 4,
|
17
|
+
character: "The Narrator",
|
18
|
+
credit_id: "52fe4250c3a36847f80149f3",
|
19
|
+
id: 819,
|
20
|
+
name: "Edward Norton",
|
21
|
+
order: 0,
|
22
|
+
profile_path: "/iUiePUAQKN4GY6jorH9m23cbVli.jpg"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json
|
27
|
+
to_hash.to_json
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ErrorResponse
|
2
|
+
attr_accessor :status_code, :status_message
|
3
|
+
|
4
|
+
def initialize(code, message)
|
5
|
+
self.status_code = code
|
6
|
+
self.status_message = message
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_json
|
10
|
+
{ status_code: status_code, status_message: status_message }.to_json
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class GuestAccountResponse
|
2
|
+
attr_accessor :guest_session_id, :success, :expires_at
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.guest_session_id = "0c550fd5da2fc3f321ab3bs9b60ca108"
|
6
|
+
self.success = true
|
7
|
+
self.expires_at = "2012-12-04 22:51:19 UTC"
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_hash
|
11
|
+
{
|
12
|
+
success: success,
|
13
|
+
guest_session_id: guest_session_id,
|
14
|
+
expires_at: expires_at
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json
|
19
|
+
to_hash.to_json
|
20
|
+
end
|
21
|
+
end
|