-
Notifications
You must be signed in to change notification settings - Fork 2
Code_Examples
bmatzelle edited this page Apr 1, 2013
·
7 revisions
Below are a few simple examples using VuzitRuby.
Below is an example that shows how include Vuzit and upload a simple file:
require "vuzitruby"
Vuzit::Service.public_key = 'YOUR_PUBLIC_API_KEY'
Vuzit::Service.private_key = 'YOUR_PRIVATE_API_KEY'
doc = Vuzit::Document.upload("c:/path/to/document.pdf")
puts "Document id: " + doc.id
Below shows how to load a document.
require "vuzitruby"
Vuzit::Service.public_key = 'YOUR_PUBLIC_API_KEY'
Vuzit::Service.private_key = 'YOUR_PRIVATE_API_KEY'
doc = Vuzit::Document.find("DOCUMENT_ID")
puts "Document id: " + doc.id
puts "Document title: " + doc.title
Search for for the first 5 documents that match “linda”:
Vuzit::Service.public_key = 'YOUR_PUBLIC_API_KEY'
Vuzit::Service.private_key = 'YOUR_PRIVATE_API_KEY'
doc = Vuzit::Document.find_all(:query => "john smith", :limit => 5)
docs.each do |doc|
puts "Document id: " + doc.id;
puts "Document title: " + doc.title;
end
Example for deleting a document.
require "vuzitruby"
Vuzit::Service.public_key = 'YOUR_PUBLIC_API_KEY'
Vuzit::Service.private_key = 'YOUR_PRIVATE_API_KEY'
doc = Vuzit::Document.destroy("DOCUMENT_ID")
Complete end-to-end example for uploading a document and viewing it with the JavaScript API using a Rails RHTML file:
<%
require "vuzitruby"
require 'cgi'
Vuzit::Service.public_key = 'YOUR_PUBLIC_API_KEY'
Vuzit::Service.private_key = 'YOUR_PRIVATE_API_KEY'
doc_id = "XXXXXXXX"
timestamp = Time.now
sig = Vuzit::Service.signature("show", doc_id, timestamp)
%>
<html>
<head>
<link href="http://vuzit.com/stylesheets/Vuzit-2.10.css" rel="Stylesheet" type="text/css" />
<script src="http://vuzit.com/javascripts/Vuzit-2.10.js" type="text/javascript"></script>
<script type="text/javascript">
// Called when the page is loaded.
function initialize() {
vuzit.Base.apiKeySet("<%= Vuzit::Service.public_key %>");
var options = {signature: '<%= CGI.escape(sig) %>',
timestamp: '<%= timestamp.to_i %>', ssl: true}
var viewer = vuzit.Viewer.fromId("<%= doc_id %>", options);
viewer.display(document.getElementById("vuzit_viewer"), { zoom: 1 });
}
</script>
</head>
<body onload="initialize()">
<div id="vuzit_viewer" style="width: 650px; height: 500px;"></div>
</body>
</html>