vzaar_api 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/README.md +2 -2
  4. data/lib/vzaar_api/abstract.rb +1 -1
  5. data/lib/vzaar_api/lib/active_object.rb +9 -4
  6. data/lib/vzaar_api/lib/api.rb +2 -1
  7. data/lib/vzaar_api/lib/has_resource_url.rb +7 -4
  8. data/lib/vzaar_api/lib/paged_resource.rb +7 -2
  9. data/lib/vzaar_api/lib/will_paginate.rb +5 -1
  10. data/lib/vzaar_api/playlist.rb +1 -1
  11. data/lib/vzaar_api/signature/abstract.rb +17 -4
  12. data/lib/vzaar_api/signature/multipart.rb +1 -1
  13. data/lib/vzaar_api/signature/single.rb +1 -1
  14. data/lib/vzaar_api/strategy/image/abstract.rb +25 -0
  15. data/lib/vzaar_api/strategy/image/create.rb +21 -0
  16. data/lib/vzaar_api/strategy/image/update.rb +11 -0
  17. data/lib/vzaar_api/strategy/subtitle/create.rb +36 -0
  18. data/lib/vzaar_api/upload/s3.rb +2 -4
  19. data/lib/vzaar_api/version.rb +1 -1
  20. data/lib/vzaar_api/video/subtitle.rb +38 -0
  21. data/lib/vzaar_api/video.rb +8 -1
  22. data/lib/vzaar_api.rb +5 -0
  23. data/spec/fixtures/vcr_cassettes/signature/multipart_201.yml +20 -20
  24. data/spec/fixtures/vcr_cassettes/signature/multipart_422.yml +12 -12
  25. data/spec/fixtures/vcr_cassettes/signature/single_201.yml +20 -20
  26. data/spec/fixtures/vcr_cassettes/signature/single_422.yml +11 -11
  27. data/spec/fixtures/vcr_cassettes/subtitles/create_201.yml +58 -0
  28. data/spec/fixtures/vcr_cassettes/subtitles/create_422.yml +48 -0
  29. data/spec/fixtures/vcr_cassettes/subtitles/create_from_file_201.yml +63 -0
  30. data/spec/fixtures/vcr_cassettes/subtitles/delete_204.yml +52 -0
  31. data/spec/fixtures/vcr_cassettes/subtitles/paginate.yml +58 -0
  32. data/spec/fixtures/vcr_cassettes/subtitles/paginate_first.yml +58 -0
  33. data/spec/fixtures/vcr_cassettes/subtitles/paginate_last.yml +113 -0
  34. data/spec/fixtures/vcr_cassettes/subtitles/paginate_next.yml +113 -0
  35. data/spec/fixtures/vcr_cassettes/subtitles/update_200.yml +113 -0
  36. data/spec/fixtures/vcr_cassettes/subtitles/update_422.yml +104 -0
  37. data/spec/fixtures/vcr_cassettes/upload/multipart_201.yml +162 -144
  38. data/spec/fixtures/vcr_cassettes/upload/multipart_403.yml +12 -116545
  39. data/spec/fixtures/vcr_cassettes/upload/single_201.yml +12 -23353
  40. data/spec/fixtures/vcr_cassettes/upload/single_403.yml +12 -23341
  41. data/spec/fixtures/vcr_cassettes/videos/create/link_201.yml +24 -22
  42. data/spec/fixtures/vcr_cassettes/videos/create/path_201.yml +55 -23394
  43. data/spec/fixtures/vcr_cassettes/videos/image_frame_202.yml +61 -0
  44. data/spec/fixtures/vcr_cassettes/videos/image_frame_422.yml +48 -0
  45. data/spec/fixtures/vcr_cassettes/videos/image_upload_frame_202.yml +62 -0
  46. data/spec/fixtures/vcr_cassettes/videos/image_upload_frame_422.yml +49 -0
  47. data/spec/support/files/drex.jpg +0 -0
  48. data/spec/support/files/fr.vtt +4 -0
  49. data/spec/support/helpers.rb +2 -3
  50. data/spec/support/shared_examples.rb +23 -0
  51. data/spec/vzaar_api/signature/multipart_spec.rb +34 -21
  52. data/spec/vzaar_api/signature/single_spec.rb +27 -16
  53. data/spec/vzaar_api/subtitle_spec.rb +206 -0
  54. data/spec/vzaar_api/upload/s3_spec.rb +40 -37
  55. data/spec/vzaar_api/video_spec.rb +55 -2
  56. metadata +45 -4
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: patch
5
+ uri: https://app.vzaar.localhost/api/v2/videos/18322783/image
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"time":3}'
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.0 (2015-12-25))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Fri, 30 Nov 2018 12:01:17 GMT
16
+ X-Auth-Token:
17
+ - pVrjGuKWP27U_kz4anfy
18
+ X-Client-Id:
19
+ - glide-franca-raise
20
+ Content-Type:
21
+ - application/json
22
+ response:
23
+ status:
24
+ code: 202
25
+ message: Accepted
26
+ headers:
27
+ Cache-Control:
28
+ - no-cache
29
+ Content-Type:
30
+ - application/json
31
+ Date:
32
+ - Fri, 30 Nov 2018 12:01:19 GMT
33
+ Server:
34
+ - nginx
35
+ X-Ratelimit-Limit:
36
+ - '200'
37
+ X-Ratelimit-Remaining:
38
+ - '199'
39
+ X-Ratelimit-Reset:
40
+ - '1543579320'
41
+ X-Ratelimit-Reset-In:
42
+ - 41 seconds
43
+ X-Request-Id:
44
+ - 415582ee-2d67-4fad-8817-16aae6459387
45
+ X-Runtime:
46
+ - '0.095732'
47
+ Content-Length:
48
+ - '2234'
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"data":{"id":18322783,"title":"24mb multi Sig V4","description":null,"state":"ready","private":false,"user_id":104013,"user_login":"cfx","account_id":103010,"account_name":"cfx","duration":117.3,"created_at":"2018-11-29T11:46:43.000Z","updated_at":"2018-11-30T11:48:27.000Z","url":"video-url","seo_url":null,"asset_url":"https://view.vzaar.com/18322783/video","poster_url":"https://view.vzaar.localhost/18322783/image","thumbnail_url":"https://view.vzaar.localhost/18322783/thumb","embed_code":"<div
54
+ class=\"vz-container\" style=\"position:relative;padding-bottom:56.25%;overflow:hidden;height:0;max-width:100%;\"><iframe
55
+ id=\"vzvd-18322783\" name=\"vzvd-18322783\" title=\"video player\" type=\"text/html\"
56
+ width=\"100%\" height=\"100%\" frameborder=\"0\" allowfullscreen allowTransparency=\"true\"
57
+ src=\"https://view.vzaar.localhost/18322783/player\" allow=\"autoplay\" class=\"video-player
58
+ video-player-responsive\" style=\"position:absolute;top:0;left:0;\"></iframe></div>","categories":[],"adverts":[{"advert_id":66,"name":"vzaar-jc","tag":"https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=","position":"pre","placement_scope":"user","created_at":"2017-10-02T13:22:06.000Z","updated_at":"2017-10-02T13:22:06.000Z"},{"advert_id":66,"name":"vzaar-jc","tag":"https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=","position":"post","placement_scope":"user","created_at":"2017-10-02T13:22:06.000Z","updated_at":"2017-10-02T13:22:06.000Z"}],"renditions":[{"id":1055605,"code":"uld","width":416,"height":234,"bitrate":145,"framerate":"12.0","status":"finished","size_in_bytes":3252196,"url":"https://view.vzaar.localhost/18322783/download/uld"},{"id":1055606,"code":"sd_lower","width":640,"height":360,"bitrate":730,"framerate":"60.0","status":"finished","size_in_bytes":12998740,"url":"https://view.vzaar.localhost/18322783/download/sd_lower"}],"subtitles":[]}}'
59
+ http_version:
60
+ recorded_at: Fri, 30 Nov 2018 12:01:19 GMT
61
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: patch
5
+ uri: https://app.vzaar.localhost/api/v2/videos/18322783/image
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.0 (2015-12-25))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Fri, 30 Nov 2018 12:11:31 GMT
16
+ X-Auth-Token:
17
+ - pVrjGuKWP27U_kz4anfy
18
+ X-Client-Id:
19
+ - glide-franca-raise
20
+ Content-Type:
21
+ - application/json
22
+ response:
23
+ status:
24
+ code: 422
25
+ message: Unprocessable Entity
26
+ headers:
27
+ Cache-Control:
28
+ - no-cache
29
+ Content-Type:
30
+ - application/json
31
+ Date:
32
+ - Fri, 30 Nov 2018 12:11:33 GMT
33
+ Server:
34
+ - nginx
35
+ X-Request-Id:
36
+ - 7411a0db-8fa4-4388-92aa-cc43606d4cb0
37
+ X-Runtime:
38
+ - '0.020769'
39
+ Content-Length:
40
+ - '72'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"errors":[{"message":"Invalid parameters","detail":"time is missing"}]}'
46
+ http_version:
47
+ recorded_at: Fri, 30 Nov 2018 12:11:33 GMT
48
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://app.vzaar.localhost/api/v2/videos/18322783/image
6
+ body:
7
+ encoding: UTF-8
8
+ string: !binary |-
9
+ LS0NCg0K
10
+ headers:
11
+ User-Agent:
12
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.0 (2015-12-25))
13
+ Accept:
14
+ - "*/*"
15
+ Date:
16
+ - Fri, 30 Nov 2018 15:58:53 GMT
17
+ X-Auth-Token:
18
+ - pVrjGuKWP27U_kz4anfy
19
+ X-Client-Id:
20
+ - glide-franca-raise
21
+ Content-Type:
22
+ - multipart/form-data; boundary=2229c10693517a1fbc3df731305a1654a01e0ca5
23
+ response:
24
+ status:
25
+ code: 202
26
+ message: Accepted
27
+ headers:
28
+ Cache-Control:
29
+ - no-cache
30
+ Content-Type:
31
+ - application/json
32
+ Date:
33
+ - Fri, 30 Nov 2018 15:58:55 GMT
34
+ Server:
35
+ - nginx
36
+ X-Ratelimit-Limit:
37
+ - '200'
38
+ X-Ratelimit-Remaining:
39
+ - '199'
40
+ X-Ratelimit-Reset:
41
+ - '1543593540'
42
+ X-Ratelimit-Reset-In:
43
+ - 6 seconds
44
+ X-Request-Id:
45
+ - 9e19170e-ab68-4093-8533-2ff61b377e55
46
+ X-Runtime:
47
+ - '0.245649'
48
+ Content-Length:
49
+ - '2232'
50
+ Connection:
51
+ - keep-alive
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"data":{"id":18322783,"title":"24mb multi Sig V4","description":"","state":"ready","private":false,"user_id":104013,"user_login":"cfx","account_id":103010,"account_name":"cfx","duration":117.3,"created_at":"2018-11-29T11:46:43.000Z","updated_at":"2018-11-30T15:58:54.837Z","url":"https://vzaar.localhost/videos/18322783","seo_url":null,"asset_url":"https://view.vzaar.localhost/18322783/video","poster_url":"https://view.vzaar.localhost/18322783/image","thumbnail_url":"https://view.vzaar.localhost/18322783/thumb","embed_code":"<div
55
+ class=\"vz-container\" style=\"position:relative;padding-bottom:56.25%;overflow:hidden;height:0;max-width:100%;\"><iframe
56
+ id=\"vzvd-18322783\" name=\"vzvd-18322783\" title=\"video player\" type=\"text/html\"
57
+ width=\"100%\" height=\"100%\" frameborder=\"0\" allowfullscreen allowTransparency=\"true\"
58
+ src=\"https://view.vzaar.localhost/18322783/player\" allow=\"autoplay\" class=\"video-player
59
+ video-player-responsive\" style=\"position:absolute;top:0;left:0;\"></iframe></div>","categories":[],"adverts":[{"advert_id":66,"name":"vzaar-jc","tag":"https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=","position":"pre","placement_scope":"user","created_at":"2017-10-02T13:22:06.000Z","updated_at":"2017-10-02T13:22:06.000Z"},{"advert_id":66,"name":"vzaar-jc","tag":"https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=","position":"post","placement_scope":"user","created_at":"2017-10-02T13:22:06.000Z","updated_at":"2017-10-02T13:22:06.000Z"}],"renditions":[{"id":1055605,"code":"uld","width":416,"height":234,"bitrate":145,"framerate":"12.0","status":"finished","size_in_bytes":3252196,"url":"https://view.vzaar.localhost/18322783/download/uld"},{"id":1055606,"code":"sd_lower","width":640,"height":360,"bitrate":730,"framerate":"60.0","status":"finished","size_in_bytes":12998740,"url":"https://view.vzaar.localhost/18322783/download/sd_lower"}],"subtitles":[]}}'
60
+ http_version:
61
+ recorded_at: Fri, 30 Nov 2018 15:58:54 GMT
62
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://app.vzaar.localhost/api/v2/videos/18322783/image
6
+ body:
7
+ encoding: UTF-8
8
+ string: !binary |-
9
+ LS0NCg0K
10
+ headers:
11
+ User-Agent:
12
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.0 (2015-12-25))
13
+ Accept:
14
+ - "*/*"
15
+ Date:
16
+ - Mon, 03 De c 2018 10:16:18 GMT
17
+ X-Auth-Token:
18
+ - pVrjGuKWP27U_kz4anfy
19
+ X-Client-Id:
20
+ - glide-franca-raise
21
+ Content-Type:
22
+ - multipart/form-data; boundary=cecaa7d8d7da5aedb88823fac7285032d48c02fc
23
+ response:
24
+ status:
25
+ code: 422
26
+ message: Unprocessable Entity
27
+ headers:
28
+ Cache-Control:
29
+ - no-cache
30
+ Content-Type:
31
+ - application/json
32
+ Date:
33
+ - Mon, 03 Dec 2018 10:16:27 GMT
34
+ Server:
35
+ - nginx
36
+ X-Request-Id:
37
+ - d2c67ae3-9bee-4ab1-b8b6-c2f9e4b08d3d
38
+ X-Runtime:
39
+ - '0.272929'
40
+ Content-Length:
41
+ - '73'
42
+ Connection:
43
+ - keep-alive
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"errors":[{"message":"File size exceeded","detail":"Max 10MB allowed"}]}'
47
+ http_version:
48
+ recorded_at: Mon, 03 Dec 2018 10:16:27 GMT
49
+ recorded_with: VCR 3.0.3
Binary file
@@ -0,0 +1,4 @@
1
+ WEBVTT
2
+
3
+ 00:00:37.000 --> 00:00:39.210
4
+ - Hello!
@@ -8,9 +8,8 @@ module Helpers
8
8
  end
