vzaar 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ead17a9da83c804eed68c6c5216fcfc2a829a4b
4
- data.tar.gz: 7e4937420e0b0d14218869924fb5c1427e85aff7
3
+ metadata.gz: a0f8c545d337aa9a7a6ac806dbaf953b94626c11
4
+ data.tar.gz: fbf6792107a9b92b0db766751513d556daa99667
5
5
  SHA512:
6
- metadata.gz: ff7a580c3554b96b9b680e18416fa5af97b93636e214d487eaef344832d89ec2f639770674dc50340cb0ab087f1c2b2eec620a438332f5df25315cca73d1229d
7
- data.tar.gz: c2400435c3e52772e60e09861a30b295a94cafa5dc271c0579ab1e011639e02bdaaebc85984b0050a1df99c410fd19c94cee893ddf10e243fd8ae2ccbf1a5a63
6
+ metadata.gz: b6ad173b1e4851f03347435aae3a75b36ad4d4dab5405564c244ee712c7f6db36411eb742fe5cc8fed6c5786b6c291f32cb63a11c071a596a8fc001838943cfd
7
+ data.tar.gz: 872224645b46d7a36d2364f21d38e55e903e789f13c85d2ed47a5ba9975d5a09310f049b6ff7a63e3b67603f62174b2187a07fee5e3f5012eb4425256a50b124
data/.gitignore CHANGED
@@ -24,3 +24,4 @@ load.rb
24
24
  test.rb
25
25
  .tags
26
26
  .gemtags
27
+ api_envs.yml
data/README.md CHANGED
@@ -18,8 +18,7 @@ And then execute:
18
18
  ### Usage
19
19
 
20
20
  ```ruby
21
- conn = Vzaar::Connection.new(:application_token => "API token", :login => "vzaar login")
22
- api = Vzaar::Api.new(conn)
21
+ api = Vzaar::Api.new(application_token: "API token", login: "vzaar login")
23
22
  ```
24
23
 
25
24
  If your login and API token are correct, you should be able to fetch your login by calling:
data/Rakefile CHANGED
@@ -6,3 +6,13 @@ desc "Run all specs"
6
6
  task :default do
7
7
  exec 'rspec spec'
