Ziggeo 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjdmNjY2ZWYxYjRhZWY5M2MwYTNjNzM0NDlkYWEwNzUzZTZkMjJmYQ==
5
+ data.tar.gz: !binary |-
6
+ NjAxNzNkMzRkYzcwMjY0NDk4ZTQ3ODAyNmExNTJkZjgyMTliNTEwNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWQwMjNmNjNjMjgzNTg3ZDMzNDUyOTViMGNmZThmYzFiODhhNmQ4N2MxNTNm
10
+ ODU4N2UxNTQ4ZDYzODQ5Yjg0Y2E0YWFjODFkMjlmNGJhNDU5Y2ZiYThmZjJk
11
+ NDFkN2IzNDA0NzU2Mjk1MTY2ZWRhZmIzYjM1NzVmYWM1OTZlMjI=
12
+ data.tar.gz: !binary |-
13
+ NDQ3YzM0MWRmNGJkYzU3NDY3MzgzNDVhNGE0NjMyM2E0N2JiMjg1YzBmMDFj
14
+ NmNkYzY3MTQxMjYxMTkyZGNkOTI1YTEwMzY4YzYxODg1MjA3NDY0N2U0N2Qz
15
+ OTNkMzNiNDBkYzFhM2E0MjY1Y2I3MzMwMDllMGUzNThiZTdlZWM=
@@ -0,0 +1,12 @@
1
+ Ziggeo Ruby Server SDK
2
+ ======================
3
+
4
+ Ziggeo API (http://ziggeo.com) allows you to integrate video recording and playback with only
5
+ two lines of code in your site, service or app. This is the Ruby Server SDK repository. It's open source,
6
+ so if you want to improve on it, feel free to add a pull request.
7
+
8
+ For Rails applications, you can simply install this repository as a gem.
9
+
10
+ gem "Ziggeo", :git => "https://github.com/Ziggeo/ZiggeoRubySdk.git"
11
+
12
+ Copyright (c) 2014 Ziggeo
@@ -0,0 +1,66 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+ require 'cgi'
5
+
6
+ require_relative "classes/ZiggeoConfig"
7
+ require_relative "classes/ZiggeoConnect"
8
+ require_relative "classes/ZiggeoVideos"
9
+ require_relative "classes/ZiggeoStreams"
10
+ require_relative "classes/ZiggeoAuthtokens"
11
+ require_relative "classes/ZiggeoAuth"
12
+
13
+ # TODO: https://github.com/nicksieger/multipart-post
14
+
15
+ class Ziggeo
16
+
17
+ attr_accessor :token, :private_key, :encryption_key, :config, :connect
18
+ def initialize(token = nil, private_key = nil, encryption_key = nil)
19
+ @token = token
20
+ @private_key = private_key
21
+ @encryption_key = encryption_key
22
+ @config = ZiggeoConfig.new()
23
+ @connect = ZiggeoConnect.new(self)
24
+ @videos = nil
25
+ @streams = nil
26
+ @authtokens = nil
27
+ @auth = nil
28
+ if (ENV["ZIGGEO_URL"] != nil)
29
+ uri = URI.parse(ENV["ZIGGEO_URL"])
30
+ @config.server_api_url = uri.scheme + "://" + uri.host + ":" + uri.port.to_s
31
+ @token = uri.user
32
+ @private_key = uri.password
33
+ query = CGI::parse(uri.query)
34
+ @encryption_key = query["encryption_key"]
35
+ end
36
+ end
37
+
38
+ def videos()
39
+ if (@videos == nil)
40
+ @videos = ZiggeoVideos.new(self)
41
+ end
42
+ return @videos
43
+ end
44
+
45
+ def streams()
46
+ if (@streams == nil)
47
+ @streams = ZiggeoStreams.new(self)
48
+ end
49
+ return @streams
50
+ end
51
+
52
+ def authtokens()
53
+ if (@authtokens == nil)
54
+ @authtokens = ZiggeoAuthtokens.new(self)
55
+ end
56
+ return @authtokens
57
+ end
58
+
59
+ def auth()
60
+ if (@auth == nil)
61
+ @auth = ZiggeoAuth.new(self)
62
+ end
63
+ return @auth
64
+ end
65
+
66
+ end
@@ -0,0 +1,42 @@
1
+ require 'openssl'
2
+ require 'digest/md5'
3
+ require 'securerandom'
4
+ require 'json'
5
+
6
+ class ZiggeoAuth
7
+
8
+ def initialize(application)
9
+ @application = application
10
+ @cipher = nil
11
+ end
12
+
13
+ def _encrypt(plaintext)
14
+ if (@cipher == nil)
15
+ hashed_key = Digest::MD5.hexdigest(@application.encryption_key)
16
+ @cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
17
+ @cipher.encrypt
18
+ @cipher.padding = 1
19
+ @cipher.key = hashed_key
20
+ end
21
+ iv = SecureRandom.hex(8)
22
+ @cipher.iv = iv
23
+ encrypted = @cipher.update(plaintext) + @cipher.final
24
+ encrypted = encrypted.unpack("H*").first
25
+ return iv + encrypted
26
+ end
27
+
28
+ def generate(options = {})
29
+ data = {
30
+ "application_token" => @application.token,
31
+ "nonce" => self._generateNonce()
32
+ }
33
+ data.update(options)
34
+ return self._encrypt(JSON.generate(data))
35
+ end
36
+
37
+ def _generateNonce()
38
+ t = Time.new
39
+ return t.to_i.to_s + rand(256 * 256 * 256 * 256).to_s
40
+ end
41
+
42
+ end
@@ -0,0 +1,23 @@
1
+ class ZiggeoAuthtokens
2
+
3
+ def initialize(application)
4
+ @application = application
5
+ end
6
+
7
+ def get(token)
8
+ return @application.connect.getJSON('/authtokens/' + token + '')
9
+ end
10
+
11
+ def update(token_or_key, data = nil)
12
+ return @application.connect.postJSON('/authtokens/' + token_or_key + '', data)
13
+ end
14
+
15
+ def delete(token_or_key)
16
+ return @application.connect.delete('/authtokens/' + token_or_key + '')
17
+ end
18
+
19
+ def create(data = nil)
20
+ return @application.connect.postJSON('/authtokens/', data)
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ class ZiggeoConfig
2
+ attr_accessor :server_api_url
3
+
4
+ def initialize()
5
+ @server_api_url = "https://srvapi.ziggeo.com"
6
+ end
7
+ end
@@ -0,0 +1,67 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class ZiggeoConnect
5
+ def initialize(application)
6
+ @application = application
7
+ end
8
+
9
+ def request(method, path, data = nil, file = nil)
10
+ url = URI.parse(@application.config.server_api_url + '/v1' + path)
11
+ if (method == "GET")
12
+ if (data != nil)
13
+ url.query = URI.encode_www_form(data)
14
+ end
15
+ req = Net::HTTP::Get.new(url.to_s)
16
+ elsif (method == "POST")
17
+ req = Net::HTTP::Post.new(url.to_s)
18
+ if (data != nil)
19
+ req.req.set_form_data(data)
20
+ end
21
+ elsif (method == "DELETE")
22
+ req = Net::HTTP::Delete.new(url.to_s)
23
+ if (data != nil)
24
+ req.req.set_form_data(data)
25
+ end
26
+ end
27
+ req.basic_auth(@application.token, @application.private_key)
28
+ http = Net::HTTP.new(url.host, url.port)
29
+ if (url.scheme == "https")
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
+ end
33
+ res = http.start() {|agent|
34
+ agent.request(req)
35
+ }
36
+ return res.body
37
+ end
38
+
39
+ def requestJSON(method, path, data = nil, file = nil)
40
+ return JSON.parse self.request(method, path, data, file)
41
+ end
42
+
43
+ def get(path, data = nil, file = nil)
44
+ return self.request("GET", path, data, file)
45
+ end
46
+
47
+ def getJSON(path, data = nil, file = nil)
48
+ return self.requestJSON("GET", path, data, file)
49
+ end
50
+
51
+ def post(path, data = nil, file = nil)
52
+ return self.request("POST", path, data, file)
53
+ end
54
+
55
+ def postJSON(path, data = nil, file = nil)
56
+ return self.requestJSON("POST", path, data, file)
57
+ end
58
+
59
+ def delete(path, data = nil, file = nil)
60
+ return self.request("DELETE", path, data, file)
61
+ end
62
+
63
+ def deleteJSON(path, data = nil, file = nil)
64
+ return self.requestJSON("DELETE", path, data, file)
65
+ end
66
+
67
+ end
@@ -0,0 +1,31 @@
1
+ class ZiggeoStreams
2
+
3
+ def initialize(application)
4
+ @application = application
5
+ end
6
+
7
+ def index(video_token_or_key, data = nil)
8
+ return @application.connect.getJSON('/videos/' + video_token_or_key + '/streams', data)
9
+ end
10
+
11
+ def get(video_token_or_key, token_or_key)
12
+ return @application.connect.getJSON('/videos/' + video_token_or_key + '/streams/' + token_or_key + '')
13
+ end
14
+
15
+ def download_video(video_token_or_key, token_or_key)
16
+ return @application.connect.get('/videos/' + video_token_or_key + '/streams/' + token_or_key + '/video')
17
+ end
18
+
19
+ def download_image(video_token_or_key, token_or_key)
20
+ return @application.connect.get('/videos/' + video_token_or_key + '/streams/' + token_or_key + '/image')
21
+ end
22
+
23
+ def delete(video_token_or_key, token_or_key)
24
+ return @application.connect.delete('/videos/' + video_token_or_key + '/streams/' + token_or_key + '')
25
+ end
26
+
27
+ def create(video_token_or_key, data = nil, file = nil)
28
+ return @application.connect.postJSON('/videos/' + video_token_or_key + '/streams', data, file)
29
+ end
30
+
31
+ end
@@ -0,0 +1,35 @@
1
+ class ZiggeoVideos
2
+
3
+ def initialize(application)
4
+ @application = application
5
+ end
6
+
7
+ def index(data = nil)
8
+ return @application.connect.getJSON('/videos/', data)
9
+ end
10
+
11
+ def get(token_or_key)
12
+ return @application.connect.getJSON('/videos/' + token_or_key + '')
13
+ end
14
+
15
+ def download_video(token_or_key)
16
+ return @application.connect.get('/videos/' + token_or_key + '/video')
17
+ end
18
+
19
+ def download_image(token_or_key)
20
+ return @application.connect.get('/videos/' + token_or_key + '/image')
21
+ end
22
+
23
+ def update(token_or_key, data = nil)
24
+ return @application.connect.postJSON('/videos/' + token_or_key + '', data)
25
+ end
26
+
27
+ def delete(token_or_key)
28
+ return @application.connect.delete('/videos/' + token_or_key + '')
29
+ end
30
+
31
+ def create(data = nil, file = nil)
32
+ return @application.connect.postJSON('/videos/', data, file)
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Ziggeo
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Ziggeo, Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The Ziggeo Ruby and Rails Server SDK.
14
+ email:
15
+ - support@ziggeo.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - lib/Ziggeo.rb
22
+ - lib/classes/ZiggeoAuth.rb
23
+ - lib/classes/ZiggeoAuthtokens.rb
24
+ - lib/classes/ZiggeoConfig.rb
25
+ - lib/classes/ZiggeoConnect.rb
26
+ - lib/classes/ZiggeoStreams.rb
27
+ - lib/classes/ZiggeoVideos.rb
28
+ homepage: http://ziggeo.com
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.2.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: The Ziggeo ServerSDK gem.
52
+ test_files: []