9
9
 
10
10
  def setup_auth!
11
- VzaarApi.auth_token = 'TUGXzNL17ypaougMYpR3'
12
- VzaarApi.client_id = 'lair-tend72'
11
+ VzaarApi.auth_token = 'pVrjGuKWP27U_kz4anfy'
12
+ VzaarApi.client_id = 'glide-franca-raise'
13
13
  VzaarApi.hostname = 'app.vzaar.localhost'
14
14
  end
15
-
16
15
  end
@@ -0,0 +1,23 @@
1
+ module SharedExamples
2
+ shared_examples "includes x-amz headers hash" do
3
+ specify do
4
+ expect(subject.x_amz_headers)
5
+ .to eq("x-amz-credential" => "abc",
6
+ "x-amz-algorithm" => "alg",
7
+ "x-amz-date" => "date",
8
+ "x-amz-signature" => "sig")
9
+ end
10
+ end
11
+
12
+ shared_examples "assigns x-amz headers from response" do |cassette_name|
13
+ specify do
14
+ VCR.use_cassette(cassette_name) do
15
+ expect(subject.x_amz_headers)
16
+ .to eq("x-amz-credential" => "credential",
17
+ "x-amz-algorithm" => "AWS4-HMAC-SHA256",
18
+ "x-amz-date" => "date",
19
+ "x-amz-signature" => "signature")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -23,46 +23,59 @@ module VzaarApi
23
23
  upload_hostname: 'upload_hostname',