8
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
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Account Details" do
4
+ context "when user is unauthenticated" do
5
+ before(:all) do
6
+ api = unauthenticated_api()
7
+ @res = api.account_type(34)
8
+ end
9
+
10
+ it_behaves_like "200 OK"
11
+ specify { expect(@res.title).to eq("Staff") }
12
+ end
13
+ end
@@ -0,0 +1,55 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Add Subtitle" do
4
+ context "when user is unauthenticated" do
5
+ it_behaves_like "Unauthenticated", -> (api) do
6
+ api.add_subtitle(test_video_id("user1"), body: "x", language: "en")
7
+ end
8
+ end
9
+
10
+ context "Authenticated User" do
11
+ before(:all) do
12
+ @api = _api(login: user1["login"],
13
+ application_token: user1["rw_token"])
14
+ end
15
+
16
+ context "RW token" do
17
+ context "when params are valid" do
18
+ before(:all) do
19
+ @res = @api.add_subtitle(test_video_id("user1"), body: "SRT", language: "en")
20
+ end
21
+
22
+ it_behaves_like "202 Accepted"
23
+ end
24
+
25
+ context "when language param is blank" do
26
+ before(:all) do
27
+ @res = @api.add_subtitle(test_video_id("user1"), body: "SRT", language: "")
28
+ end
29
+
30
+ it_behaves_like "422 Failure"
31
+
32
+ specify { expect(@res.errors.first["language"]).to eq("empty string") }
33
+ end
34
+ end
35
+
36
+
37
+ context "RO token" do
38
+ it_behaves_like "RO only", user1["login"], user1["ro_token"], -> (api) do
39
+ api.add_subtitle(test_video_id("user1"), body: "SRT", language: "en")
40
+ end
41
+ end
42
+
43
+ context "when user doesn't have permission to the video" do
44
+ before(:all) do
45
+ @res = @api.add_subtitle(test_video_id("user2"), body: "SRT", language: "en")
46
+ end
47
+
48
+ it_behaves_like "422 Failure"
49
+
50
+ specify do
51
+ expect(@res.errors.first["user"]).to match(/Permission Denied/)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ development:
2
+ user1:
3
+ login: vz-account1
4
+ rw_token: cyCFbqQ4YTkrQhjFu7OZ2yoO3ol2avg79jRqWhKCpo
5
+ test_video_id: 1465464
6
+
7
+ user2:
8
+ login: vz-account2
9
+ rw_token: tnDyOtR0YPx6nKPdgw9MM35Cicm5y4ZZGNCglOtI
10
+ test_video_id: 1465488
@@ -0,0 +1,18 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Authentication" do
4
+ describe "whoami" do
5
+ context "when user is unauthenticated" do
6
+ it_behaves_like "Unauthenticated", -> (api) { api.whoami }
7
+ end
8
+
9
+ context "when auth success" do
10
+ specify do
11
+ api = _api(login: user1["login"],
12
+ application_token: user1["rw_token"])
13
+
14
+ expect(api.whoami).to eq(user1["login"])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Delete Video" do
4
+ vid_id = nil
5
+
6
+ before(:all) do
7
+ file_path = "./spec/support/video.mov"
8
+ desc = "Delete Video"
9
+ @api = _api(login: user1["login"],
10
+ application_token: user1["rw_token"])
11
+
12
+ @title = "api-test-#{rand_str}"
13
+
14
+ res = @api.upload_video(path: file_path, title: @title, description: desc)
15
+ vid_id = res.id
16
+ end
17
+
18
+ context "when user is unauthenticated" do
19
+ it_behaves_like "Unauthenticated", -> (api) do
20
+ api.delete_video(vid_id)
21
+ end
22
+ end
23
+
24
+ context "Authenticated User" do
25
+ context "RW token" do
26
+ before(:all) do
27
+ @res = @api.delete_video(vid_id)
28
+ end
29
+
30
+ specify { expect(@res.http_status_code).to eq 200 }
31
+ specify { expect(@res.title).to eq(@title) }
32
+ end
33
+
34
+ context "RO token" do
35
+ it_behaves_like "RO only", user1["login"], user1["ro_token"], -> (api) do
36
+ api.delete_video(vid_id)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Upload Thumbnail" do
4
+ context "when user is unauthenticated" do
5
+ it_behaves_like "Unauthenticated", -> (api) do
6
+ api.edit_video(test_video_id("user1"), title: "foo")
7
+ end
8
+ end
9
+
10
+ context "Authenticated User" do
11
+ context "RW token" do
12
+ before(:all) do
13
+ @api = _api(login: user1["login"],
14
+ application_token: user1["rw_token"])
15
+ end
16
+
17
+ describe "updating params" do
18
+ before(:all) do
19
+ @title = rand_str()
20
+ @desc = rand_str()
21
+ @res = @api.edit_video(test_video_id("user1"),
22
+ title: @title,
23
+ description: @desc)
24
+ end
25
+
26
+ it_behaves_like "200 OK"
27
+
28
+ specify { expect(@res.title).to eq(@title) }
29
+ specify { expect(@res.description).to eq(@desc) }
30
+ end
31
+ end
32
+
33
+ context "RO token" do
34
+ it_behaves_like "RO only", user1["login"], user1["ro_token"], -> (api) do
35
+ api.edit_video(test_video_id("user1"), title: "woof")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,65 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Generate Thumbnail" do
4
+ before(:all) do
5
+ @video_id = test_video_id("user1")
6
+ @video_id2 = test_video_id("user2")
7
+ end
8
+
9
+ context "when user is unauthenticated" do
10
+ it_behaves_like "Unauthenticated", -> (api) do
11
+ api.generate_thumbnail(test_video_id("user1"), time: 3)
12
+ end
13
+ end
14
+
15
+ context "Authenticated User" do
16
+ context "RW token" do
17
+ before(:all) do
18
+ @api = _api(login: user1["login"],
19
+ application_token: user1["rw_token"])
20
+ end
21
+
22
+ context "when params are valid" do
23
+ before(:all) do
24
+ @res = @api.generate_thumbnail(test_video_id("user1"), time: 3)
25
+ end
26
+
27
+ it_behaves_like "202 Accepted"
28
+ end
29
+
30
+ context "when time param is invalid" do
31
+ before(:all) do
32
+ @res = @api.generate_thumbnail(test_video_id("user1"), time: "invalid")
33
+ end
34
+
35
+ it_behaves_like "422 Failure"
36
+
37
+ specify do
38
+ expect(@res.errors.first["thumb_time"]).to eq("invalid integer")
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ context "RO token" do
45
+ it_behaves_like "RO only", user1["login"], user1["ro_token"], -> (api) do
46
+ api.generate_thumbnail(test_video_id("user1"), time: 3)
47
+ end
48
+ end
49
+
50
+
51
+ context "when user doesn't have permission to the video" do
52
+ before(:all) do
53
+ api = _api(login: user1["login"],
54
+ application_token: user1["rw_token"])
55
+ @res = api.generate_thumbnail(test_video_id("user2"), time: 3)
56
+ end
57
+
58
+ it_behaves_like "422 Failure"
59
+
60
+ specify do
61
+ expect(@res.errors.first["user"]).to match(/Permission Denied/)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,7 @@
1
+ To run the tests you need to setup 2 testing accounts on vzaar app and upload testing video to your first account.
2
+ Then generate RW and RO tokens for each account.
3
+
4
+ After that copy examples/api_envs.yml.example to the main gem's directory (as a api_envs.yml) and fill config with the data from your accounts.
5
+
6
+
7
+ rake spec:api:dev will run all api specs
@@ -0,0 +1,100 @@
1
+ require 'rspec'
2
+ require 'vzaar'
3
+ require 'yaml'
4
+ require 'pry'
5
+
6
+
7
+ RSpec.shared_examples("RO only") do |login, token, fn|
8
+ specify do
9
+ api = _api(login: login, application_token: token)
10
+
11
+ expect do
12
+ fn.call(api)
13
+ end.to raise_error(Vzaar::Error, "Protected Resource")
14
+ end
15
+ end
16
+
17
+
18
+ RSpec.shared_examples("Unauthenticated") do |fn|
19
+ specify do
20
+ api = unauthenticated_api()
21
+ expect do
22
+ fn.call(api)
23
+ end.to raise_error(Vzaar::Error, "Protected Resource")
24
+ end
25
+ end
26
+
27
+
28
+ RSpec.shared_examples("422 Failure") do
29
+ specify { expect(@res.http_status_code).to eq(422) }
30
+ specify { expect(@res.status).to eq("Failure") }
31
+ end
32
+
33
+ RSpec.shared_examples("202 Accepted") do
34
+ specify { expect(@res.http_status_code).to eq 202 }
35
+ specify { expect(@res.status).to eq("Accepted") }
36
+ end
37
+
38
+ RSpec.shared_examples("200 OK") do
39
+ specify { expect(@res.http_status_code).to eq 200 }
40
+ end
41
+
42
+ RSpec.shared_examples("401 Unauthorized") do
43
+ specify { expect(@res.http_status_code).to eq 401 }
44
+ end
45
+
46
+ def env
47
+ ENV["API_ENV"] || "development"
48
+ end
49
+
50
+ def server
51
+ case env
52
+ when "development" then "http://app.vzaar.localhost"
53
+ end
54
+ end
55
+
56
+ def api_envs
57
+ @api_envs ||= YAML.load_file("api_envs.yml")
58
+ end
59
+
60
+ def user1
61
+ api_envs[env]["user1"]
62
+ end
63
+
64
+ def user2
65
+ api_envs[env]["user2"]
66
+ end
67
+
68
+ def user_with_public_api
69
+ api_envs[env]["user_with_public_api"]
70
+ end
71
+
72
+ def user_with_public_videos_access_only
73
+ api_envs[env]["user_with_public_videos_access_only"]
74
+ end
75
+
76
+ def test_video_id(account)
77
+ api_envs[env][account]["test_video_id"]
78
+ end
79
+
80
+ def user_ro
81
+ end
82
+
83
+ def conn_params(params={})
84
+ { application_token: params[:application_token],
85
+ login: params[:login],
86
+ server: server,
87
+ force_http: true }
88
+ end
89
+
90
+ def _api(params)
91
+ Vzaar::Api.new(conn_params(params))
92
+ end
93
+
94
+ def unauthenticated_api
95
+ _api(login: "unknown", application_token: "wrong")
96
+ end
97
+
98
+ def rand_str
99
+ (0...8).map { (65 + rand(26)).chr }.join
100
+ end
@@ -0,0 +1,48 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Upload Thumbnail" do
4
+ file_path = "./spec/support/pic.jpg"
5
+
6
+ context "when user is unauthenticated" do
7
+ it_behaves_like "Unauthenticated", -> (api) do
8
+ api.upload_thumbnail(test_video_id("user1"), path: file_path)
9
+ end
10
+ end
11
+
12
+ context "Authenticated User" do
13
+ context "RW token" do
14
+ before(:all) do
15
+ @api = _api(login: user1["login"],
16
+ application_token: user1["rw_token"])
17
+ end
18
+
19
+ context "when params are valid" do
20
+ before(:all) do
21
+ @res = @api.upload_thumbnail(test_video_id("user1"), path: file_path)
22
+ end
23
+
24
+ it_behaves_like "202 Accepted"
25
+ end
26
+ end
27
+
28
+ context "RO token" do
29
+ it_behaves_like "RO only", user1["login"], user1["ro_token"], -> (api) do
30
+ api.upload_thumbnail(test_video_id("user1"), path: file_path)
31
+ end
32
+ end
33
+
34
+ context "when user doesn't have permission to the video" do
35
+ before(:all) do
36
+ api = _api(login: user1["login"],
37
+ application_token: user1["rw_token"])
38
+ @res = api.upload_thumbnail(test_video_id("user2"), path: file_path)
39
+ end
40
+
41
+ it_behaves_like "422 Failure"
42
+
43
+ specify do
44
+ expect(@res.errors.first["user"]).to match(/Permission Denied/)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,62 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Upload Video" do
4
+
5
+ context "File uploads" do
6
+ file_path = "./spec/support/video.mov"
7
+ desc = "Upload Video/File Uploads"
8
+
9
+ context "Authenticated User" do
10
+ context "RW token" do
11
+ before(:all) do
12
+ api = _api(login: user1["login"],
13
+ application_token: user1["rw_token"])
14
+
15
+ title = "api-test-#{rand_str}"
16
+ @res = api.upload_video(path: file_path, title: title, description: desc)
17
+ end
18
+
19
+ specify { expect(@res.http_status_code).to eq 201 }
20
+ specify { expect(@res.id.to_s).to match(/^[0-9]+$/) }
21
+ end
22
+
23
+ context "RO token" do
24
+ it_behaves_like "RO only", user1["login"], user1["ro_token"], -> (api) do
25
+ api.upload_video(path: file_path, description: desc)
26
+ end
27
+ end
28
+ end
29
+
30
+ context "when user is unauthenticated" do
31
+ it_behaves_like "Unauthenticated", -> (api) do
32
+ api.upload_video(path: file_path, title: "woof", description: desc)
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+
39
+ context "Link uploads" do
40
+ desc = "Upload Video/Link Uploads"
41
+ file_url = "http://samples.mplayerhq.hu/MPEG-4/turn-on-off.mp4"
42
+
43
+ context "Authenticated User" do
44
+ before(:all) do
45
+ api = _api(login: user1["login"],
46
+ application_token: user1["rw_token"])
47
+
48
+ title = "api-test-#{rand_str}"
49
+ @res = api.upload_video(url: file_url, title: title, description: desc)
50
+ end
51
+
52
+ specify { expect(@res.http_status_code).to eq 200 }
53
+ specify { expect(@res.id.to_s).to match(/^[0-9]+$/) }
54
+ end
55
+
56
+ context "when user is unauthenticated" do
57
+ it_behaves_like "Unauthenticated", -> (api) do
58
+ api.upload_video(url: file_url, title: "woof", description: desc)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "User Details" do
4
+ context "when user is unauthenticated" do
5
+ before(:all) do
6
+ api = unauthenticated_api()
7
+ @res = api.user_details(user1['login'])
8
+ end
9
+
10
+ it_behaves_like "200 OK"
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Video Details" do
4
+ context "Fully Protected API" do
5
+ it_behaves_like "Unauthenticated", -> (api) do
6
+ api.video_details(test_video_id("user1"))
7
+ end
8
+ end
9
+
10
+ context "Public API" do
11
+ before(:all) do
12
+ api = unauthenticated_api
13
+ @res = api.video_details(test_video_id("user_with_public_api"))
14
+ end
15
+
16
+ it_behaves_like "200 OK"
17
+ end
18
+
19
+ context "Protected API with access for public videos" do
20
+ scope = api_envs[env]["user_with_public_videos_access_only"]
21
+
22
+ context "when video is public" do
23
+ before do
24
+ api = unauthenticated_api
25
+ @res = api.video_details(scope["test_public_video_id"])
26
+ end
27
+
28
+ it_behaves_like "200 OK"
29
+ end
30
+
31
+ context "when video is private" do
32
+ it_behaves_like "Unauthenticated", -> (api) do
33
+ api.video_details(scope["test_video_id"])
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe "Video List" do
4
+ context "when user is unauthenticated" do
5
+ it_behaves_like "Unauthenticated", -> (api) do
6
+ api.video_list(user1["login"])
7
+ end
8
+
9
+
10
+ context "when Public API Feeds is enabled" do
11
+ before(:all) do
12
+ api = unauthenticated_api
13
+ @res = api.video_list(user_with_public_api["login"])
14
+ end
15
+
16
+ it_behaves_like "200 OK"
17
+ end
18
+ end
19
+ end
data/lib/vzaar/api.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  module Vzaar
2
- class Api < Struct.new(:conn)
2
+ class Api < Struct.new(:options)
3
+ def conn
4
+ @conn ||= Connection.new(options)
5
+ end
3
6
 
