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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a66c41aa22b7ac34c00d55f887bd51e67f477326
4
+ data.tar.gz: aabba334cffe595e17690a893a0eabc8a5a0dc3f
5
+ SHA512:
6
+ metadata.gz: 8d39461adbe0756c34809fb76ca493fb1686d74ab3f4910c2cbfdb1340fc38255b5647f4d91c1cb10cdcd956e82146003f307659ec59ca7c4df97b1ad5d09c15
7
+ data.tar.gz: 4159a4a63fa90ef7f28306bd045fe6dda90828ee137bc2eaa7265cb158dc0e33870d5dc3b5245d273f2378dc39076a148f1732b28966945be56ec8fb37e4af71
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ .gemtags
5
+ .tags
6
+ api_envs.yml
7
+ Gemfile.lock
8
+ pkg/*
9
+ tmp
10
+ test*.rb
11
+ .ruby-gemset
12
+ .ruby-version
13
+ tags
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format Fuubar
3
+ --require vzaar_api_helper
4
+ --require spec_helper
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.2.5
3
+ - 2.3.1
data/Changelog ADDED
@@ -0,0 +1,50 @@
1
+ [2.0.0] 2017-07-13 Alan Oliver <alan@vzaar.com>
2
+
3
+ * Version 2.0.0 of the gem released, this gem version contains BREAKING
4
+ CHANGES.
5
+ * This gem uses version 2 of the vzaar API, providing a simpler, cleaner way
6
+ to interact with vzaar.
7
+ * The Gem has been fully rewritten to conform to the new API.
8
+ * You can see documentation of the new API at our new developer hub at
9
+ https://developer.vzaar.com/docs
10
+
11
+ [1.6.2] 2016-05-19 EJ <ed@vzaar.com>
12
+
13
+ * add metadata to signature API call and S3 uploads
14
+
15
+ [1.6.1] 2016-04-21 EJ <ed@vzaar.com>
16
+
17
+ * escape ampersands in filename when sending signature request
18
+
19
+ [1.6.0] 2016-03-03 EJ <ed@vzaar.com>
20
+
21
+ * support for chunked uploads
22
+
23
+ [1.5.3] 2015-07-07 Raz Itzhakian <raz.itzhakian@fiverr.com>
24
+
25
+ * timeout option added for API calls
26
+
27
+ [1.5.2] 2015-03-30 JC <jozef@vzaar.com>
28
+
29
+ * call CGI.escape against link_upload/url and video/seo_url params
30
+
31
+ [1.5.1] 2015-03-27 JC <jozef@vzaar.com>
32
+
33
+ * escaping special chars from xml added
34
+
35
+ 2015-02-19 JC <jozef@vzaar.com>
36
+
37
+ * renditions added to Vzaar::Resource::Video
38
+
39
+ 2015-02-16 JC <jozef@vzaar.com>
40
+
41
+ * private and seo_url params added to api#edit_video
42
+ * API specs improved for edit_video/json
43
+
44
+ 2015-01-21 JC <jozef@vzaar.com>
45
+
46
+ * API specs added for edit/delete http verbs
47
+
48
+ 2015-01-14 JC <jozef@vzaar.com>
49
+
50
+ * changelog added
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,25 @@
1
+ guard :rspec, cmd: "bundle exec rspec", all_on_start: true do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+ clearing :on
5
+
6
+ # Feel free to open issues for suggestions and improvements
7
+
8
+ # RSpec files
9
+ rspec = dsl.rspec
10
+ watch(rspec.spec_helper) { rspec.spec_dir }
11
+ watch(rspec.spec_support) { rspec.spec_dir }
12
+ watch(rspec.spec_files)
13
+
14
+ # Ruby files
15
+ ruby = dsl.ruby
16
+ dsl.watch_spec_files_for(ruby.lib_files)
17
+
18
+ watch(%r{^spec/.+_spec\.rb$})
19
+ watch(%r{^lib/vzaar_api.rb$}) { "spec" }
20
+ watch(%r{^lib/vzaar_api/(.+)\.rb$}) { "spec" }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
22
+
23
+ watch('spec/vzaar_api_helper.rb') { "spec" }
24
+ watch('spec/spec_helper.rb') { "spec" }
25
+ end
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # vzaar API
2
+
3
+ ![vzaar Logo](https://raw.github.com/vzaar/vzaar-api-ruby/master/vzaar.png)
4
+
5
+ By [vzaar](http://vzaar.com)
6
+
7
+ [![Build Status](https://secure.travis-ci.org/vzaar/vzaar-api-ruby.png)](http://travis-ci.org/vzaar/vzaar-api-ruby) [![Code Climate](https://codeclimate.com/github/vzaar/vzaar-api-ruby.png)](https://codeclimate.com/github/vzaar/vzaar-api-ruby)
8
+
9
+ vzaar's Ruby client for interacting with version 2 of the [vzaar API](https://vzaar.readme.io/docs).
10
+
11
+ ## Requirements
12
+
13
+ Ruby 2.2+
14
+
15
+ ## Installation
16
+
17
+ ```
18
+ gem install vzaar --version
19
+ ```
20
+
21
+
22
+ ## Backwards compatability
23
+
24
+ Versions 1 and 2 of the vzaar API are incompatable with each other. The same applies to the API SDKs. Some functionality available in the version 1 SDK has been deprecated in version 2 and will not be implemented. The version 2 API also has a different authentication mechanism so your existing API key will not work with version 2 SDKs.
25
+
26
+ To ease migration to the version 2 SDK, it is possible to use both versions without any conflicts.
27
+
28
+ ```
29
+ Vzaar # <= this is version 1
30
+ VzaarApi # <= this is version 2
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Configure your API credentials:
36
+
37
+ ```
38
+ VzaarApi.auth_token = '<your-auth-token>'
39
+ VzaarApi.client_id = '<your-client-id>'
40
+ ```
41
+
42
+ Usage instructions and examples are available on [vzaar's documentation site](https://vzaar.readme.io).
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+
53
+ ## License
54
+
55
+ Released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # uncomment these lines when this library is gemified
2
+ # require 'bundler/gem_tasks'
3
+ # Bundler::GemHelper.install_tasks
4
+
5
+ desc "Run all specs"
6
+ task :default do
7
+ exec 'rspec spec'
8
+ end
9
+
10
+ namespace :spec do
11
+ namespace :api do
12
+
13
+ task :dev do
14
+ exec 'API_ENV=development bundle exec rspec examples'
15
+ end
16
+
17
+ task :qa do
18
+ exec 'API_ENV=qa bundle exec rspec examples'
19
+ end
20
+
21
+ task :prod do
22
+ exec 'API_ENV=production bundle exec rspec examples'
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ # Integration specs
2
+
3
+ ## Setup
4
+
5
+ Copy the `api_envs.yml.example` file into the root of this repository.
6
+
7
+ ```
8
+ cp examples/api_envs.yml.example api_envs.yml
9
+ ```
10
+
11
+ Then edit your new file with the relevant information for the envionment you wish to target.
12
+ You will need the following to be setup in the relevant account:
13
+
14
+ 1. Your category should have at least 3 sub-categories.
15
+ 2. Ensure your account has access to the following encoding presets: `2, 3, 4, 5, 6`
16
+ 3. You need at least 2 ingest recipes.
17
+
18
+ ## Running the examples
19
+
20
+ From the root of this repository:
21
+
22
+ ```
23
+ # development
24
+ rake spec:api:dev
25
+
26
+ # prodcution
27
+ rake spec:api:prod
28
+ ```
29
+
30
+ ## Verifying the results
31
+
32
+ The `Video` examples will upload and process multiple videos. You should always check
33
+ that these videos actually encode as expected.
@@ -0,0 +1,31 @@
1
+ development:
2
+ hostname: app.vzaar.localhost
3
+ vd_hostname: view.vzaar.localhost
4
+ category_id:
5
+ encoding_preset_id:
6
+ ingest_recipe:
7
+ default:
8
+ other:
9
+
10
+ account_owner:
11
+ auth_token:
12
+ client_id:
13
+
14
+ intruder:
15
+ auth_token: some-secret
16
+ client_id: naughty
17
+
18
+ production:
19
+ category_id:
20
+ encoding_preset_id:
21
+ ingest_recipe:
22
+ default:
23
+ other:
24
+
25
+ account_owner:
26
+ auth_token:
27
+ client_id:
28
+
29
+ intruder:
30
+ auth_token: some-secret
31
+ client_id: naughty
@@ -0,0 +1,100 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Category: Create / Update / Delete' do
5
+
6
+ let(:described_class) { Category }
7
+
8
+ context 'when user is authenticated' do
9
+ before { setup_for :account_owner }
10
+
11
+ let(:attrs) { { name: 'new SDK category' } }
12
+
13
+ it 'creates, updates and deletes a resource' do
14
+ # name is required
15
+ expect{described_class.create}.to raise_error(
16
+ Error, "Invalid parameters: name is missing"
17
+ )
18
+
19
+ # create new category tree
20
+ category = described_class.create attrs
21
+ expect(category.name).to eq 'new SDK category'
22
+ expect(category.parent_id).to be_nil
23
+ expect(category.depth).to eq 0
24
+
25
+ subcategory = described_class.create attrs.merge(parent_id: category.id)
26
+ expect(subcategory.name).to eq 'new SDK category'
27
+ expect(subcategory.parent_id).to eq category.id
28
+ expect(subcategory.depth).to eq 1
29
+
30
+ subsubcategory = described_class.create attrs.merge(parent_id: subcategory.id)
31
+ expect(subsubcategory.name).to eq 'new SDK category'
32
+ expect(subsubcategory.parent_id).to eq subcategory.id
33
+ expect(subsubcategory.depth).to eq 2
34
+
35
+ expect(described_class.find(category.id).tree_children_count).to eq 2
36
+ expect(described_class.find(category.id).node_children_count).to eq 1
37
+ expect(described_class.find(subcategory.id).node_children_count).to eq 1
38
+
39
+ # can't create subcategories deeper than account will allow
40
+ expect{
41
+ described_class.create(attrs.merge(parent_id: subsubcategory.id))
42
+ }.to raise_error(
43
+ Error, 'Invalid parameters: Validation failed: Category depth must not exceed 3'
44
+ )
45
+
46
+ # perform update
47
+ name = "updated at: #{Time.now.utc}"
48
+ category.name = name
49
+ category.save
50
+ expect(category.name).to eq name
51
+
52
+ # move category and children to top level
53
+ subcategory.move_to_root = true
54
+ subcategory.save
55
+ expect(subcategory.parent_id).to be_nil
56
+ expect(subcategory.depth).to eq 0
57
+ expect(described_class.find(subsubcategory.id).depth).to eq 1
58
+ expect(described_class.find(category.id).node_children_count).to eq 0
59
+
60
+ expect(described_class.find(category.id).tree_children_count).to eq 0
61
+ expect(described_class.find(category.id).node_children_count).to eq 0
62
+ expect(described_class.find(subcategory.id).node_children_count).to eq 1
63
+
64
+ # move category and children to a new parent
65
+ subcategory.parent_id = category.id
66
+ subcategory.save
67
+ expect(subcategory.parent_id).to eq category.id
68
+ expect(subcategory.depth).to eq 1
69
+ expect(subsubcategory.depth).to eq 2
70
+
71
+ expect(described_class.find(category.id).tree_children_count).to eq 2
72
+ expect(described_class.find(category.id).node_children_count).to eq 1
73
+ expect(described_class.find(subcategory.id).node_children_count).to eq 1
74
+
75
+ # can't move if it will exceed category depth limit
76
+ new_cat = described_class.create(attrs)
77
+ new_cat.parent_id = subsubcategory.id
78
+ expect{new_cat.save}.to raise_error(
79
+ Error, 'Invalid parameters: Category depth must not exceed 3'
80
+ )
81
+
82
+ # delete categories
83
+ subsubcategory.delete
84
+ expect{ described_class.find(subsubcategory.id) }.to raise_error(
85
+ Error, 'Not found: Resource cannot be found')
86
+
87
+ # deleting parent deletes children
88
+ category.delete
89
+ expect{ described_class.find(category.id) }.to raise_error(
90
+ Error, 'Not found: Resource cannot be found')
91
+
92
+ expect{ described_class.find(subcategory.id) }.to raise_error(
93
+ Error, 'Not found: Resource cannot be found')
94
+
95
+ new_cat.delete # keep things tidy
96
+ end
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Category: List' do
5
+
6
+ let(:described_class) { Category }
7
+
8
+ context 'when user is authenticated' do
9
+ before { setup_for :account_owner }
10
+
11
+ describe '#each_item' do
12
+ it 'retrieves the resource list' do
13
+ ids = described_class.each_item.map(&:id)
14
+ expect(ids).not_to be_empty
15
+ end
16
+ end
17
+
18
+ describe '#paginate' do
19
+ let(:pager) { described_class.paginate(page: 2, per_page: 1) }
20
+ specify { expect(pager.first.count).to eq 1 }
21
+ specify { expect(pager.next.count).to eq 1 }
22
+ specify { expect(pager.previous.count).to eq 1 }
23
+ specify { expect(pager.last.count).to eq 1 }
24
+ end
25
+ end
26
+
27
+ context 'when user is not authenticated' do
28
+ before { setup_for :intruder }
29
+
30
+ it 'raises an error' do
31
+ pager = described_class.paginate
32
+ expect{ pager.first }.to raise_error(
33
+ Error, 'Authentication failed: Invalid credentials')
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Category: List' do
5
+
6
+ let(:described_class) { Category }
7
+
8
+ let(:category) { described_class.find(id) }
9
+ let(:id) { api_envs['category_id'] }
10
+
11
+ context 'when user is authenticated' do
12
+ before { setup_for :account_owner }
13
+
14
+ describe '#each_item' do
15
+ it 'retrieves the resource list' do
16
+ ids = category.subtree.each_item.map(&:id)
17
+ expect(ids).not_to be_empty
18
+ end
19
+ end
20
+
21
+ describe '#paginate' do
22
+ let(:pager) { category.subtree(page: 2, per_page: 1) }
23
+ specify { expect(pager.first.count).to eq 1 }
24
+ specify { expect(pager.next.count).to eq 1 }
25
+ specify { expect(pager.previous.count).to eq 1 }
26
+ specify { expect(pager.last.count).to eq 1 }
27
+ end
28
+ end
29
+
30
+ context 'when user is not authenticated' do
31
+ before { setup_for :intruder }
32
+
33
+ it 'raises an error' do
34
+ expect{ category.subtree }.to raise_error(
35
+ Error, 'Authentication failed: Invalid credentials')
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Category: Lookup' do
5
+
6
+ let(:described_class) { Category }
7
+ let(:id) { api_envs['category_id'] }
8
+
9
+ context 'when user is authenticated' do
10
+ before { setup_for :account_owner }
11
+
12
+ context 'and resource can be found' do
13
+ subject { described_class.find(id) }
14
+ specify { expect(subject.id).to eq id }
15
+ end
16
+
17
+ context 'and resource cannot be found' do
18
+ it 'raises an error' do
19
+ expect{ described_class.find(-1) }.to raise_error(
20
+ Error, 'Not found: Resource cannot be found')
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'when user is not authenticated' do
26
+ before { setup_for :intruder }
27
+
28
+ it 'raises an error' do
29
+ expect{ described_class.find(id) }.to raise_error(
30
+ Error, 'Authentication failed: Invalid credentials')
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Encoding preset: List' do
5
+
6
+ let(:described_class) { EncodingPreset }
7
+
8
+ context 'when user is authenticated' do
9
+ before { setup_for :account_owner }
10
+
11
+ describe '#each_item' do
12
+ it 'retrieves the resource list' do
13
+ ids = described_class.each_item.map(&:id)
14
+ expect(ids).not_to be_empty
15
+ end
16
+ end
17
+
18
+ describe '#paginate' do
19
+ let(:pager) { described_class.paginate(page: 2, per_page: 1) }
20
+ specify { expect(pager.first.count).to eq 1 }
21
+ specify { expect(pager.next.count).to eq 1 }
22
+ specify { expect(pager.previous.count).to eq 1 }
23
+ specify { expect(pager.last.count).to eq 1 }
24
+ end
25
+ end
26
+
27
+ context 'when user is not authenticated' do
28
+ before { setup_for :intruder }
29
+
30
+ it 'raises an error' do
31
+ pager = described_class.paginate
32
+ expect{ pager.first }.to raise_error(
33
+ Error, 'Authentication failed: Invalid credentials')
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Encoding preset: Lookup' do
5
+
6
+ let(:described_class) { EncodingPreset }
7
+ let(:id) { api_envs['encoding_preset_id'] }
8
+
9
+ context 'when user is authenticated' do
10
+ before { setup_for :account_owner }
11
+
12
+ context 'and resource can be found' do
13
+ subject { described_class.find(id) }
14
+ specify { expect(subject.id).to eq id }
15
+ end
16
+
17
+ context 'and resource cannot be found' do
18
+ it 'raises an error' do
19
+ expect{ described_class.find(-1) }.to raise_error(
20
+ Error, 'Not found: Resource cannot be found')
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'when user is not authenticated' do
26
+ before { setup_for :intruder }
27
+
28
+ it 'raises an error' do
29
+ expect{ described_class.find(id) }.to raise_error(
30
+ Error, 'Authentication failed: Invalid credentials')
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,70 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Ingest recipe: Create / Update / Delete' do
5
+
6
+ let(:described_class) { IngestRecipe }
7
+ let(:id) { api_envs['ingest_recipe']['default'] }
8
+ let(:other_id) { api_envs['ingest_recipe']['other'] }
9
+
10
+ context 'when user is authenticated' do
11
+ before { setup_for :account_owner }
12
+
13
+ let(:attrs) do
14
+ {
15
+ name: 'new SDK recipe',
16
+ description: 'created by the SDK tests',
17
+ default: true,
18
+ frame_grab_time: 5.5,
19
+ multipass: false,
20
+ generate_animated_thumb: true,
21
+ generate_sprite: true,
22
+ use_watermark: true,
23
+ send_to_youtube: true,
24
+ encoding_preset_ids: [2, 3, 4]
25
+ }
26
+ end
27
+
28
+ it 'creates, updates and deletes a resource' do
29
+ # create new recipe
30
+ recipe = described_class.create attrs
31
+ expect(recipe.name).to eq 'new SDK recipe'
32
+ expect(recipe.default).to eq true
33
+ expect(recipe.encoding_presets.map(&:id)).to match_array [2, 3, 4]
34
+
35
+ # ensure previous default has changed
36
+ expect(described_class.find(id).default).to eq false
37
+
38
+ # perform update
39
+ name = "updated at: #{Time.now.utc}"
40
+ recipe.name = name
41
+ recipe.encoding_preset_ids = [4, 5, 6]
42
+ recipe.save
43
+ expect(recipe.name).to eq name
44
+ expect(recipe.encoding_presets.map(&:id)).to match_array [4, 5, 6]
45
+
46
+ # ensure you cannot unset current default
47
+ recipe.default = false
48
+ expect { recipe.save }.to raise_error(
49
+ Error, 'Invalid parameters: You cannot unflag your default ingest recipe')
50
+
51
+ # restore previous default
52
+ default = described_class.find(id)
53
+ expect(recipe.default).to eq false
54
+ default.default = true
55
+ default.save
56
+ expect(default.default).to eq true
57
+
58
+ # reload original recipe
59
+ recipe = described_class.find(recipe.id)
60
+ expect(recipe.default).to eq false
61
+
62
+ # delete recipe
63
+ recipe.delete
64
+ expect{ described_class.find(recipe.id) }.to raise_error(
65
+ Error, 'Not found: Resource cannot be found')
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './../spec_helper'
2
+
3
+ module VzaarApi
4
+ describe 'Ingest recipe: List' do
5
+
6
+ let(:described_class) { IngestRecipe }
7
+
8
+ context 'when user is authenticated' do
9
+ before { setup_for :account_owner }
10
+
11
+ describe '#each_item' do
12
+ it 'retrieves the resource list' do
13
+ ids = described_class.each_item.map(&:id)
14
+ expect(ids).not_to be_empty
15
+ end
16
+ end
17
+
18
+ describe '#paginate' do
19
+ let(:pager) { described_class.paginate(page: 2, per_page: 1) }
20
+ specify { expect(pager.first.count).to eq 1 }
21
+ specify { expect(pager.next.count).to eq 1 }
22
+ specify { expect(pager.previous.count).to eq 1 }
23
+ specify { expect(pager.last.count).to eq 1 }
24
+ end
25
+ end
26
+
27
+ context 'when user is not authenticated' do
28
+ before { setup_for :intruder }
29
+
30
+ it 'raises an error' do
31
+ pager = described_class.paginate
32
+ expect{ pager.first }.to raise_error(
33
+ Error, 'Authentication failed: Invalid credentials')
34
+ end
35
+ end
36
+
37
+ end
38
+ end