24
24
  part_size: 'part_size',
25
25
  part_size_in_bytes: 'part_size_in_bytes',
26
- parts: 'parts'
26
+ parts: 'parts',
27
+ upload_hostname: 'upload_hostname',
28
+ :"x-amz-credential" => "abc",
29
+ :"x-amz-algorithm" => "alg",
30
+ :"x-amz-date" => "date",
31
+ :"x-amz-signature" => "sig"
27
32
  }
28
33
  end
29
34
 
30
- specify { expect(subject.access_key_id).to eq 'access_key_id' }
31
35
  specify { expect(subject.acl).to eq 'acl' }
32
36
  specify { expect(subject.bucket).to eq 'bucket' }
33
- specify { expect(subject.content_type).to eq 'content_type' }
34
37
  specify { expect(subject.guid).to eq 'guid' }
35
38
  specify { expect(subject.key).to eq 'key' }
36
39
  specify { expect(subject.policy).to eq 'policy' }
37
- specify { expect(subject.signature).to eq 'signature' }
38
- specify { expect(subject.success_action_status).to eq 'success_action_status' }
40
+ specify { expect(subject.success_action_status)
41
+ .to eq 'success_action_status' }
39
42
  specify { expect(subject.upload_hostname).to eq 'upload_hostname' }