4
7
  def whoami(opts={})
5
8
  resource = Request::WhoAmI.new(conn, opts).execute
@@ -5,7 +5,7 @@ module Vzaar
5
5
  SERVER = "vzaar.com"
6
6
  attr_reader :application_token, :force_http, :login, :options
7
7
 
8
- def initialize(options)
8
+ def initialize(options={})
9
9
  @options = options
10
10
  @application_token = options[:application_token]
11
11
  @force_http = options[:force_http]
@@ -4,7 +4,7 @@ module Vzaar
4
4
  attr_reader :http_status_code
5
5
 
6
6
  def initialize(xml_body, status_code)
7
- @http_status_code = status_code
7
+ @http_status_code = status_code.to_i
8
8
 
9
9
  doc = Nokogiri::XML(xml_body)
10
10
  doc.xpath("//videos/video").each do |xml|
data/lib/vzaar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vzaar
2
- VERSION = "1.2.4"
2
+ VERSION = "1.3.0"
3
3
  end
Binary file
@@ -2,9 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module Vzaar
4
4
  describe Api do
5
-
6
- subject { described_class.new connection }
7
- let(:connection) { Connection.new options }
5
+ subject { described_class.new(options) }
8
6
 
9
7
  let(:application_token) { 'b0v8p14Ugpx5zMgDf6leUOxSt8pkcGCFyBcsh0ugHg' }
