Ziggeo 2.18 → 2.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +661 -597
- data/lib/Ziggeo.rb +42 -46
- data/lib/classes/ZiggeoConfig.rb +7 -3
- data/lib/classes/ZiggeoConnect.rb +43 -23
- data/lib/classes/ZiggeoEffectProfileProcess.rb +14 -2
- data/lib/classes/ZiggeoMetaProfileProcess.rb +4 -0
- data/lib/classes/ZiggeoStreams.rb +23 -5
- data/lib/classes/ZiggeoVideos.rb +9 -3
- metadata +4 -18
data/lib/Ziggeo.rb
CHANGED
@@ -19,7 +19,7 @@ require_relative "classes/ZiggeoAnalytics"
|
|
19
19
|
|
20
20
|
class Ziggeo
|
21
21
|
|
22
|
-
attr_accessor :token, :private_key, :encryption_key, :config, :connect, :api_connect
|
22
|
+
attr_accessor :token, :private_key, :encryption_key, :config, :connect, :api_connect, :cdn_connect
|
23
23
|
|
24
24
|
def initialize(token = nil, private_key = nil, encryption_key = nil)
|
25
25
|
@token = token
|
@@ -42,6 +42,14 @@ class Ziggeo
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
@api_connect = ZiggeoConnect.new(self, api_url)
|
45
|
+
cdn_url = @config.cdn_url
|
46
|
+
cdn_regions = @config.cdn_regions
|
47
|
+
cdn_regions.each do |key, value|
|
48
|
+
if (@token.start_with?(key))
|
49
|
+
cdn_url = value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@cdn_connect = ZiggeoConnect.new(self, cdn_url)
|
45
53
|
@auth = nil
|
46
54
|
@videos = nil
|
47
55
|
@streams = nil
|
@@ -64,70 +72,58 @@ class Ziggeo
|
|
64
72
|
end
|
65
73
|
|
66
74
|
def auth()
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
return @auth end
|
75
|
+
@auth = @auth || ZiggeoAuth.new(self)
|
76
|
+
return @auth
|
77
|
+
end
|
71
78
|
|
72
79
|
def videos()
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
return @videos end
|
80
|
+
@videos = @videos || ZiggeoVideos.new(self)
|
81
|
+
return @videos
|
82
|
+
end
|
77
83
|
|
78
84
|
def streams()
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
return @streams end
|
85
|
+
@streams = @streams || ZiggeoStreams.new(self)
|
86
|
+
return @streams
|
87
|
+
end
|
83
88
|
|
84
89
|
def authtokens()
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return @authtokens end
|
90
|
+
@authtokens = @authtokens || ZiggeoAuthtokens.new(self)
|
91
|
+
return @authtokens
|
92
|
+
end
|
89
93
|
|
90
94
|
def application()
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
return @application end
|
95
|
+
@application = @application || ZiggeoApplication.new(self)
|
96
|
+
return @application
|
97
|
+
end
|
95
98
|
|
96
99
|
def effectProfiles()
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
return @effectProfiles end
|
100
|
+
@effectProfiles = @effectProfiles || ZiggeoEffectProfiles.new(self)
|
101
|
+
return @effectProfiles
|
102
|
+
end
|
101
103
|
|
102
104
|
def effectProfileProcess()
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
return @effectProfileProcess end
|
105
|
+
@effectProfileProcess = @effectProfileProcess || ZiggeoEffectProfileProcess.new(self)
|
106
|
+
return @effectProfileProcess
|
107
|
+
end
|
107
108
|
|
108
109
|
def metaProfiles()
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
return @metaProfiles end
|
110
|
+
@metaProfiles = @metaProfiles || ZiggeoMetaProfiles.new(self)
|
111
|
+
return @metaProfiles
|
112
|
+
end
|
113
113
|
|
114
114
|
def metaProfileProcess()
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
return @metaProfileProcess end
|
115
|
+
@metaProfileProcess = @metaProfileProcess || ZiggeoMetaProfileProcess.new(self)
|
116
|
+
return @metaProfileProcess
|
117
|
+
end
|
119
118
|
|
120
119
|
def webhooks()
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
return @webhooks end
|
120
|
+
@webhooks = @webhooks || ZiggeoWebhooks.new(self)
|
121
|
+
return @webhooks
|
122
|
+
end
|
125
123
|
|
126
124
|
def analytics()
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
return @analytics end
|
131
|
-
|
125
|
+
@analytics = @analytics || ZiggeoAnalytics.new(self)
|
126
|
+
return @analytics
|
127
|
+
end
|
132
128
|
|
133
129
|
end
|
data/lib/classes/ZiggeoConfig.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
|
2
2
|
class ZiggeoConfig
|
3
|
-
attr_accessor :server_api_url, :api_url, :
|
3
|
+
attr_accessor :request_timeout, :request_timeout_per_mb, :server_api_url, :api_url, :cdn_url, :regions, :api_regions, :cdn_regions, :resilience_factor, :resilience_on_fail
|
4
4
|
|
5
5
|
def initialize()
|
6
6
|
@request_timeout = 30 # seconds
|
7
7
|
@request_timeout_per_mb = 20 # seconds per MB of uploaded file
|
8
|
-
@server_api_url = "https://
|
8
|
+
@server_api_url = "https://srv-api.ziggeo.com"
|
9
9
|
@api_url = "https://api-us-east-1.ziggeo.com"
|
10
|
-
@
|
10
|
+
@cdn_url = "https://video-cdn.ziggeo.com"
|
11
|
+
@regions = {"r1" => "https://srv-api-eu-west-1.ziggeo.com", }
|
11
12
|
@api_regions = {"r1" => "https://api-eu-west-1.ziggeo.com", }
|
13
|
+
@cdn_regions = {"r1" => "https://video-cdn-eu-west-1.ziggeo.com", }
|
14
|
+
@resilience_factor = 5
|
15
|
+
@resilience_on_fail = {"error" => "Too many failed attempts"}
|
12
16
|
end
|
13
17
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
3
|
require 'httparty'
|
4
|
-
require 'httmultiparty'
|
5
4
|
|
6
5
|
class ZiggeoConnect
|
7
6
|
def initialize(application, baseuri)
|
@@ -17,27 +16,20 @@ class ZiggeoConnect
|
|
17
16
|
method.downcase!
|
18
17
|
allowed_methods = %w(get post delete)
|
19
18
|
return unless allowed_methods.include?(method)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
rescue Net::ReadTimeout => error
|
31
|
-
self.timeout_error_message timeout_in_seconds, error
|
32
|
-
end
|
19
|
+
unless (file.nil?)
|
20
|
+
data = data || {}
|
21
|
+
data["file"] = File.new(file)
|
22
|
+
timeout_in_seconds = ( ( File.size(file).to_f / 2**20 ).ceil * @application.config.request_timeout_per_mb.to_i ).to_i;
|
23
|
+
end
|
24
|
+
if (method == "get")
|
25
|
+
begin
|
26
|
+
HTTParty.send(method, url.to_s, query: data, basic_auth: auth, timeout: timeout_in_seconds)
|
27
|
+
rescue Net::ReadTimeout => error
|
28
|
+
self.timeout_error_message timeout_in_seconds, error
|
33
29
|
end
|
34
30
|
else
|
35
|
-
data = data.nil? ? {} : data;
|
36
|
-
data["file"] = File.new(file)
|
37
|
-
timeout_in_seconds = ( ( File.size(file).to_f / 2**20 ).round(0) * @application.config.request_timeout_per_mb.to_i ).to_i;
|
38
|
-
|
39
31
|
begin
|
40
|
-
|
32
|
+
HTTParty.send(method, url.to_s, body: data, basic_auth: auth, timeout: timeout_in_seconds)
|
41
33
|
rescue Net::ReadTimeout => error
|
42
34
|
self.timeout_error_message timeout_in_seconds, error
|
43
35
|
end
|
@@ -46,12 +38,13 @@ class ZiggeoConnect
|
|
46
38
|
|
47
39
|
def request(method, path, data = nil, file = nil)
|
48
40
|
res = nil
|
49
|
-
|
41
|
+
@application.config.resilience_factor.times do
|
50
42
|
res = self.singleRequest(method, path, data, file)
|
51
|
-
|
43
|
+
if res.response.code.to_i >= 200 && res.response.code.to_i < 500
|
44
|
+
return res.body
|
45
|
+
end
|
52
46
|
end
|
53
|
-
|
54
|
-
return res.body
|
47
|
+
return @application.config.resilience_on_fail.to_json
|
55
48
|
end
|
56
49
|
|
57
50
|
def requestJSON(method, path, data = nil, file = nil)
|
@@ -82,6 +75,33 @@ class ZiggeoConnect
|
|
82
75
|
return self.requestJSON("DELETE", path, data, file)
|
83
76
|
end
|
84
77
|
|
78
|
+
def uploadFile(url, file, data)
|
79
|
+
res = nil
|
80
|
+
data["file"] = File.new(file)
|
81
|
+
timeout_in_seconds = ( ( File.size(file).to_f / 2**20 ).ceil * @application.config.request_timeout_per_mb.to_i ).to_i;
|
82
|
+
begin
|
83
|
+
@application.config.resilience_factor.times do
|
84
|
+
res = HTTParty.send("post", url.to_s, body: data, timeout: timeout_in_seconds)
|
85
|
+
if res.response.code.to_i >= 200 && res.response.code.to_i < 300
|
86
|
+
return
|
87
|
+
end
|
88
|
+
end
|
89
|
+
raise Exception.new res.response
|
90
|
+
rescue Net::ReadTimeout => error
|
91
|
+
self.timeout_error_message timeout_in_seconds, error
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def postUploadJSON(path, scope, data = nil, file = nil, type_key = nil)
|
96
|
+
data = data || {}
|
97
|
+
if type_key && (file.is_a? String)
|
98
|
+
data[type_key] = File.extname(file)
|
99
|
+
end
|
100
|
+
result = self.postJSON(path, data)
|
101
|
+
self.uploadFile(result["url_data"]["url"], file, result["url_data"]["fields"])
|
102
|
+
return result[scope]
|
103
|
+
end
|
104
|
+
|
85
105
|
protected
|
86
106
|
|
87
107
|
def timeout_error_message( timeout_in_seconds, error )
|
@@ -21,11 +21,23 @@ class ZiggeoEffectProfileProcess
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def create_watermark_process(effect_token_or_key, data = nil, file = nil)
|
24
|
-
|
24
|
+
unless file.nil?
|
25
|
+
result = @application.connect.postUploadJSON('/v1/effects/' + effect_token_or_key + '/process/watermark-upload-url', 'effect_process', data, file)
|
26
|
+
result = @application.connect.postJSON('/v1/effects/' + effect_token_or_key + '/process/' + result["token"] + '/confirm-watermark');
|
27
|
+
return result
|
28
|
+
else
|
29
|
+
return @application.connect.postJSON('/v1/effects/' + effect_token_or_key + '/process/watermark', data, file)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
def edit_watermark_process(effect_token_or_key, token_or_key, data = nil, file = nil)
|
28
|
-
|
34
|
+
unless file.nil?
|
35
|
+
result = @application.connect.postUploadJSON('/v1/effects/' + effect_token_or_key + '/process/' + token_or_key + '/watermark-upload-url', 'effect_process', data, file)
|
36
|
+
result = @application.connect.postJSON('/v1/effects/' + effect_token_or_key + '/process/' + token_or_key + '/confirm-watermark');
|
37
|
+
return result
|
38
|
+
else
|
39
|
+
return @application.connect.postJSON('/v1/effects/' + effect_token_or_key + '/process/watermark/' + token_or_key + '', data, file)
|
40
|
+
end
|
29
41
|
end
|
30
42
|
|
31
43
|
end
|
@@ -28,4 +28,8 @@ class ZiggeoMetaProfileProcess
|
|
28
28
|
return @application.connect.postJSON('/v1/metaprofiles/' + meta_token_or_key + '/process/nsfw', data)
|
29
29
|
end
|
30
30
|
|
31
|
+
def create_profanity_process(meta_token_or_key, data = nil)
|
32
|
+
return @application.connect.postJSON('/v1/metaprofiles/' + meta_token_or_key + '/process/profanity', data)
|
33
|
+
end
|
34
|
+
|
31
35
|
end
|
@@ -13,11 +13,11 @@ class ZiggeoStreams
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def download_video(video_token_or_key, token_or_key)
|
16
|
-
return @application.
|
16
|
+
return @application.cdn_connect.get('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/video')
|
17
17
|
end
|
18
18
|
|
19
19
|
def download_image(video_token_or_key, token_or_key)
|
20
|
-
return @application.
|
20
|
+
return @application.cdn_connect.get('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/image')
|
21
21
|
end
|
22
22
|
|
23
23
|
def push_to_service(video_token_or_key, token_or_key, data = nil)
|
@@ -29,15 +29,33 @@ class ZiggeoStreams
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def create(video_token_or_key, data = nil, file = nil)
|
32
|
-
|
32
|
+
unless file.nil?
|
33
|
+
result = @application.connect.postUploadJSON('/v1/videos/' + video_token_or_key + '/streams-upload-url', 'stream', data, file, 'video_type')
|
34
|
+
result = @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + result["token"] + '/confirm-video');
|
35
|
+
return result
|
36
|
+
else
|
37
|
+
return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams', data, file)
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
def attach_image(video_token_or_key, token_or_key, data = nil, file = nil)
|
36
|
-
|
42
|
+
unless file.nil?
|
43
|
+
result = @application.connect.postUploadJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/image-upload-url', 'stream', data, file)
|
44
|
+
result = @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/confirm-image');
|
45
|
+
return result
|
46
|
+
else
|
47
|
+
return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/image', data, file)
|
48
|
+
end
|
37
49
|
end
|
38
50
|
|
39
51
|
def attach_video(video_token_or_key, token_or_key, data = nil, file = nil)
|
40
|
-
|
52
|
+
unless file.nil?
|
53
|
+
result = @application.connect.postUploadJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/video-upload-url', 'stream', data, file, 'video_type')
|
54
|
+
result = @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/confirm-video');
|
55
|
+
return result
|
56
|
+
else
|
57
|
+
return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/video', data, file)
|
58
|
+
end
|
41
59
|
end
|
42
60
|
|
43
61
|
def attach_subtitle(video_token_or_key, token_or_key, data = nil)
|
data/lib/classes/ZiggeoVideos.rb
CHANGED
@@ -25,11 +25,11 @@ class ZiggeoVideos
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def download_video(token_or_key)
|
28
|
-
return @application.
|
28
|
+
return @application.cdn_connect.get('/v1/videos/' + token_or_key + '/video')
|
29
29
|
end
|
30
30
|
|
31
31
|
def download_image(token_or_key)
|
32
|
-
return @application.
|
32
|
+
return @application.cdn_connect.get('/v1/videos/' + token_or_key + '/image')
|
33
33
|
end
|
34
34
|
|
35
35
|
def get_stats(token_or_key)
|
@@ -61,7 +61,13 @@ class ZiggeoVideos
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def create(data = nil, file = nil)
|
64
|
-
|
64
|
+
unless file.nil?
|
65
|
+
result = @application.connect.postUploadJSON('/v1/videos-upload-url', 'video', data, file, 'video_type')
|
66
|
+
result["default_stream"] = @application.connect.postJSON('/v1/videos/' + result["token"] + '/streams/' + result["default_stream"]["token"] + '/confirm-video');
|
67
|
+
return result
|
68
|
+
else
|
69
|
+
return @application.connect.postJSON('/v1/videos/', data, file)
|
70
|
+
end
|
65
71
|
end
|
66
72
|
|
67
73
|
def analytics(token_or_key, data = nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Ziggeo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.26'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ziggeo, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.16'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: httmultiparty
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: '0.16'
|
41
27
|
description: The Ziggeo Ruby and Rails Server SDK.
|
42
28
|
email:
|
43
29
|
- support@ziggeo.com
|