40
43
  specify { expect(subject.part_size).to eq 'part_size' }
41
- specify { expect(subject.part_size_in_bytes).to eq 'part_size_in_bytes' }
44
+ specify { expect(subject.part_size_in_bytes)
45
+ .to eq 'part_size_in_bytes' }
42
46
  specify { expect(subject.parts).to eq 'parts' }
47
+
48
+ it_behaves_like "includes x-amz headers hash"
43
49
  end
44
50
 
45
51
  describe '#create' do
52
+ let(:attrs) do
53
+ { filename: 'video.mp4',
54
+ filesize: 25165824,
55
+ uploader: UPLOADER }
56
+ end
57
+
58
+ subject { described_class.create attrs }
59
+
46
60
  context 'when successful' do
47
61
  it 'builds a signature' do
48
62
  VCR.use_cassette('signature/multipart_201') do
49
- attrs = { filename: 'video.mp4', filesize: 25165824, uploader: UPLOADER }
50
- signature = described_class.create attrs
51
- expect(signature.access_key_id).to eq 'access_key_id'
52
- expect(signature.acl).to eq 'private'
53
- expect(signature.bucket).to eq 'vzaar-upload-development'
54
- expect(signature.content_type).to eq 'binary/octet-stream'
55
- expect(signature.guid).to eq 'guid'
56
- expect(signature.key).to eq 'vzaar/t8d/ec9/source/t8dec9434bcc64622b68d1dc16f3ddffap/${filename}'
57
- expect(signature.policy).to eq 'policy'
58
- expect(signature.signature).to eq 'signature'
59
- expect(signature.success_action_status).to eq '201'
60
- expect(signature.upload_hostname).to eq 'https://vzaar-upload-development.s3.amazonaws.com'
61
- expect(signature.part_size).to eq '5MB'
62
- expect(signature.part_size_in_bytes).to eq 5242880
63
- expect(signature.parts).to eq 5
63
+ expect(subject.acl).to eq 'private'
64
+ expect(subject.bucket).to eq 'vzaar-upload-development'
65
+ expect(subject.guid).to eq "tjYfV-j3o754"
66
+ expect(subject.key)
67
+ .to eq "vzaar/tjY/fV-/source/tjYfV-j3o754/${filename}"
68
+ expect(subject.policy).to eq 'policy'
69
+ expect(subject.success_action_status).to eq '201'
70
+ expect(subject.upload_hostname).to eq 'https://vzaar-upload-development.s3.amazonaws.com'
71
+ expect(subject.part_size).to eq '5MB'
72
+ expect(subject.part_size_in_bytes).to eq 5242880
73
+ expect(subject.parts).to eq 5
64
74
  end
