Ziggeo 2.19 → 2.29

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Ziggeo.rb CHANGED
@@ -8,6 +8,8 @@ require_relative "classes/ZiggeoConnect"
8
8
  require_relative "classes/ZiggeoAuth"
9
9
  require_relative "classes/ZiggeoVideos"
10
10
  require_relative "classes/ZiggeoStreams"
11
+ require_relative "classes/ZiggeoAudios"
12
+ require_relative "classes/ZiggeoAudio_streams"
11
13
  require_relative "classes/ZiggeoAuthtokens"
12
14
  require_relative "classes/ZiggeoApplication"
13
15
  require_relative "classes/ZiggeoEffectProfiles"
@@ -19,7 +21,7 @@ require_relative "classes/ZiggeoAnalytics"
19
21
 
20
22
  class Ziggeo
21
23
 
22
- attr_accessor :token, :private_key, :encryption_key, :config, :connect, :api_connect
24
+ attr_accessor :token, :private_key, :encryption_key, :config, :connect, :api_connect, :cdn_connect
23
25
 
24
26
  def initialize(token = nil, private_key = nil, encryption_key = nil)
25
27
  @token = token
@@ -42,9 +44,19 @@ class Ziggeo
42
44
  end
43
45
  end
44
46
  @api_connect = ZiggeoConnect.new(self, api_url)
47
+ cdn_url = @config.cdn_url
48
+ cdn_regions = @config.cdn_regions
49
+ cdn_regions.each do |key, value|
50
+ if (@token.start_with?(key))
51
+ cdn_url = value
52
+ end
53
+ end
54
+ @cdn_connect = ZiggeoConnect.new(self, cdn_url)
45
55
  @auth = nil
46
56
  @videos = nil
47
57
  @streams = nil
58
+ @audios = nil
59
+ @audio_streams = nil
48
60
  @authtokens = nil
49
61
  @application = nil
50
62
  @effectProfiles = nil
@@ -64,70 +76,68 @@ class Ziggeo
64
76
  end
65
77
 
66
78
  def auth()
67
- if (@auth == nil)
68
- @auth = ZiggeoAuth.new(self)
69
- end
70
- return @auth end
79
+ @auth = @auth || ZiggeoAuth.new(self)
80
+ return @auth
81
+ end
71
82
 
72
83
  def videos()
73
- if (@videos == nil)
74
- @videos = ZiggeoVideos.new(self)
75
- end
76
- return @videos end
84
+ @videos = @videos || ZiggeoVideos.new(self)
85
+ return @videos
86
+ end
77
87
 
78
88
  def streams()
79
- if (@streams == nil)
80
- @streams = ZiggeoStreams.new(self)
81
- end
82
- return @streams end
89
+ @streams = @streams || ZiggeoStreams.new(self)
90
+ return @streams
91
+ end
92
+
93
+ def audios()
94
+ @audios = @audios || ZiggeoAudios.new(self)
95
+ return @audios
96
+ end
97
+
98
+ def audio_streams()
99
+ @audio_streams = @audio_streams || ZiggeoAudio_streams.new(self)
100
+ return @audio_streams
101
+ end
83
102
 
84
103
  def authtokens()
85
- if (@authtokens == nil)
86
- @authtokens = ZiggeoAuthtokens.new(self)
87
- end
88
- return @authtokens end
104
+ @authtokens = @authtokens || ZiggeoAuthtokens.new(self)
105
+ return @authtokens
106
+ end
89
107
 
90
108
  def application()
91
- if (@application == nil)
92
- @application = ZiggeoApplication.new(self)
93
- end
94
- return @application end
109
+ @application = @application || ZiggeoApplication.new(self)
110
+ return @application
111
+ end
95
112
 
96
113
  def effectProfiles()
97
- if (@effectProfiles == nil)
98
- @effectProfiles = ZiggeoEffectProfiles.new(self)
99
- end
100
- return @effectProfiles end
114
+ @effectProfiles = @effectProfiles || ZiggeoEffectProfiles.new(self)
115
+ return @effectProfiles
116
+ end
101
117
 
102
118
  def effectProfileProcess()
103
- if (@effectProfileProcess == nil)
104
- @effectProfileProcess = ZiggeoEffectProfileProcess.new(self)
105
- end
106
- return @effectProfileProcess end
119
+ @effectProfileProcess = @effectProfileProcess || ZiggeoEffectProfileProcess.new(self)
120
+ return @effectProfileProcess
121
+ end
107
122
 
108
123
  def metaProfiles()
109
- if (@metaProfiles == nil)
110
- @metaProfiles = ZiggeoMetaProfiles.new(self)
111
- end
112
- return @metaProfiles end
124
+ @metaProfiles = @metaProfiles || ZiggeoMetaProfiles.new(self)
125
+ return @metaProfiles
126
+ end
113
127
 
