vzaar_api 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,72 @@
1
+ module VzaarApi
2
+ module Signature
3
+ describe Single 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
+ }
25
+ end
26
+
27
+ specify { expect(subject.access_key_id).to eq 'access_key_id' }
28
+ specify { expect(subject.acl).to eq 'acl' }
29
+ specify { expect(subject.bucket).to eq 'bucket' }
30
+ specify { expect(subject.content_type).to eq 'content_type' }
31
+ specify { expect(subject.guid).to eq 'guid' }
32
+ specify { expect(subject.key).to eq 'key' }
33
+ specify { expect(subject.policy).to eq 'policy' }
34
+ specify { expect(subject.signature).to eq 'signature' }
35
+ specify { expect(subject.success_action_status).to eq 'success_action_status' }
36
+ specify { expect(subject.upload_hostname).to eq 'upload_hostname' }
37
+ end
38
+
39
+ describe '#create' do
40
+ context 'when successful' do
41
+ it 'builds a signature' do
42
+ 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
+ end
56
+ end
57
+ end
58
+
59
+ context 'when unsuccessful' do
60
+ it 'raises an error' do
61
+ VCR.use_cassette('signature/single_422') do
62
+ attrs = { filename: 'video.mp4' }
63
+ expect { described_class.create attrs }.
64
+ to raise_error(Error, 'Invalid parameters: uploader is missing')
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,112 @@
1
+ module VzaarApi
2
+ module Upload
3
+ describe S3 do
4
+
5
+ subject { described_class.new attrs, signature }
6
+
7
+ describe '#execute' do
8
+ context 'when multipart' do
9
+ let(:attrs) do
10
+ { path: 'spec/support/files/video-12.0MB.mp4', title: 'video-title' }
11
+ end
12
+
13
+ let(:signature_attrs) do
14
+ {
15
+ access_key_id: 'access_key_id',
16
+ key: 'vzaar/t22/063/source/t22063bd228834adc8b9c7d5fb320b2b3o/${filename}',
17
+ acl: 'private',
18
+ policy: 'policy',
19
+ signature: 'signature',
20
+ success_action_status: '201',
21
+ content_type: 'binary/octet-stream',
22
+ guid: 't22063bd228834adc8b9c7d5fb320b2b3o',
23
+ bucket: 'vzaar-upload-development',
24
+ upload_hostname: 'https://vzaar-upload-development.s3.amazonaws.com',
25
+ part_size: '5MB',
26
+ part_size_in_bytes: 5242880,
27
+ parts: 3
28
+ }
29
+ end
30
+
31
+ let(:signature) { Signature::Multipart.new signature_attrs.merge(signature_attrs) }
32
+
33
+ context 'when successful' do
34
+ let(:expected_result) do
35
+ { guid: 't22063bd228834adc8b9c7d5fb320b2b3o', title: 'video-title' }
36
+ end
37
+
38
+ it 'uploads the video file' do
39
+ VCR.use_cassette('upload/multipart_201') do
40
+ expect(subject.execute).to eq expected_result
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'when unsuccessful' do
46
+ it 'handles an AWS 403 error' do
47
+ VCR.use_cassette('upload/multipart_403') do
48
+ expect { subject.execute }.to raise_error(
49
+ Error, 'The AWS Access Key Id you provided does not exist in our records.')
50
+ end
51
+ end
52
+
53
+ it 'handles an unexpected error' do
54
+ allow(subject).to receive(:http_client).and_raise(SocketError, 'error message')
55
+ expect { subject.execute }.to raise_error(Error, 'error message')
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'when single' do
61
+ let(:attrs) do
62
+ { path: 'spec/support/files/video-1.0MB.mp4', title: 'video-title' }
63
+ end
64
+
65
+ let(:signature_attrs) do
66
+ {
67
+ access_key_id: 'access_key_id',
68
+ key: "vzaar/t20/d72/source/t20d722afb9294989bda5f7cf01b11346v/${filename}",
69
+ acl: 'private',
70
+ policy: 'policy',
71
+ signature: 'signature',
72
+ success_action_status: "201",
73
+ content_type: "binary/octet-stream",
74
+ guid: "t20d722afb9294989bda5f7cf01b11346v",
75
+ bucket: "vzaar-upload-development",
76
+ upload_hostname: "https://vzaar-upload-development.s3.amazonaws.com"
77
+ }
78
+ end
79
+
80
+ let(:signature) { Signature::Single.new signature_attrs }
81
+
82
+ context 'when successful' do
83
+ let(:expected_result) do
84
+ { guid: 't20d722afb9294989bda5f7cf01b11346v', title: 'video-title' }
85
+ end
86
+
87
+ it 'uploads the video file' do
88
+ VCR.use_cassette('upload/single_201') do
89
+ expect(subject.execute).to eq expected_result
90
+ end
91
+ end
92
+ end
93
+
94
+ context 'when unsuccessful' do
95
+ it 'handles an AWS 403 error' do
96
+ VCR.use_cassette('upload/single_403') do
97
+ expect { subject.execute }.to raise_error(
98
+ Error, 'The AWS Access Key Id you provided does not exist in our records.')
99
+ end
100
+ end
101
+
102
+ it 'handles an unexpected error' do
103
+ allow(subject).to receive(:http_client).and_raise(SocketError, 'error message')
104
+ expect { subject.execute }.to raise_error(Error, 'error message')
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,248 @@
1
+ module VzaarApi
2
+ describe Video do
3
+
4
+ before do
5
+ setup_auth!
6
+ end
7
+
8
+ describe '#initialize' do
9
+ subject { described_class.new attrs }
10
+
11
+ let(:attrs) do
12
+ {
13
+ id: 'id',
14
+ title: 'title',
15
+ user_id: 'user_id',
16
+ account_id: 'account_id',
17
+ description: 'description',
18
+ private: 'private',
19
+ seo_url: 'seo_url',
20
+ url: 'url',
21
+ thumbnail_url: 'thumbnail_url',
22
+ state: 'state',
23
+ categories: categories,
24
+ renditions: renditions,
25
+ created_at: 'created_at',
26
+ updated_at: 'updated_at',
27
+ }
28
+ end
29
+
30
+ let(:categories) do
31
+ [ { id: 'category-id' } ]
32
+ end
33
+
34
+ let(:renditions) do
35
+ [ { id: 'rendition-id' } ]
36
+ end
37
+
38
+ specify { expect(subject.id).to eq 'id' }
39
+ specify { expect(subject.title).to eq 'title' }
40
+ specify { expect(subject.user_id).to eq 'user_id' }
41
+ specify { expect(subject.account_id).to eq 'account_id' }
42
+ specify { expect(subject.description).to eq 'description' }
43
+ specify { expect(subject.private).to eq 'private' }
44
+ specify { expect(subject.seo_url).to eq 'seo_url' }
45
+ specify { expect(subject.url).to eq 'url' }
46
+ specify { expect(subject.thumbnail_url).to eq 'thumbnail_url' }
47
+ specify { expect(subject.state).to eq 'state' }
48
+ specify { expect(subject.categories.first.id).to eq 'category-id' }
49
+ specify { expect(subject.renditions.first.id).to eq 'rendition-id' }
50
+ specify { expect(subject.created_at).to eq 'created_at' }
51
+ specify { expect(subject.updated_at).to eq 'updated_at' }
52
+ end
53
+
54
+ describe 'description' do
55
+ let(:video) do
56
+ VCR.use_cassette('videos/find') do
57
+ described_class.find(7574982)
58
+ end
59
+ end
60
+
61
+ context 'when nothing has changed' do
62
+ let(:changed) { [] }
63
+ let(:changed_attributes) { {} }
64
+ let(:changes) { {} }
65
+
66
+ specify { expect(video).not_to be_changed }
67
+ specify { expect(video.changed).to match_array changed }
68
+ specify { expect(video.changed_attributes).to eq changed_attributes }
69
+ specify { expect(video.changes).to eq changes }
70
+ end
71
+
72
+ context 'when attributes have changed' do
73
+ before do
74
+ video.title = 'new-title'
75
+ video.description = 'new-desc'
76
+ end
77
+
78
+ let(:changed) { [:title, :description] }
79
+ let(:changed_attributes) { { title: 'new-title', description: 'new-desc'} }
80
+ let(:changes) { { title: %w(video-mp4 new-title), description: %w(description new-desc)} }
81
+
82
+ specify { expect(video).to be_changed }
83
+ specify { expect(video.changed).to match_array changed }
84
+ specify { expect(video.changed_attributes).to eq changed_attributes }
85
+ specify { expect(video.changes).to eq changes }
86
+ end
87
+ end
88
+
89
+ describe '.find' do
90
+ context 'when the video can be found' do
91
+ it 'finds the video' do
92
+ VCR.use_cassette('videos/find') do
93
+ video = described_class.find(7574982)
94
+ expect(video.id).to eq 7574982
95
+ expect(video.title).to eq 'video-mp4'
96
+ expect(video.user_id).to eq 79357
97
+ expect(video.account_id).to eq 79357
98
+ expect(video.description).to eq 'description'
99
+ expect(video.private).to eq false
100
+ expect(video.seo_url).to eq 'seo-url'
101
+ expect(video.url).to eq 'video-url'
102
+ expect(video.thumbnail_url).to eq 'https://view.vzaar.localhost/7574982/thumb'
103
+ expect(video.state).to eq 'ready'
104
+ expect(video.categories.count).to eq 2
105
+ expect(video.renditions.count).to eq 8
106
+ expect(video.legacy_renditions.count).to eq 8
107
+ expect(video.created_at).to eq '2016-12-01T17:27:12.000Z'
108
+ expect(video.updated_at).to eq '2017-01-30T12:49:41.000Z'
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'when the video cannot be found' do
114
+ it 'raises an error' do
115
+ VCR.use_cassette('videos/find_404') do
116
+ expect { described_class.find(-1) }.
117
+ to raise_error(Error, 'Not found: Resource cannot be found')
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '.create' do
124
+ context 'when we already have the guid' do
125
+ let(:attrs) do
126
+ { guid: 't8dec9434bcc64622b68d1dc16f3ddffap' }
127
+ end
128
+
129
+ context 'and a new video is created' do
130
+ it 'returns the new video' do
131
+ VCR.use_cassette('videos/create/guid_201') do
132
+ video = described_class.create(attrs)
133
+ expect(video.id).to eq 7574982
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'and the video has already been created' do
139
+ it 'raises an error' do
140
+ VCR.use_cassette('videos/create/guid_error') do
141
+ expect { described_class.create attrs }.to raise_error(
142
+ Error, 'Invalid parameters: The provided guid already exists')
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ context 'when we have a file path' do
149
+ let(:attrs) do
150
+ { path: 'spec/support/files/video-1.0MB.mp4', title: 'video' }
151
+ end
152
+
153
+ context 'and a new video is created' do
154
+ it 'returns the new video' do
155
+ VCR.use_cassette('videos/create/path_201') do
156
+ video = described_class.create(attrs)
157
+ expect(video.id).to eq 7574827
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ context 'when we provide a url' do
164
+ let(:attrs) do
165
+ { url: 'http://example.com/video.mp4', uploader: UPLOADER }
166
+ end
167
+
168
+ context 'and a new video is created' do
169
+ it 'returns the new video' do
170
+ VCR.use_cassette('videos/create/link_201') do
171
+ video = described_class.create(attrs)
172
+ expect(video.id).to eq 7574826
173
+ end
174
+ end
175
+ end
176
+
177
+ context 'and invalid params are provided' do
178
+ it 'raises an error' do
179
+ VCR.use_cassette('videos/create/link_error') do
180
+ attrs.delete :uploader
181
+ expect { described_class.create attrs }.to raise_error(
182
+ Error, 'Invalid parameters: uploader is missing')
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ context 'when invalid params are provided' do
189
+ it 'raises an error' do
190
+ expect { described_class.create }.to raise_error(
191
+ Error, 'Invalid parameters: Expected one of :guid, :path, :url')
192
+ end
193
+ end
194
+ end
195
+
196
+ describe '#delete' do
197
+ context 'when video is deleted successfully' do
198
+ it 'returns true' do
199
+ VCR.use_cassette('videos/delete_204') do
200
+ video = described_class.find(7574985)
201
+ expect(video.delete).to eq true
202
+ expect { described_class.find(7574985) }.
203
+ to raise_error(Error, 'Not found: Resource cannot be found')
204
+ end
205
+ end
206
+ end
207
+ end
208
+
209
+ describe '.paginate' do
210
+ it 'loads the video collection' do
211
+ VCR.use_cassette('videos/paginate_first') do
212
+ pager = described_class.paginate(per_page: 3)
213
+ pager.first
214
+ ids = pager.collection.map { |video| video.id }
215
+ expect(ids).to match_array [7574851, 7574852, 7574853]
216
+ end
217
+ end
218
+
219
+ it 'loads the video collection' do
220
+ VCR.use_cassette('videos/paginate_next') do
221
+ pager = described_class.paginate(per_page: 3)
222
+ pager.next
223
+ ids = pager.collection.map { |video| video.id }
224
+ expect(ids).to match_array [7574848, 7574849, 7574850]
225
+ end
226
+ end
227
+
228
+ it 'loads the video collection' do
229
+ VCR.use_cassette('videos/paginate_last') do
230
+ pager = described_class.paginate(per_page: 3)
231
+ pager.last
232
+ ids = pager.collection.map { |video| video.id }
233
+ expect(ids).to match_array [927938, 935900]
234
+ end
235
+ end
236
+
237
+ it 'loads the video collection' do
238
+ VCR.use_cassette('videos/paginate_previous') do
239
+ pager = described_class.paginate(page: 4, per_page: 3)
240
+ pager.previous
241
+ ids = pager.collection.map { |video| video.id }
242
+ expect(ids).to match_array [7574844, 7574845, 7574847]
243
+ end
244
+ end
245
+ end
246
+
247
+ end
248
+ end
@@ -0,0 +1,18 @@
1
+ describe VzaarApi do
2
+
3
+ before do
4
+ VzaarApi.auth_token = auth_token
5
+ VzaarApi.client_id = client_id
6
+ VzaarApi.hostname = hostname
7
+ end
8
+
9
+ let(:auth_token) { 'auth-token' }
10
+ let(:client_id) { 'client-id' }
11
+ let(:hostname) { 'app.vzaar.localhost' }
12
+
13
+ specify { expect(VzaarApi.auth_token).to eq auth_token }
14
+ specify { expect(VzaarApi.client_id).to eq client_id }
15
+ specify { expect(VzaarApi.hostname).to eq hostname }
16
+ specify { expect(VzaarApi.protocol).to eq 'https' }
17
+
18
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'vzaar_api'
5
+ require 'vcr'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |c|
12
+ c.include Helpers
13
+ end
14
+
15
+ VCR.configure do |c|
16
+ c.default_cassette_options = { :match_requests_on => [:uri, :method] }
17
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
18
+ c.hook_into :webmock
19
+ end
data/vzaar.png ADDED
Binary file
data/vzaar_api.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/vzaar_api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'vzaar_api'
6
+ s.version = VzaarApi::VERSION
7
+ s.authors = ['vzaar']
8
+ s.email = ['support@vzaar.com']
9
+ s.description = 'A Ruby gem for the vzaar API v2'
10
+ s.summary = "vzaar-#{s.version}"
11
+ s.homepage = 'http://vzaar.com'
12
+ s.license = 'MIT'
13
+
14
+ s.platform = Gem::Platform::RUBY
15
+ s.required_ruby_version = '>= 2.0'
16
+ s.rubygems_version = ">= 2.5"
17
+
18
+ s.files = `git ls-files`.split($/)
19
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ s.test_files = s.files.grep(%r{^(spec)/})
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_dependency 'httpclient', '~> 2.8'
24
+ s.add_dependency 'request_store', '~> 1.3'
25
+
26
+ s.add_development_dependency 'bundler', '~> 1.3'
27
+ s.add_development_dependency 'fuubar', '~> 2.2'
28
+ s.add_development_dependency 'rake', '~> 10.5'
29
+ s.add_development_dependency 'growl', '~> 1.0'
30
+ s.add_development_dependency 'guard-rspec', '~> 4.6'
31
+ s.add_development_dependency 'pry-byebug', '~> 3.4'
32
+ s.add_development_dependency 'rspec', '~> 3.1'
33
+ s.add_development_dependency 'vcr', '~> 3.0'
34
+ s.add_development_dependency 'webmock', '~> 2.1'
35
+ end