65
75
  end
76
+
77
+ it_behaves_like "assigns x-amz headers from response",
78
+ "signature/multipart_201"
66
79
  end
67
80
 
68
81
  context 'when unsuccessful' do
@@ -20,40 +20,52 @@ module VzaarApi
20
20
  policy: 'policy',
21
21
  signature: 'signature',
22
22
  success_action_status: 'success_action_status',
23
- upload_hostname: 'upload_hostname'
23
+ upload_hostname: 'upload_hostname',
24
+ :"x-amz-credential" => "abc",
25
+ :"x-amz-algorithm" => "alg",
26
+ :"x-amz-date" => "date",
27
+ :"x-amz-signature" => "sig"
24
28
  }
25
29
  end
26
30
 
27
31
  specify { expect(subject.access_key_id).to eq 'access_key_id' }
28
32
  specify { expect(subject.acl).to eq 'acl' }
29
33
  specify { expect(subject.bucket).to eq 'bucket' }
30
- specify { expect(subject.content_type).to eq 'content_type' }
31
34
  specify { expect(subject.guid).to eq 'guid' }
32
35
  specify { expect(subject.key).to eq 'key' }
33
36
  specify { expect(subject.policy).to eq 'policy' }
34
- specify { expect(subject.signature).to eq 'signature' }
35
37
  specify { expect(subject.success_action_status).to eq 'success_action_status' }