10
8
  let(:force_http) { false }
@@ -20,8 +18,6 @@ module Vzaar
20
18
  }
21
19
  end
22
20
 
23
- specify { expect(subject.conn).to eq(connection) }
24
-
25
21
  describe "#whoami" do
26
22
  context "with valid credentials" do
27
23
  it "returns the user login" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vzaar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed James
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-18 00:00:00.000000000 Z
12
+ date: 2014-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -184,6 +184,20 @@ files:
184
184
  - LICENSE.txt
185
185
  - README.md
186
186
  - Rakefile
187
+ - examples/account_details_spec.rb
188
+ - examples/add_subtitle_spec.rb
189
+ - examples/api_envs.yml.example
190
+ - examples/authentication_spec.rb
191
+ - examples/delete_video_spec.rb
192
+ - examples/edit_video_spec.rb
193
+ - examples/generate_thumbnail_spec.rb
194
+ - examples/readme.md
195
+ - examples/spec_helper.rb
196
+ - examples/upload_thumbnail_spec.rb
197
+ - examples/upload_video_spec.rb
198
+ - examples/user_details_spec.rb
199
+ - examples/video_details_spec.rb
200
+ - examples/video_list_spec.rb
187
201
  - lib/vzaar.rb
188
202
  - lib/vzaar/api.rb
189
203
  - lib/vzaar/connection.rb
@@ -263,6 +277,7 @@ files:
263
277
  - spec/support/cfx.jpeg
264
278
  - spec/support/cfx.png
265
279
  - spec/support/pic.jpg
280
+ - spec/support/video.mov
266
281
  - spec/support/video.mp4
267
282
  - spec/vzaar/api_xml_spec.rb
268
283
  - spec/vzaar/connection_spec.rb
@@ -297,7 +312,7 @@ rubyforge_project:
297
312
  rubygems_version: 2.2.2
298
313
  signing_key:
299
314
  specification_version: 4
300
- summary: vzaar-1.2.4
315
+ summary: vzaar-1.3.0
301
316
  test_files:
302
317
  - spec/fixtures/vcr_cassettes/account_type-fail.yml
303
318
  - spec/fixtures/vcr_cassettes/account_type-success.yml
@@ -337,6 +352,7 @@ test_files:
337
352
  - spec/support/cfx.jpeg
338
353
  - spec/support/cfx.png
339
354
  - spec/support/pic.jpg
355
+ - spec/support/video.mov
340
356
  - spec/support/video.mp4
341
357
  - spec/vzaar/api_xml_spec.rb
342
358
  - spec/vzaar/connection_spec.rb