Ziggeo 2.16 → 2.24

Sign up to get free protection for your applications and to get access to all the features.
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
- if (@auth == nil)
68
- @auth = ZiggeoAuth.new(self)
69
- end
70
- return @auth end
75
+ @auth = @auth || ZiggeoAuth.new(self)
76
+ return @auth
77
+ end
71
78
 
72
79
  def videos()
73
- if (@videos == nil)
74
- @videos = ZiggeoVideos.new(self)
75
- end
76
- return @videos end
80
+ @videos = @videos || ZiggeoVideos.new(self)
81
+ return @videos
82
+ end
77
83
 
78
84
  def streams()
79
- if (@streams == nil)
80
- @streams = ZiggeoStreams.new(self)
81
- end
82
- return @streams end
85
+ @streams = @streams || ZiggeoStreams.new(self)
86
+ return @streams
87
+ end
83
88
 
84
89
  def authtokens()
85
- if (@authtokens == nil)
86
- @authtokens = ZiggeoAuthtokens.new(self)
87
- end
88
- return @authtokens end
90
+ @authtokens = @authtokens || ZiggeoAuthtokens.new(self)
91
+ return @authtokens
92
+ end
89
93
 
90
94
  def application()
91
- if (@application == nil)
92
- @application = ZiggeoApplication.new(self)
93
- end
94
- return @application end
95
+ @application = @application || ZiggeoApplication.new(self)
96
+ return @application
97
+ end
95
98
 
96
99
  def effectProfiles()
97
- if (@effectProfiles == nil)
98
- @effectProfiles = ZiggeoEffectProfiles.new(self)
99
- end
100
- return @effectProfiles end
100
+ @effectProfiles = @effectProfiles || ZiggeoEffectProfiles.new(self)
101
+ return @effectProfiles
102
+ end
101
103
 
102
104
  def effectProfileProcess()
103
- if (@effectProfileProcess == nil)
104
- @effectProfileProcess = ZiggeoEffectProfileProcess.new(self)
105
- end
106
- return @effectProfileProcess end
105
+ @effectProfileProcess = @effectProfileProcess || ZiggeoEffectProfileProcess.new(self)
106
+ return @effectProfileProcess
107
+ end
107
108
 
108
109
  def metaProfiles()
109
- if (@metaProfiles == nil)
110
- @metaProfiles = ZiggeoMetaProfiles.new(self)
111
- end
112
- return @metaProfiles end
110
+ @metaProfiles = @metaProfiles || ZiggeoMetaProfiles.new(self)
111
+ return @metaProfiles
112
+ end
113
113
 
114
114
  def metaProfileProcess()
115
- if (@metaProfileProcess == nil)
116
- @metaProfileProcess = ZiggeoMetaProfileProcess.new(self)
117
- end
118
- return @metaProfileProcess end
115
+ @metaProfileProcess = @metaProfileProcess || ZiggeoMetaProfileProcess.new(self)
116
+ return @metaProfileProcess
117
+ end
119
118
 
120
119
  def webhooks()
121
- if (@webhooks == nil)
122
- @webhooks = ZiggeoWebhooks.new(self)
123
- end
124
- return @webhooks end
120
+ @webhooks = @webhooks || ZiggeoWebhooks.new(self)
121
+ return @webhooks
122
+ end
125
123
 
126
124
  def analytics()
127
- if (@analytics == nil)
128
- @analytics = ZiggeoAnalytics.new(self)
129
- end
130
- return @analytics end
131
-
125
+ @analytics = @analytics || ZiggeoAnalytics.new(self)
126
+ return @analytics
127
+ end
132
128
 
133
129
  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
@@ -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)
@@ -9,7 +8,7 @@ class ZiggeoConnect
9
8
  @baseuri = baseuri
10
9
  end
11
10
 
12
- def request(method, path, data = nil, file = nil)
11
+ def singleRequest(method, path, data = nil, file = nil)
13
12
  url = URI.parse(@baseuri + path)
14
13
  auth = { username: @application.token, password: @application.private_key }
15
14
  timeout_in_seconds = @application.config.request_timeout.to_i
@@ -17,33 +16,37 @@ class ZiggeoConnect
17
16
  method.downcase!
18
17
  allowed_methods = %w(get post delete)
19
18
  return unless allowed_methods.include?(method)
20
- if (file.nil?)
21
- if (method == "get")
22
- begin
23
- HTTParty.send(method, url.to_s, query: data, basic_auth: auth, timeout: timeout_in_seconds).body
24
- rescue Net::ReadTimeout => error
25
- self.timeout_error_message timeout_in_seconds, error
26
- end
27
- else
28
- begin
29
- HTTParty.send(method, url.to_s, body: data, basic_auth: auth, timeout: timeout_in_seconds).body
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
- HTTMultiParty.send(method, url.to_s, body: data, basic_auth: auth, timeout: timeout_in_seconds).body
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
44
36
  end
45
37
  end
46
38
 
39
+ def request(method, path, data = nil, file = nil)
40
+ res = nil
41
+ @application.config.resilience_factor.times do
42
+ res = self.singleRequest(method, path, data, file)
43
+ if res.response.code.to_i >= 200 && res.response.code.to_i < 500
44
+ return res.body
45
+ end
46
+ end
47
+ return @application.config.resilience_on_fail.to_json
48
+ end
49
+
47
50
  def requestJSON(method, path, data = nil, file = nil)
48
51
  return JSON.parse(self.request(method, path, data, file))
49
52
  end
@@ -72,6 +75,33 @@ class ZiggeoConnect
72
75
  return self.requestJSON("DELETE", path, data, file)
73
76
  end
74
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
+
75
105
  protected
76
106
 
77
107
  def timeout_error_message( timeout_in_seconds, error )
@@ -21,7 +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
31
+ end
32
+
33
+ def edit_watermark_process(effect_token_or_key, token_or_key, data = nil, file = nil)
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
25
41
  end
26
42
 
27
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
@@ -29,15 +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
59
+ end
60
+
61
+ def attach_subtitle(video_token_or_key, token_or_key, data = nil)
62
+ return @application.connect.postJSON('/v1/videos/' + video_token_or_key + '/streams/' + token_or_key + '/subtitle', data)
41
63
  end
42
64
 
43
65
  def bind(video_token_or_key, 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.16'
4
+ version: '2.24'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziggeo, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-05 00:00:00.000000000 Z
11
+ date: 2021-02-07 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
@@ -79,8 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
65
  - !ruby/object:Gem::Version
80
66
  version: '0'
81
67
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.5.2.3
68
+ rubygems_version: 3.0.3
84
69
  signing_key:
85
70
  specification_version: 4
86
71
  summary: The Ziggeo ServerSDK gem.