36
38
  specify { expect(subject.upload_hostname).to eq 'upload_hostname' }
39
+
40
+ it_behaves_like "includes x-amz headers hash"
37
41
  end
38
42
 
39
43
  describe '#create' do
40
44
  context 'when successful' do
45
+ let(:attrs) do
46
+ { filename: 'video.mp4',
47
+ filesize: 25165824,
48
+ uploader: UPLOADER }
49
+ end
50
+
51
+ subject { described_class.create attrs }
52
+
41
53
  it 'builds a signature' do
42
54
  VCR.use_cassette('signature/single_201') do
43
- attrs = { filename: 'video.mp4', filesize: 25165824, uploader: UPLOADER }
44
- signature = described_class.create attrs
45
- expect(signature.access_key_id).to eq 'access_key_id'
46
- expect(signature.acl).to eq 'private'
47
- expect(signature.bucket).to eq 'vzaar-upload-development'
48
- expect(signature.content_type).to eq 'binary/octet-stream'
49
- expect(signature.guid).to eq 'guid'
50
- expect(signature.key).to eq 'vzaar/t8d/ec9/source/t8dec9434bcc64622b68d1dc16f3ddffap/${filename}'
51
- expect(signature.policy).to eq 'policy'
52
- expect(signature.signature).to eq 'signature'
53
- expect(signature.success_action_status).to eq '201'
54
- expect(signature.upload_hostname).to eq 'https://vzaar-upload-development.s3.amazonaws.com'
55
+ expect(subject.acl).to eq 'private'
56
+ expect(subject.bucket).to eq 'vzaar-upload-development'
57
+ expect(subject.guid).to eq "guid"
58
+ expect(subject.key)
59
+ .to eq "vzaar/twc/Kqm/source/twcKqmLoY-d4/${filename}"
60
+ expect(subject.policy).to eq 'policy'
61
+ expect(subject.success_action_status).to eq '201'
62
+ expect(subject.upload_hostname)
63
+ .to eq 'https://vzaar-upload-development.s3.amazonaws.com'
55
64
  end
