vzaar_api 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +4 -0
  4. data/.tool-versions +1 -0
  5. data/.travis.yml +3 -0
  6. data/Changelog +50 -0
  7. data/Gemfile +3 -0
  8. data/Guardfile +25 -0
  9. data/README.md +55 -0
  10. data/Rakefile +26 -0
  11. data/examples/README.md +33 -0
  12. data/examples/api_envs.yml.example +31 -0
  13. data/examples/category/create_update_delete_spec.rb +100 -0
  14. data/examples/category/list_spec.rb +38 -0
  15. data/examples/category/list_subtree_spec.rb +40 -0
  16. data/examples/category/lookup_spec.rb +35 -0
  17. data/examples/encoding_preset/list_spec.rb +38 -0
  18. data/examples/encoding_preset/lookup_spec.rb +35 -0
  19. data/examples/ingest_recipe/create_update_delete_spec.rb +70 -0
  20. data/examples/ingest_recipe/list_spec.rb +38 -0
  21. data/examples/ingest_recipe/lookup_spec.rb +35 -0
  22. data/examples/playlist/create_update_delete_spec.rb +97 -0
  23. data/examples/playlist/list_spec.rb +37 -0
  24. data/examples/playlist/lookup_spec.rb +34 -0
  25. data/examples/rate_limit_spec.rb +18 -0
  26. data/examples/spec_helper.rb +17 -0
  27. data/examples/support/helpers.rb +16 -0
  28. data/examples/support/videos/medium.mp4 +0 -0
  29. data/examples/support/videos/small.mp4 +0 -0
  30. data/examples/video/create_update_delete_spec.rb +73 -0
  31. data/lib/vzaar_api/abstract.rb +9 -0
  32. data/lib/vzaar_api/category.rb +39 -0
  33. data/lib/vzaar_api/encoding_preset.rb +19 -0
  34. data/lib/vzaar_api/ingest_recipe.rb +35 -0
  35. data/lib/vzaar_api/legacy_rendition.rb +11 -0
  36. data/lib/vzaar_api/lib/active_object.rb +92 -0
  37. data/lib/vzaar_api/lib/api.rb +54 -0
  38. data/lib/vzaar_api/lib/api_response.rb +61 -0
  39. data/lib/vzaar_api/lib/has_attributes.rb +49 -0
  40. data/lib/vzaar_api/lib/has_collection_builder.rb +17 -0
  41. data/lib/vzaar_api/lib/has_resource_url.rb +24 -0
  42. data/lib/vzaar_api/lib/paged_resource.rb +80 -0
  43. data/lib/vzaar_api/lib/will_paginate.rb +22 -0
  44. data/lib/vzaar_api/link_upload.rb +14 -0
  45. data/lib/vzaar_api/playlist.rb +29 -0
  46. data/lib/vzaar_api/rendition.rb +16 -0
  47. data/lib/vzaar_api/signature/abstract.rb +40 -0
  48. data/lib/vzaar_api/signature/factory.rb +39 -0
  49. data/lib/vzaar_api/signature/multipart.rb +23 -0
  50. data/lib/vzaar_api/signature/single.rb +17 -0
  51. data/lib/vzaar_api/strategy/video/create.rb +46 -0
  52. data/lib/vzaar_api/upload/s3.rb +90 -0
  53. data/lib/vzaar_api/upload/virtual_file.rb +14 -0
  54. data/lib/vzaar_api/version.rb +4 -0
  55. data/lib/vzaar_api/video.rb +38 -0
  56. data/lib/vzaar_api.rb +60 -0
  57. data/spec/fixtures/vcr_cassettes/categories/each_item.yml +363 -0
  58. data/spec/fixtures/vcr_cassettes/categories/find.yml +61 -0
  59. data/spec/fixtures/vcr_cassettes/categories/find_404.yml +49 -0
  60. data/spec/fixtures/vcr_cassettes/categories/paginate_first.yml +61 -0
  61. data/spec/fixtures/vcr_cassettes/categories/paginate_last.yml +119 -0
  62. data/spec/fixtures/vcr_cassettes/categories/paginate_next.yml +120 -0
  63. data/spec/fixtures/vcr_cassettes/categories/paginate_previous.yml +120 -0
  64. data/spec/fixtures/vcr_cassettes/categories/subtree.yml +127 -0
  65. data/spec/fixtures/vcr_cassettes/categories/subtree_paginate_first.yml +123 -0
  66. data/spec/fixtures/vcr_cassettes/categories/subtree_paginate_last.yml +185 -0
  67. data/spec/fixtures/vcr_cassettes/categories/subtree_paginate_next.yml +184 -0
  68. data/spec/fixtures/vcr_cassettes/categories/subtree_paginate_previous.yml +184 -0
  69. data/spec/fixtures/vcr_cassettes/encoding_presets/each_item.yml +299 -0
  70. data/spec/fixtures/vcr_cassettes/encoding_presets/find.yml +62 -0
  71. data/spec/fixtures/vcr_cassettes/encoding_presets/find_404.yml +51 -0
  72. data/spec/fixtures/vcr_cassettes/encoding_presets/paginate_first.yml +62 -0
  73. data/spec/fixtures/vcr_cassettes/encoding_presets/paginate_last.yml +121 -0
  74. data/spec/fixtures/vcr_cassettes/encoding_presets/paginate_next.yml +121 -0
  75. data/spec/fixtures/vcr_cassettes/encoding_presets/paginate_previous.yml +121 -0
  76. data/spec/fixtures/vcr_cassettes/ingest_recipes/create_200.yml +63 -0
  77. data/spec/fixtures/vcr_cassettes/ingest_recipes/create_422.yml +52 -0
  78. data/spec/fixtures/vcr_cassettes/ingest_recipes/delete_204.yml +166 -0
  79. data/spec/fixtures/vcr_cassettes/ingest_recipes/delete_422.yml +112 -0
  80. data/spec/fixtures/vcr_cassettes/ingest_recipes/each_item.yml +182 -0
  81. data/spec/fixtures/vcr_cassettes/ingest_recipes/find.yml +62 -0
  82. data/spec/fixtures/vcr_cassettes/ingest_recipes/find_404.yml +51 -0
  83. data/spec/fixtures/vcr_cassettes/ingest_recipes/paginate_first.yml +62 -0
  84. data/spec/fixtures/vcr_cassettes/ingest_recipes/paginate_last.yml +122 -0
  85. data/spec/fixtures/vcr_cassettes/ingest_recipes/paginate_next.yml +121 -0
  86. data/spec/fixtures/vcr_cassettes/ingest_recipes/paginate_previous.yml +122 -0
  87. data/spec/fixtures/vcr_cassettes/ingest_recipes/update_200.yml +242 -0
  88. data/spec/fixtures/vcr_cassettes/ingest_recipes/update_422.yml +113 -0
  89. data/spec/fixtures/vcr_cassettes/playlists/each_item.yml +607 -0
  90. data/spec/fixtures/vcr_cassettes/playlists/find.yml +66 -0
  91. data/spec/fixtures/vcr_cassettes/playlists/find_404.yml +51 -0
  92. data/spec/fixtures/vcr_cassettes/playlists/paginate_first.yml +74 -0
  93. data/spec/fixtures/vcr_cassettes/playlists/paginate_last.yml +146 -0
  94. data/spec/fixtures/vcr_cassettes/playlists/paginate_next.yml +145 -0
  95. data/spec/fixtures/vcr_cassettes/playlists/paginate_previous.yml +145 -0
  96. data/spec/fixtures/vcr_cassettes/signature/multipart_201.yml +62 -0
  97. data/spec/fixtures/vcr_cassettes/signature/multipart_422.yml +52 -0
  98. data/spec/fixtures/vcr_cassettes/signature/single_201.yml +62 -0
  99. data/spec/fixtures/vcr_cassettes/signature/single_422.yml +51 -0
  100. data/spec/fixtures/vcr_cassettes/upload/multipart_201.yml +279868 -0
  101. data/spec/fixtures/vcr_cassettes/upload/multipart_403.yml +116578 -0
  102. data/spec/fixtures/vcr_cassettes/upload/single_201.yml +23388 -0
  103. data/spec/fixtures/vcr_cassettes/upload/single_403.yml +23374 -0
  104. data/spec/fixtures/vcr_cassettes/videos/create/error.yml +51 -0
  105. data/spec/fixtures/vcr_cassettes/videos/create/guid_201.yml +65 -0
  106. data/spec/fixtures/vcr_cassettes/videos/create/guid_error.yml +52 -0
  107. data/spec/fixtures/vcr_cassettes/videos/create/link_201.yml +65 -0
  108. data/spec/fixtures/vcr_cassettes/videos/create/link_error.yml +51 -0
  109. data/spec/fixtures/vcr_cassettes/videos/create/path_201.yml +23509 -0
  110. data/spec/fixtures/vcr_cassettes/videos/delete_204.yml +168 -0
  111. data/spec/fixtures/vcr_cassettes/videos/find.yml +66 -0
  112. data/spec/fixtures/vcr_cassettes/videos/find_404.yml +51 -0
  113. data/spec/fixtures/vcr_cassettes/videos/paginate_first.yml +71 -0
  114. data/spec/fixtures/vcr_cassettes/videos/paginate_last.yml +137 -0
  115. data/spec/fixtures/vcr_cassettes/videos/paginate_next.yml +139 -0
  116. data/spec/fixtures/vcr_cassettes/videos/paginate_previous.yml +139 -0
  117. data/spec/spec_helper.rb +103 -0
  118. data/spec/support/files/video-1.0MB.mp4 +0 -0
  119. data/spec/support/files/video-12.0MB.mp4 +0 -0
  120. data/spec/support/files/video-4.9MB.mp4 +0 -0
  121. data/spec/support/files/video-5.0MB.mp4 +0 -0
  122. data/spec/support/helpers.rb +16 -0
  123. data/spec/vzaar_api/category_spec.rb +141 -0
  124. data/spec/vzaar_api/encoding_preset_spec.rb +92 -0
  125. data/spec/vzaar_api/ingest_recipe_spec.rb +197 -0
  126. data/spec/vzaar_api/lib/api_spec.rb +28 -0
  127. data/spec/vzaar_api/playlist_spec.rb +97 -0
  128. data/spec/vzaar_api/rendition_spec.rb +55 -0
  129. data/spec/vzaar_api/signature/factory_spec.rb +68 -0
  130. data/spec/vzaar_api/signature/multipart_spec.rb +81 -0
  131. data/spec/vzaar_api/signature/single_spec.rb +72 -0
  132. data/spec/vzaar_api/upload/s3_spec.rb +112 -0
  133. data/spec/vzaar_api/video_spec.rb +248 -0
  134. data/spec/vzaar_api/vzaar_api_spec.rb +18 -0
  135. data/spec/vzaar_api_helper.rb +19 -0
  136. data/vzaar.png +0 -0
  137. data/vzaar_api.gemspec +35 -0
  138. metadata +413 -0
