Class: VdoCipher
- Inherits:
-
Object
- Object
- VdoCipher
- Defined in:
- lib/vdocipher.rb
Constant Summary collapse
- @@version =
'1.1.0'
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(conf, version = '1.1.3') ⇒ VdoCipher
constructor
A new instance of VdoCipher.
- #play_code(id, attr = "", theme = "9ae8bbe8dd964ddc9bdb932cca1cb59a") ⇒ Object
Constructor Details
#initialize(conf, version = '1.1.3') ⇒ VdoCipher
Returns a new instance of VdoCipher.
7 8 9 10 |
# File 'lib/vdocipher.rb', line 7 def initialize(conf, version = '1.1.3') @key = conf[:clientSecretKey] @version = version end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/vdocipher.rb', line 5 def version @version end |
Instance Method Details
#play_code(id, attr = "", theme = "9ae8bbe8dd964ddc9bdb932cca1cb59a") ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vdocipher.rb', line 11 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 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=\"vdo%s\" %s></div>\n<script>\n(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);};\nif(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0];\na.async=1; a.src=e; m.parentNode.insertBefore(a,m);}\n})(window,document,\"script\",\"https://d1z78r8i505acl.cloudfront.net/playerAssets/%s/vdo.js\",\"vdo\");\nvdo.add({\notp: \"%s\",\nplaybackInfo: btoa(JSON.stringify({\n videoId: \"%s\"\n})),\ntheme: \"%s\",\ncontainer: document.querySelector( \"#vdo%s\" ),\n});\n</script>\n\n" = % [otp["otp"], attr, version, otp["otp"], id, theme, otp["otp"]] end |