114
128
  def metaProfileProcess()
115
- if (@metaProfileProcess == nil)
116
- @metaProfileProcess = ZiggeoMetaProfileProcess.new(self)
117
- end
118
- return @metaProfileProcess end
129
+ @metaProfileProcess = @metaProfileProcess || ZiggeoMetaProfileProcess.new(self)
130
+ return @metaProfileProcess
131
+ end
119
132
 
120
133
  def webhooks()
121
- if (@webhooks == nil)
122
- @webhooks = ZiggeoWebhooks.new(self)
123
- end
124
- return @webhooks end
134
+ @webhooks = @webhooks || ZiggeoWebhooks.new(self)
135
+ return @webhooks
136
+ end
125
137
 
126
138
  def analytics()
127
- if (@analytics == nil)
128
- @analytics = ZiggeoAnalytics.new(self)
129
- end
130
- return @analytics end
131
-
139
+ @analytics = @analytics || ZiggeoAnalytics.new(self)
140
+ return @analytics
141
+ end
132
142
 
133
143
  end
@@ -0,0 +1,33 @@
1
+ class ZiggeoAudio_streams
2
+
3
+ def initialize(application)
4
+ @application = application
5
+ end
6
+
7
+ def index(audio_token_or_key, data = nil)
8
+ return @application.api_connect.getJSON('/server/v1/audios/bytoken/' + audio_token_or_key + '/streams', data)
9
+ end
10
+
11
+ def get(audio_token_or_key, token_or_key)
12
+ return @application.api_connect.getJSON('/server/v1/audios/bytoken/' + audio_token_or_key + '/streams/bytoken/' + token_or_key + '')
13
+ end
14
+
15
+ def download_audio(audio_token_or_key, token_or_key)
16
+ return @application.connect.get('/v1/server/v1/audios/bytoken/' + audio_token_or_key + '/streams/bytoken/' + token_or_key + '/audio')
17
+ end
18
+
19
+ def delete(audio_token_or_key, token_or_key)
20
+ return @application.api_connect.delete('/server/v1/audios/bytoken/' + audio_token_or_key + '/streams/bytoken/' + token_or_key + '')
21
+ end
22
+
23
+ def create(audio_token_or_key, data = nil, file = nil)
24
+ unless file.nil?
25
+ result = @application.connect.postUploadJSON('/server/v1/audios/' + audio_token_or_key + '/streams-upload-url', 'stream', data, file, 'audio_type')
26
+ result = @application.connect.postJSON('/server/v1/audios/' + audio_token_or_key + '/streams/' + result["token"] + '/confirm-video');
27
+ return result
28
+ else
29
+ return @application.api_connect.postJSON('/server/v1/audios/bytoken/' + audio_token_or_key + '/streams', data, file)
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,49 @@
1
+ class ZiggeoAudios
2
+
3
+ def initialize(application)
4
+ @application = application
5
+ end
6
+
7
+ def index(data = nil)
8
+ return @application.api_connect.getJSON('/server/v1/audios/', data)
9
+ end
10
+
11
+ def count(data = nil)
12
+ return @application.api_connect.getJSON('/server/v1/audios/count', data)
13
+ end
14
+
15
+ def get(token_or_key)
16
+ return @application.api_connect.getJSON('/server/v1/audios/bytoken/' + token_or_key + '')
17
+ end
18
+
19
+ def get_bulk(data = nil)
20
+ return @application.api_connect.postJSON('/server/v1/audios/get-bulk', data)
21
+ end
22
+
23
+ def download_audio(token_or_key)
24
+ return @application.connect.get('/v1/server/v1/audios/bytoken/' + token_or_key + '/video')
25
+ end
26
+
27
+ def update(token_or_key, data = nil)
28
+ return @application.api_connect.postJSON('/server/v1/audios/bytoken/' + token_or_key + '', data)
29
+ end
30
+
31
+ def update_bulk(data = nil)
32
+ return @application.api_connect.postJSON('/server/v1/audios/update-bulk', data)
33
+ end
34
+
35
+ def delete(token_or_key)
36
+ return @application.api_connect.delete('/server/v1/audios/bytoken/' + token_or_key + '')
37
+ end
38
+
39
+ def create(data = nil, file = nil)
40
+ unless file.nil?
41
+ result = @application.connect.postUploadJSON('/server/v1/audios/audios-upload-url', 'audio', data, file, 'audio_type')
42
+ result["default_stream"] = @application.connect.postJSON('/server/v1/audios/' + result["token"] + '/streams/' + result["default_stream"]["token"] + '/confirm-audio');
43
+ return result
44
+ else
45
+ return @application.api_connect.postJSON('/server/v1/audios/', data, file)
46
+ end
47
+ end
48
+
49
+ end
@@ -1,13 +1,17 @@
1
1
 