56
65
  end
66
+
67
+ it_behaves_like "assigns x-amz headers from response",
68
+ "signature/single_201"
57
69
  end
58
70
 
59
71
  context 'when unsuccessful' do
@@ -66,7 +78,6 @@ module VzaarApi
66
78
  end
67
79
  end
68
80
  end
69
-
70
81
  end
71
82
  end
72
83
  end
@@ -0,0 +1,206 @@
1
+ module VzaarApi
2
+ describe Video::Subtitle do
3
+ def get_subtitle(index)
4
+ VCR.use_cassette('subtitles/paginate') do
5
+ subs = described_class.paginate(video_id, page: 1, per_page: 3)
6
+ subs.first[index-1]
7
+ end
8
+ end
9
+
10
+ before do
11
+ setup_auth!
12
+ end
13
+
14
+ let(:video_id) { 14370501 }
15
+
16
+ let(:subtitle) { get_subtitle 1 }
17
+ let(:subtitle2) { get_subtitle 2 }
18
+ let(:subtitle3) { get_subtitle 3 }
19
+
20
+ describe '#initialize' do
21
+ subject { described_class.new attrs }
22
+
23
+ let(:attrs) do
24
+ {
25
+ id: 'id',
26
+ title: 'title',
27
+ code: 'code',
28
+ language: 'language',
29
+ created_at: 'created_at',
30
+ updated_at: 'updated_at',
31
+ scope_id: video_id
32
+ }
33
+ end
34
+
35
+ specify { expect(subject.id).to eq 'id' }
36
+ specify { expect(subject.title).to eq 'title' }
37
+ specify { expect(subject.code).to eq 'code' }
38
+ specify { expect(subject.language).to eq 'language' }
39
+ specify { expect(subject.created_at).to eq 'created_at' }
40
+ specify { expect(subject.updated_at).to eq 'updated_at' }
41
+ specify { expect(subject.scope_id).to eq video_id }
42
+ end
43
+
44
+ describe '#code' do
45
+ context 'when nothing has changed' do
46
+ let(:changed) { [] }
47
+ let(:changed_attributes) { {} }
48
+ let(:changes) { {} }
49
+
50
+ specify { expect(subtitle).not_to be_changed }
51
+ specify { expect(subtitle.changed).to match_array changed }
52
+ specify { expect(subtitle.changed_attributes).to eq changed_attributes }
53
+ specify { expect(subtitle.changes).to eq changes }
54
+ end
55
+
56
+ context 'when attributes have changed' do
57
+ before do
58
+ subtitle.code = 'pl'
59
+ end
60
+
61
+ let(:changed) { [:code] }
62
+ let(:changed_attributes) { { code: 'pl' } }
63
+ let(:changes) { { code: %w(ru pl) } }
64
+
65
+ specify { expect(subtitle).to be_changed }
66
+ specify { expect(subtitle.changed).to match_array changed }
67
+ specify { expect(subtitle.changed_attributes).to eq changed_attributes }
68
+ specify { expect(subtitle.changes).to eq changes }
69
+ end
70
+ end
71
+
72
+ describe '.create' do
73
+ context 'when we have a file path' do
74
+ let(:attrs) do
75
+ { file: 'spec/support/files/fr.vtt', code: 'de' }
76
+ end
77
+
78
+ context 'and a new subtilte is created' do
79
+ it 'returns the new subtitle' do
80
+ VCR.use_cassette('subtitles/create_from_file_201') do
81
+ sub = described_class.create(video_id, attrs)
82
+ expect(sub.id).to eq 26887
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'when we provide a string' do
89
+ let(:attrs) do
90
+ { content: 'WEBVTT\n', code: 'pl' }
91
+ end
92
+
93
+ context 'and a new subtitle is created' do
94
+ it 'returns the new subtitle' do
95
+ VCR.use_cassette('subtitles/create_201') do
96
+ sub = described_class.create(video_id, attrs)
97
+ expect(sub.id).to eq 26888
98
+ end
99
+ end
100
+ end
101
+
102
+ context 'and invalid params are provided' do
103
+ let(:attrs) {{ content: 'WEBVTT\n' }}
104
+
105
+ it 'raises an error' do
106
+ VCR.use_cassette('subtitles/create_422') do
107
+ expect { described_class.create(video_id, attrs) }
108
+ .to raise_error(Error, 'Invalid parameters: code is missing')
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "update" do
116
+ context "when attribute is updated" do
117
+ specify do
118
+ VCR.use_cassette('subtitles/update_200') do
119
+ pager = described_class.paginate(
120
+ video_id, page: 1, per_page: 3
121
+ )
122
+ sub = pager.first.first
123
+ sub.code = "sr"
124
+
125
+ expect(sub.save).to be_truthy
126
+ expect(sub.code).to eq("sr")
127
+ end
128
+ end
129
+ end
130
+
131
+ context "when attribute cannot be updated" do
132
+ specify do
133
+ VCR.use_cassette('subtitles/update_422') do
134
+ pager = described_class.paginate(
135
+ video_id, page: 1, per_page: 3
136
+ )
137
+ sub = pager.first.first
138
+ sub.code = ""
139
+
140
+ msg = "Invalid parameters: Validation failed: "\
141
+ "Code field cannot be blank, Language not supported"
142
+
143
+ expect { sub.save }.to raise_error(VzaarApi::Error, msg)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ describe '#delete' do
150
+ context 'when subtitle is deleted successfully' do
151
+ specify do
152
+ VCR.use_cassette('subtitles/delete_204') do
153
+ expect(subtitle.delete).to be_truthy
154
+ end
155
+ end
156
+ end
157
+ end
158
+
159
+ describe '.paginate' do
160
+ it "loads all subtitels from page 1" do
161
+ VCR.use_cassette('subtitles/paginate') do
162
+ pager = described_class.paginate(
163
+ video_id, page: 1, per_page: 3
164
+ )
165
+ expect(pager.first.length).to eq 3
166
+ end
167
+ end
168
+
169
+ describe "first" do
170
+ specify do
171
+ VCR.use_cassette('subtitles/paginate_first') do
172
+ pager = described_class.paginate(
173
+ video_id, page: 1, per_page: 1
174
+ )
175
+
176
+ expect(pager.first.first.id).to eq(subtitle.id)
177
+ end
178
+ end
179
+ end
180
+
181
+ describe "next" do
182
+ specify do
183
+ VCR.use_cassette('subtitles/paginate_next') do
184
+ pager = described_class.paginate(
185
+ video_id, page: 1, per_page: 1
186
+ )
187
+
188
+ expect(pager.next.first.id).to eq(subtitle2.id)
189
+ end
190
+ end
191
+ end
192
+
193
+ describe "last" do
194
+ specify do
195
+ VCR.use_cassette('subtitles/paginate_last') do
196
+ pager = described_class.paginate(
197
+ video_id, page: 1, per_page: 1
198
+ )
199
+
200
+ expect(pager.last.first.id).to eq(subtitle3.id)
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end