@@ -0,0 +1,92 @@
1
+ module VzaarApi
2
+ describe EncodingPreset do
3
+
4
+ before do
5
+ setup_auth!
6
+ end
7
+
8
+ describe '.find' do
9
+ context 'when the encoding preset can be found' do
10
+ it 'finds the encoding preset' do
11
+ VCR.use_cassette('encoding_presets/find') do
12
+ preset = described_class.find(4)
13
+ expect(preset.id).to eq 4
14
+ expect(preset.name).to eq "LD"
15
+ expect(preset.description).to eq "270p"
16
+ expect(preset.output_format).to eq "mp4"
17
+ expect(preset.bitrate_kbps).to eq 365
18
+ expect(preset.max_bitrate_kbps).to eq 500
19
+ expect(preset.long_dimension).to eq 480
20
+ expect(preset.video_codec).to eq "libx264"
21
+ expect(preset.profile).to eq "baseline"
22
+ expect(preset.frame_rate_upper_threshold).to eq "29.97"
23
+ expect(preset.keyframe_upper_threshold).to eq 60
24
+ expect(preset.audio_bitrate_kbps).to eq 128
25
+ expect(preset.audio_channels).to eq 2
26
+ expect(preset.audio_sample_rate).to eq 44100
27
+ expect(preset.created_at).to eq "2016-10-24T12:36:47.000Z"
28
+ expect(preset.updated_at).to eq "2016-10-24T12:36:47.000Z"
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'when the encoding preset cannot be found' do
34
+ it 'raises an error' do
35
+ VCR.use_cassette('encoding_presets/find_404') do
36
+ expect { described_class.find(-1) }.
37
+ to raise_error(Error, 'Not found: Resource cannot be found')
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '.each_item' do
44
+ it 'loads the category collection' do
45
+ VCR.use_cassette('encoding_presets/each_item') do
46
+ enum = described_class.each_item(per_page: 2)
47
+ ids = enum.map { |preset| preset.id }
48
+ expect(ids).to match_array [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '.paginate' do
54
+ it 'loads the preset collection' do
55
+ VCR.use_cassette('encoding_presets/paginate_first') do
56
+ pager = described_class.paginate(per_page: 1)
57
+ pager.first
58
+ ids = pager.collection.map { |preset| preset.id }
59
+ expect(ids).to match_array [9]
60
+ end
61
+ end
62
+
63
+ it 'loads the preset collection' do
64
+ VCR.use_cassette('encoding_presets/paginate_next') do
65
+ pager = described_class.paginate(per_page: 1)
66
+ pager.next
67
+ ids = pager.collection.map { |preset| preset.id }
68
+ expect(ids).to match_array [2]
69
+ end
70
+ end
71
+
72
+ it 'loads the preset collection' do
73
+ VCR.use_cassette('encoding_presets/paginate_last') do
74
+ pager = described_class.paginate(per_page: 1)
75
+ pager.last
76
+ ids = pager.collection.map { |preset| preset.id }
77
+ expect(ids).to match_array [11]
78
+ end
79
+ end
80
+
81
+ it 'loads the preset collection' do
82
+ VCR.use_cassette('encoding_presets/paginate_previous') do
83
+ pager = described_class.paginate(page: 4, per_page: 1)
84
+ pager.previous
85
+ ids = pager.collection.map { |preset| preset.id }
86
+ expect(ids).to match_array [3]
87
+ end
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,197 @@
1
+ module VzaarApi
2
+ describe IngestRecipe do
3
+
4
+ before do
5
+ setup_auth!
6
+ end
7
+
8
+ describe '.find' do
9
+ context 'when the recipe can be found' do
10
+ it 'finds the recipe' do
11
+ VCR.use_cassette('ingest_recipes/find') do
12
+ recipe = described_class.find(1)
13
+ expect(recipe.id).to eq 1
14
+ expect(recipe.name).to eq "new-video"
15
+ expect(recipe.recipe_type).to eq "new_video"
16
+ expect(recipe.description).to be_nil
17
+ expect(recipe.account_id).to eq 79357
18
+ expect(recipe.user_id).to eq 79357
19
+ expect(recipe.default).to eq true
20
+ expect(recipe.multipass).to eq false
21
+ expect(recipe.frame_grab_time).to eq "3.5"
22
+ expect(recipe.generate_animated_thumb).to eq true
23
+ expect(recipe.generate_sprite).to eq true
24
+ expect(recipe.use_watermark).to eq true
25
+ expect(recipe.send_to_youtube).to eq false
26
+ expect(recipe.encoding_presets.count).to eq 5
27
+ expect(recipe.created_at).to eq '2016-11-09T11:01:38.000Z'
28
+ expect(recipe.updated_at).to eq '2016-11-09T11:01:38.000Z'
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'when the recipe cannot be found' do
34
+ it 'raises an error' do
35
+ VCR.use_cassette('ingest_recipes/find_404') do
36
+ expect { described_class.find(-1) }.
37
+ to raise_error(Error, 'Not found: Resource cannot be found')
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '.create' do
44
+ context 'when recipe is created successfully' do
45
+ let(:attrs) do
46
+ {
47
+ name: 'new-recipe',
48
+ description: 'the new recipe',
49
+ default: true,
50
+ frame_grab_time: 5.5,
51
+ multipass: false,
52
+ generate_animated_thumb: true,
53
+ generate_sprite: true,
54
+ use_watermark: true,
55
+ send_to_youtube: true,
56
+ encoding_preset_ids: [1,2,3,4]
57
+ }
58
+ end
59
+
60
+ it 'returns the ingest recipe object' do
61
+ VCR.use_cassette('ingest_recipes/create_200') do
62
+ recipe = described_class.create(attrs)
63
+ expect(recipe.id).to eq 8
64
+ expect(recipe.name).to eq "new-recipe"
65
+ expect(recipe.recipe_type).to eq "new_video"
66
+ expect(recipe.description).to eq 'the new recipe'
67
+ expect(recipe.account_id).to eq 79357
68
+ expect(recipe.user_id).to eq 79357
69
+ expect(recipe.default).to eq true
70
+ expect(recipe.multipass).to eq false
71
+ expect(recipe.frame_grab_time).to eq '5.5'
72
+ expect(recipe.generate_animated_thumb).to eq true
73
+ expect(recipe.generate_sprite).to eq true
74
+ expect(recipe.use_watermark).to eq true
75
+ expect(recipe.send_to_youtube).to eq true
76
+ expect(recipe.encoding_presets.count).to eq 4
77
+ expect(recipe.created_at).to eq '2016-11-18T10:25:47.996Z'
78
+ expect(recipe.updated_at).to eq '2016-11-18T10:25:47.996Z'
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'when an error is returned' do
84
+ let(:attrs) { { junk: 'yard' } }
85
+ it 'raises the error returned form the API' do
86
+ VCR.use_cassette('ingest_recipes/create_422') do
87
+ expect { described_class.create(attrs) }.
88
+ to raise_error(Error, 'Invalid parameters: name is missing, ' \
89
+ 'encoding_preset_ids is missing, encoding_preset_ids is invalid')
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#save' do
96
+ context 'when recipe is updated successfully' do
97
+ it 'returns the ingest recipe object' do
98
+ VCR.use_cassette('ingest_recipes/update_200') do
99
+ recipe = described_class.find(8)
100
+ recipe.encoding_presets = nil
101
+ recipe.encoding_presets << EncodingPreset.find(1)
102
+ recipe.encoding_presets << EncodingPreset.find(2)
103
+ recipe.name = 'updated'
104
+ expect(recipe.save).to eq true
105
+ expect(recipe.name).to eq 'updated'
106
+ expect(recipe.encoding_presets.count).to eq 2
107
+ expect(recipe.created_at).to eq '2016-11-18T10:25:47.000Z'
108
+ expect(recipe.updated_at).to eq '2016-11-18T11:20:06.000Z'
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'when an error is returned' do
114
+ it 'raises the error returned form the API' do
115
+ VCR.use_cassette('ingest_recipes/update_422') do
116
+ recipe = described_class.find(8)
117
+ recipe.encoding_presets = nil
118
+ expect { recipe.save }.to raise_error(
119
+ Error, 'Invalid parameters: encoding_preset_ids is invalid')
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ describe '#delete' do
126
+ context 'when recipe is deleted successfully' do
127
+ it 'returns true' do
128
+ VCR.use_cassette('ingest_recipes/delete_204') do
129
+ recipe = described_class.find(7)
130
+ expect(recipe.delete).to eq true
131
+ expect { described_class.find(7) }.
132
+ to raise_error(Error, 'Not found: Resource cannot be found')
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'when an error is returned' do
138
+ it 'raises the error returned form the API' do
139
+ VCR.use_cassette('ingest_recipes/delete_422') do
140
+ recipe = described_class.find(8)
141
+ expect { recipe.delete }.to raise_error(
142
+ Error, 'Invalid parameters: You cannot delete your default ingest recipe')
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ describe '.each_item' do
149
+ it 'loads the category collection' do
150
+ VCR.use_cassette('ingest_recipes/each_item') do
151
+ enum = described_class.each_item(per_page: 2)
152
+ ids = enum.map { |recipe| recipe.id }
153
+ expect(ids).to match_array [1, 2, 3, 5, 8]
154
+ end
155
+ end
156
+ end
157
+
158
+ describe '.paginate' do
159
+ it 'loads the recipe collection' do
160
+ VCR.use_cassette('ingest_recipes/paginate_first') do
161
+ pager = described_class.paginate(per_page: 1)
162
+ pager.first
163
+ ids = pager.collection.map { |recipe| recipe.id }
164
+ expect(ids).to match_array [1]
165
+ end
166
+ end
167
+
168
+ it 'loads the recipe collection' do
169
+ VCR.use_cassette('ingest_recipes/paginate_next') do
170
+ pager = described_class.paginate(per_page: 1)
171
+ pager.next
172
+ ids = pager.collection.map { |recipe| recipe.id }
173
+ expect(ids).to match_array [2]
174
+ end
175
+ end
176
+
177
+ it 'loads the recipe collection' do
178
+ VCR.use_cassette('ingest_recipes/paginate_last') do
179
+ pager = described_class.paginate(per_page: 1)
180
+ pager.last
181
+ ids = pager.collection.map { |recipe| recipe.id }
182
+ expect(ids).to match_array [7]
183
+ end
184
+ end
185
+
186
+ it 'loads the recipe collection' do
187
+ VCR.use_cassette('ingest_recipes/paginate_previous') do
188
+ pager = described_class.paginate(page: 4, per_page: 1)
189
+ pager.previous
190
+ ids = pager.collection.map { |recipe| recipe.id }
191
+ expect(ids).to match_array [3]
192
+ end
193
+ end
194
+ end
195
+
196
+ end
197
+ end
@@ -0,0 +1,28 @@
1
+ module VzaarApi
2
+ module Lib
3
+ describe Api do
4
+
5
+ before do
6
+ VzaarApi.auth_token = auth_token
7
+ VzaarApi.client_id = client_id
8
+ VzaarApi.hostname = hostname
9
+ end
10
+
11
+ let(:auth_token) { 'auth-token' }
12
+ let(:client_id) { 'client-id' }
13
+ let(:hostname) { 'app.vzaar.localhost' }
14
+
15
+ describe '#headers' do
16
+ let(:expected_result) do
17
+ {
18
+ 'X-Auth-Token' => auth_token,
19
+ 'X-Client-Id' => client_id,
20
+ 'Content-Type' => 'application/json'
21
+ }
22
+ end
23
+ specify { expect(subject.headers).to eq expected_result }
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,97 @@
1
+ module VzaarApi
2
+ describe Playlist do
3
+
4
+ before { setup_auth! }
5
+
6
+ describe '.find' do
7
+ context 'when the playlist can be found' do
8
+ it 'finds the playlist' do
9
+ VCR.use_cassette 'playlists/find' do
10
+ playlist = described_class.find(12692)
11
+ expect(playlist.id).to eq 12692
12
+ expect(playlist.category_id).to eq 2253
13
+ expect(playlist.max_vids).to eq 43
14
+ expect(playlist.title).to eq 'test'
15
+ expect(playlist.sort_by).to eq 'created_at'
16
+ expect(playlist.sort_order).to eq 'desc'
17
+ expect(playlist.private).to be_falsey
18
+ expect(playlist.dimensions).to eq '768x340'
19
+ expect(playlist.position).to eq 'right'
20
+ expect(playlist.autoplay).to be_truthy
21
+ expect(playlist.continuous_play).to be_truthy
22
+ expect(playlist.embed_code).to match(
23
+ "<iframe id=\"vzpl-12692\" name=\"vzpl-12692\" " \
24
+ "title=\"vzaar video player\" class=\"vzaar video player\" " \
25
+ "type=\"text/html\" width=\"927\" height=\"340\" frameborder=\"0\" " \
26
+ "allowFullScreen allowTransparency=\"true\" mozallowfullscreen " \
27
+ "webkitAllowFullScreen src=\"//view.vzaar.localhost/playlists/12692\">" \
28
+ "</iframe>"
29
+ )
30
+ expect(playlist.created_at).to eq "2017-04-21T14:16:50.000Z"
31
+ expect(playlist.updated_at).to eq "2017-04-21T14:16:50.000Z"
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'when the playlist cannot be found' do
37
+ it 'raises an error' do
38
+ VCR.use_cassette('playlists/find_404') do
39
+ expect { described_class.find(-1) }.
40
+ to raise_error(Error, 'Not found: Resource cannot be found')
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.each_item' do
47
+ it 'loads the playlist collection' do
48
+ VCR.use_cassette('playlists/each_item') do
49
+ enum = described_class.each_item(per_page: 2)
50
+ ids = enum.map { |playlist| playlist.id }
51
+ expect(ids).to match_array [
52
+ 12, 1065, 12676, 12677, 12678, 12679, 12680, 12681, 12682, 12683,
53
+ 12684, 12685, 12686, 12687, 12688, 12689, 12691, 12692
54
+ ]
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '.paginate' do
60
+ it 'loads the playlist collection' do
61
+ VCR.use_cassette('playlists/paginate_first') do
62
+ pager = described_class.paginate(per_page: 3)
63
+ pager.first
64
+ ids = pager.collection.map { |playlist| playlist.id }
65
+ expect(ids).to match_array [12, 12676, 12677]
66
+ end
67
+ end
68
+
69
+ it 'loads the playlist collection' do
70
+ VCR.use_cassette('playlists/paginate_next') do
71
+ pager = described_class.paginate(per_page: 3)
72
+ pager.next
73
+ ids = pager.collection.map { |playlist| playlist.id }
74
+ expect(ids).to match_array [12678, 12679, 12680]
75
+ end
76
+ end
77
+
78
+ it 'loads the playlist collection' do
79
+ VCR.use_cassette('playlists/paginate_last') do
80
+ pager = described_class.paginate(per_page: 3)
81
+ pager.last
82
+ ids = pager.collection.map { |playlist| playlist.id }
83
+ expect(ids).to match_array [1065, 12691, 12692]
84
+ end
85
+ end
86
+
87
+ it 'loads the playlist collection' do
88
+ VCR.use_cassette('playlists/paginate_previous') do
89
+ pager = described_class.paginate(page: 4, per_page: 3)
90
+ pager.previous
91
+ ids = pager.collection.map { |playlist| playlist.id }
92
+ expect(ids).to match_array [12681, 12682, 12683]
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,55 @@
1
+ module VzaarApi
2
+ describe Rendition do
3
+
4
+ subject { described_class.new attrs }
5
+
6
+ let(:attrs) do
7
+ {
8
+ id: 'id',
9
+ encoding_preset_id: 'encoding_preset_id',
10
+ state: 'state',
11
+ source_as_rendition: 'source_as_rendition',
12
+ name: 'name',
13
+ output_format: 'output_format',
14
+ bitrate_kbps: 'bitrate_kbps',
15
+ width: 'width',
16
+ height: 'height',
17
+ video_codec: 'video_codec',
18
+ profile: 'profile',
19
+ frame_rate: 'frame_rate',
20
+ keyframe: 'keyframe',
21
+ audio_bitrate_kbps: 'audio_bitrate_kbps',
22
+ audio_channels: 'audio_channels',
23
+ audio_sample_rate: 'audio_sample_rate',
24
+ size_in_bytes: 'size_in_bytes',
25
+ error_message: 'error_message',
26
+ created_at: 'created_at',
27
+ updated_at: 'updated_at'
28
+ }
29
+ end
30
+
31
+ describe '#initialize' do
32
+ specify { expect(subject.id).to eq 'id' }
33
+ specify { expect(subject.encoding_preset_id).to eq 'encoding_preset_id' }
34
+ specify { expect(subject.state).to eq 'state' }
35
+ specify { expect(subject.source_as_rendition).to eq 'source_as_rendition' }
36
+ specify { expect(subject.name).to eq 'name' }
37
+ specify { expect(subject.output_format).to eq 'output_format' }
38
+ specify { expect(subject.bitrate_kbps).to eq 'bitrate_kbps' }
39
+ specify { expect(subject.width).to eq 'width' }
40
+ specify { expect(subject.height).to eq 'height' }
41
+ specify { expect(subject.video_codec).to eq 'video_codec' }
42
+ specify { expect(subject.profile).to eq 'profile' }
43
+ specify { expect(subject.frame_rate).to eq 'frame_rate' }
44
+ specify { expect(subject.keyframe).to eq 'keyframe' }
45
+ specify { expect(subject.audio_bitrate_kbps).to eq 'audio_bitrate_kbps' }
46
+ specify { expect(subject.audio_channels).to eq 'audio_channels' }
47
+ specify { expect(subject.audio_sample_rate).to eq 'audio_sample_rate' }
48
+ specify { expect(subject.size_in_bytes).to eq 'size_in_bytes' }
49
+ specify { expect(subject.error_message).to eq 'error_message' }
50
+ specify { expect(subject.created_at).to eq 'created_at' }
51
+ specify { expect(subject.updated_at).to eq 'updated_at' }
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,68 @@
1
+ module VzaarApi
2
+ module Signature
3
+ describe Factory do
4
+
5
+ subject { described_class.new attrs }
6
+
7
+ let(:attrs) do
8
+ { path: './spec/support/files/video-5.0MB.mp4' }
9
+ end
10
+
11
+ describe '.create' do
12
+ before do
13
+ allow(described_class).to receive(:new).with(attrs) { instance }
14
+ end
15
+
16
+ let(:instance) { double create: true }
17
+ let(:result) { described_class.create attrs }
18
+ specify { expect(result).to be true }
19
+ end
20
+
21
+ describe '#create' do
22
+ before do
23
+ allow(subject).to receive(:multipart?) { multipart }
24
+ allow(Multipart).to receive(:create).with(multipart_attrs) { 'multipart' }
25
+ allow(Single).to receive(:create).with(multipart_attrs) { 'single' }
26
+ end
27
+
28
+ let(:multipart_attrs) do
29
+ {
30
+ filesize: 5242880,
31
+ filename: 'video-5.0MB.mp4'
32
+ }
33
+ end
34
+
35
+ context 'when multipart' do
36
+ let(:multipart) { true }
37
+ specify { expect(subject.create).to eq 'multipart' }
38
+ end
39
+
40
+ context 'when single' do
41
+ let(:multipart) { false }
42
+ specify { expect(subject.create).to eq 'single' }
43
+ end
44
+ end
45
+
46
+ describe '#multipart?' do
47
+ context 'when multipart params are provided' do
48
+ let(:attrs) { { path: './spec/support/files/video-5.0MB.mp4' } }
49
+ specify { expect(subject.multipart?).to be true }
50
+ end
51
+
52
+ context 'when non-multipart params are provided' do
53
+ let(:attrs) { { path: './spec/support/files/video-4.9MB.mp4' } }
54
+ specify { expect(subject.multipart?).to be false }
55
+ end
56
+
57
+ context 'when invalid params are provided' do
58
+ let(:attrs) { { path: './no/file/here.mp4' } }
59
+ it 'raises an error' do
60
+ expect { subject.multipart? }.to raise_error(
61
+ Error, 'Invalid parameters: path is invalid')
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,81 @@
1
+ module VzaarApi
2
+ module Signature
3
+ describe Multipart do
4
+
5
+ before do
6
+ setup_auth!
7
+ end
8
+
9
+ describe '#initialize' do
10
+ subject { described_class.new attrs }
11
+
12
+ let(:attrs) do
13
+ {
14
+ access_key_id: 'access_key_id',
15
+ acl: 'acl',
16
+ bucket: 'bucket',
17
+ content_type: 'content_type',
18
+ guid: 'guid',
19
+ key: 'key',
20
+ policy: 'policy',
21
+ signature: 'signature',
22
+ success_action_status: 'success_action_status',
23
+ upload_hostname: 'upload_hostname',
24
+ part_size: 'part_size',
25
+ part_size_in_bytes: 'part_size_in_bytes',
26
+ parts: 'parts'
27
+ }
28
+ end
29
+
30
+ specify { expect(subject.access_key_id).to eq 'access_key_id' }
31
+ specify { expect(subject.acl).to eq 'acl' }
32
+ specify { expect(subject.bucket).to eq 'bucket' }
33
+ specify { expect(subject.content_type).to eq 'content_type' }
34
+ specify { expect(subject.guid).to eq 'guid' }
35
+ specify { expect(subject.key).to eq 'key' }
36
+ 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' }
39
+ specify { expect(subject.upload_hostname).to eq 'upload_hostname' }
40
+ specify { expect(subject.part_size).to eq 'part_size' }
41
+ specify { expect(subject.part_size_in_bytes).to eq 'part_size_in_bytes' }
42
+ specify { expect(subject.parts).to eq 'parts' }
43
+ end
44
+
45
+ describe '#create' do
46
+ context 'when successful' do
47
+ it 'builds a signature' do
48
+ 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
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'when unsuccessful' do
69
+ it 'raises an error' do
70
+ VCR.use_cassette('signature/multipart_422') do
71
+ attrs = { filename: 'video.mp4', filesize: nil, uploader: UPLOADER }
72
+ expect { described_class.create attrs }.
73
+ to raise_error(Error, 'Invalid parameters: Filesize must be between 5MB and 5TB')
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end