Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions lib/vdocipher.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
require "net/http"
require "json"

class VdoCipher
@@version = '1.1.0'
@@version = '1.1.1'
attr_reader :version

def initialize(conf, version = '1.1.3')
@key = conf[:clientSecretKey]
@version = version
end

def play_code(id, attr="", theme="9ae8bbe8dd964ddc9bdb932cca1cb59a")
if (@key == nil)
return "key not set"
end
url = URI.parse('https://api.vdocipher.com/v2/otp?video='+ id)
req = Net::HTTP::Post.new(url.to_s)
req.body = 'clientSecretKey=' + @key
return "key not set" if (@key == nil)

url = URI.parse("https://dev.vdocipher.com/api/videos/#{id}/otp")

header = { 'Content-Type': 'text/json', 'Authorization': "Apisecret #{@key}" }

req = Net::HTTP::Post.new(url.request_uri, header)
res = Net::HTTP.start(url.host, url.port, use_ssl:true) {|http|
http.request(req)
}

if(res.code != "200")
return 'Status code error: ' + res.code
end

otp = JSON.parse(res.body)
if( otp['error'] == "No video found" )
return "video not found"
end

# make the theme configurable
div_id = Time.now.to_i

embedcode = <<EOS
<div id="vdo%s" %s></div>
<div id="vdo#{div_id}"></div>
<script>
(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){ (v[o].d=v[o].d||[]).push(a);};
if(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0];
a.async=1; a.src=e; m.parentNode.insertBefore(a,m);}
})(window,document,"script","https://d1z78r8i505acl.cloudfront.net/playerAssets/%s/vdo.js","vdo");
(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){
(v[o].d=v[o].d||[]).push(a);};if(!v[o].l) { v[o].l=1*new Date();
a=i.createElement(d); m=i.getElementsByTagName(d)[0]; a.async=1; a.src=e;
m.parentNode.insertBefore(a,m);}})(window,document,"script",
"https://player.vdocipher.com/playerAssets/1.6.10/vdo.js","vdo");
vdo.add({
otp: "%s",
otp: "#{otp["otp"]}",
playbackInfo: btoa(JSON.stringify({
videoId: "%s"
videoId: "#{id}"
})),
theme: "%s",
container: document.querySelector( "#vdo%s" ),
theme: "#{theme}",
container: document.querySelector( "#vdo#{div_id}" ),
});
</script>

EOS
embedcode = embedcode % [otp["otp"], attr, version, otp["otp"], id, theme, otp["otp"]]
embedcode
end
end

end
2 changes: 1 addition & 1 deletion vdocipher.gemspec
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'vdocipher'
s.version = '1.1.0'
s.version = '1.1.1'
s.date = '2017-08-24'
s.summary = "VdoCipher API interface"
s.description = "Stream and manage videos hosted through vdocipher streaming service."
Expand Down