2
2
  class ZiggeoConfig
3
- attr_accessor :server_api_url, :api_url, :request_timeout, :request_timeout_per_mb, :regions, :api_regions
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://srvapi.ziggeo.com"
8
+ @server_api_url = "https://srv-api.ziggeo.com"
9
9
  @api_url = "https://api-us-east-1.ziggeo.com"
10
- @regions = {"r1" => "https://srvapi-eu-west-1.ziggeo.com", }
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
@@ -16,25 +16,18 @@ class ZiggeoConnect
16
16
  method.downcase!
17
17
  allowed_methods = %w(get post delete)
18
18
  return unless allowed_methods.include?(method)
19
- if (file.nil?)
20
- if (method == "get")
21
- begin
22
- HTTParty.send(method, url.to_s, query: data, basic_auth: auth, timeout: timeout_in_seconds)
23
- rescue Net::ReadTimeout => error
24
- self.timeout_error_message timeout_in_seconds, error
25
- end
26
- else
27
- begin
28
- HTTParty.send(method, url.to_s, body: data, basic_auth: auth, timeout: timeout_in_seconds)
29
- rescue Net::ReadTimeout => error
30
- self.timeout_error_message timeout_in_seconds, error
31
- end
32
- end
33
- else
34
- data = data.nil? ? {} : data;
19
+ unless (file.nil?)
20
+ data = data || {}
35
21
  data["file"] = File.new(file)
36
22
  timeout_in_seconds = ( ( File.size(file).to_f / 2**20 ).ceil * @application.config.request_timeout_per_mb.to_i ).to_i;
37
-
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
29
+ end
30
+ else
38
31
  begin
39
32
  HTTParty.send(method, url.to_s, body: data, basic_auth: auth, timeout: timeout_in_seconds)
40
33
  rescue Net::ReadTimeout => error
@@ -45,12 +38,13 @@ class ZiggeoConnect
45
38
 
46
39
  def request(method, path, data = nil, file = nil)
47
40
  res = nil
48
- 5.times do
41
+ @application.config.resilience_factor.times do
49
42
  res = self.singleRequest(method, path, data, file)
50
- break if res.response.code.to_i < 500
43
+ if res.response.code.to_i >= 200 && res.response.code.to_i < 500
44
+ return res.body
45
+ end
51
46
  end
52
-
53
- return res.body
47
+ return @application.config.resilience_on_fail.to_json
54
48
  end
55
49
 
56
50
  def requestJSON(method, path, data = nil, file = nil)
@@ -81,6 +75,33 @@ class ZiggeoConnect
81
75
  return self.requestJSON("DELETE", path, data, file)
82
76
  end
83
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
+
84
105
  protected
85
106
 
86
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
- return @application.connect.postJSON('/v1/effects/' + effect_token_or_key + '/process/watermark', data, file)
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
- return @application.connect.postJSON('/v1/effects/' + effect_token_or_key + '/process/watermark/' + token_or_key + '', data, file)
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.connect.get('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/video')
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.connect.get('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/image')
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,23 +29,37 @@ class ZiggeoStreams
29
29
  end
30
30
 
31
31
  def create(video_token_or_key, data = nil, file = nil)
32
- return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams', data, file)
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
- return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/image', data, file)
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
- return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/video', data, file)
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)
44
62
  return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/subtitle', data)
45
63
  end
46
64
 
47
- def bind(video_token_or_key, token_or_key)
48
- return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/bind')
49
- end
50
-
51
65
  end
@@ -25,11 +25,11 @@ class ZiggeoVideos
25
25
  end
26
26
 
27
27
  def download_video(token_or_key)
28
- return @application.connect.get('/v1/videos/' + token_or_key + '/video')
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.connect.get('/v1/videos/' + token_or_key + '/image')
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
- return @application.connect.postJSON('/v1/videos/', data, file)
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.19'
4
+ version: '2.29'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziggeo, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2022-02-13 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.13'
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.13'
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
@@ -49,6 +35,8 @@ files:
49
35
  - lib/Ziggeo.rb
50
36
  - lib/classes/ZiggeoAnalytics.rb
51
37
  - lib/classes/ZiggeoApplication.rb
38
+ - lib/classes/ZiggeoAudioStreams.rb
39
+ - lib/classes/ZiggeoAudios.rb
52
40
  - lib/classes/ZiggeoAuth.rb
53
41
  - lib/classes/ZiggeoAuthtokens.rb
54
42
  - lib/classes/ZiggeoConfig.rb
@@ -79,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
67
  - !ruby/object:Gem::Version
80
68
  version: '0'
81
69
  requirements: []
82
- rubygems_version: 3.0.3
70
+ rubygems_version: 3.0.3.1
83
71
  signing_key:
84
72
  specification_version: 4
85
73
  summary: The Ziggeo ServerSDK gem.