vuzitruby 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -5,7 +5,7 @@
5
5
  This is a library that allows developers to directly access the Vuzit Web
6
6
  Service API through a simple Ruby script:
7
7
 
8
- http://vuzit.com/developer/documents_api
8
+ http://vuzit.com/developer/web_service_api
9
9
 
10
10
  Below is a basic upload example:
11
11
 
@@ -95,6 +95,8 @@ Upload and View with the JavaScript API Example for a Rails RHTML file:
95
95
 
96
96
  == LICENSE
97
97
 
98
+ Copyright (c) 2009-2010 Brent Matzelle, Vuzit LLC
99
+
98
100
  Released under the MIT license:
99
101
 
100
102
  http://www.opensource.org/licenses/mit-license.php
data/bin/vuzitcl CHANGED
@@ -83,6 +83,8 @@ def help_command(args)
83
83
  print_usage_delete
84
84
  when "upload"
85
85
  print_usage_upload
86
+ when "search"
87
+ print_usage_search
86
88
  else
87
89
  error("Unknown option: [#{command}]")
88
90
  end
@@ -109,6 +111,51 @@ def load_command(args)
109
111
  end
110
112
  end
111
113
 
114
+ # Performs the search command.
115
+ def search_command(args)
116
+ return if !global_parameters_load(args)
117
+
118
+ options = Hash.new
119
+ opts = OptionParser.new do |opts|
120
+ opts.on("-q", "--query [QUERY]", "") do |value|
121
+ options[:query] = value
122
+ end
123
+
124
+ opts.on("-l", "--limit [LIMIT]", "") do |value|
125
+ options[:limit] = value
126
+ end
127
+
128
+ opts.on("-o", "--offset [OFFSET]", "") do |value|
129
+ options[:offset] = value
130
+ end
131
+ end
132
+
133
+ begin
134
+ opts.parse!(args)
135
+ rescue OptionParser::InvalidOption => e
136
+ e.recover(args)
137
+ end
138
+
139
+ begin
140
+ docs = Vuzit::Document.find_all(options)
141
+
142
+ docs.each do |doc|
143
+ puts "LOADED: #{doc.id}"
144
+ puts "title: #{doc.title}"
145
+ puts "subject: #{doc.subject}"
146
+ puts "pages: #{doc.page_count}"
147
+ puts "width: #{doc.page_width}"
148
+ puts "height: #{doc.page_height}"
149
+ puts "size: #{doc.file_size}"
150
+ puts "status: #{doc.status}"
151
+ puts "excerpt: #{doc.excerpt}"
152
+ puts ''
153
+ end
154
+ rescue Vuzit::ClientException => ex
155
+ puts "Error occurred: #{ex.code}, #{ex.message}"
156
+ end
157
+ end
158
+
112
159
  # Performs the load command.
113
160
  def upload_command(args)
114
161
  path = args.pop
@@ -166,9 +213,10 @@ def print_usage_general
166
213
  puts ""
167
214
  puts "Available commands:"
168
215
  puts ""
169
- puts " upload"
170
216
  puts " delete"
171
217
  puts " load"
218
+ puts " upload"
219
+ puts " search"
172
220
  puts " help"
173
221
  end
174
222
 
@@ -190,9 +238,22 @@ def print_usage_load
190
238
  print_usage_global
191
239
  end
192
240
 
241
+ # Prints the search options
242
+ def print_usage_search
243
+ puts "search: Searches for documents within Vuzit."
244
+ puts "usage: search [OPTIONS]"
245
+ puts ""
246
+ puts "Valid options:"
247
+ puts " -q, --query Query keywords"
248
+ puts " -l, --limit Limits the results to a number"
249
+ puts " -o, --offset Offsets the results at this number"
250
+ puts ""
251
+ print_usage_global
252
+ end
253
+
193
254
  # Prints the upload options
194
255
  def print_usage_upload
195
- puts "upload: Upload a file to Vuzit."
256
+ puts "upload: Upload a document to Vuzit."
196
257
  puts "usage: upload [OPTIONS] PATH"
197
258
  puts ""
198
259
  puts "Valid options:"
@@ -212,6 +273,8 @@ case command
212
273
  load_command(ARGV)
213
274
  when "delete"
214
275
  delete_command(ARGV)
276
+ when "search"
277
+ search_command(ARGV)
215
278
  when "upload"
216
279
  upload_command(ARGV)
217
280
  when "help"
@@ -33,6 +33,23 @@ module Vuzit
33
33
  return result
34
34
  end
35
35
 
36
+ # Returns the value of a child node.
37
+ def self.node_value(node, key)
38
+ result = nil
39
+
40
+ if node.elements[key] != nil
41
+ result = node.elements[key].text
42
+ end
43
+
44
+ return result
45
+ end
46
+
47
+ # Returns the integer value of a child node or -1 if none.
48
+ def self.node_value_int(node, key)
49
+ text = node_value(node, key)
50
+ return (text == nil) ? -1 : text.to_i
51
+ end
52
+
36
53
  # Returns a clean version of the parameters hash table.
37
54
  def self.parameters_clean(params)
38
55
  result = Hash.new
@@ -80,13 +97,7 @@ module Vuzit
80
97
  timestamp = Time.now
81
98
  params[:timestamp] = timestamp.to_i # time since epoch
82
99
 
83
- pages = ''
84
- if params.has_key?(:included_pages)
85
- pages = params[:included_pages]
86
- end
87
- label = ''
88
-
89
- signature = Vuzit::Service::signature(method, id, timestamp, pages, label)
100
+ signature = Vuzit::Service::signature(method, id, timestamp, params)
90
101
  params[:signature] = signature
91
102
 
92
103
  return params
@@ -101,6 +112,12 @@ module Vuzit
101
112
  request = Net::HTTP::Post.new('/documents', {'User-Agent' => Vuzit::Service.user_agent})
102
113
  request.multipart_params = parameters_clean(fields)
103
114
 
115
+ # If the stream is over 3 megabytes in size
116
+ if fields[:upload].stat.size > (3 * 1048576)
117
+ # Set the timeout to 5 minutes
118
+ http.read_timeout = (5 * 60 * 1000)
119
+ end
120
+
104
121
  tries = 3
105
122
  begin
106
123
  tries -= 1
@@ -13,11 +13,12 @@ module Vuzit
13
13
  attr_reader :page_height # Page height of the document in pixels
14
14
  attr_reader :file_size # File size of the original document bytes
15
15
  attr_reader :status # Status of the document
16
+ attr_reader :excerpt # Text excerpt of the document
16
17
 
17
18
  # Constructor.
18
19
  def initialize #:nodoc:
19
20
  # Set the defaults
20
- @id = @title = @subject = nil
21
+ @id = @title = @subject = @excerpt = nil
21
22
  @page_count = @page_width = @page_height = @file_size = @status = -1
22
23
  end
23
24
 
@@ -89,18 +90,47 @@ module Vuzit
89
90
 
90
91
  id = doc.root.elements['web_id']
91
92
  if id == nil
92
- raise Vuzit::ClientException.new("Unknown error occurred");
93
+ raise Vuzit::ClientException.new("The web_id element missing - unknown error occurred");
93
94
  end
94
95
 
95
- result = Vuzit::Document.new
96
- result.send(:set_id, id.text)
97
- result.send(:set_title, doc.root.elements['title'].text)
98
- result.send(:set_subject, doc.root.elements['subject'].text)
99
- result.send(:set_page_count, doc.root.elements['page_count'].text.to_i)
100
- result.send(:set_page_width, doc.root.elements['width'].text.to_i)
101
- result.send(:set_page_height, doc.root.elements['height'].text.to_i)
102
- result.send(:set_file_size, doc.root.elements['file_size'].text.to_i)
103
- result.send(:set_status, doc.root.elements['status'].text.to_i)
96
+ result = xml_to_document(doc.root)
97
+
98
+ return result
99
+ end
100
+
101
+ # Performs a search to return all documents as defined by the options.
102
+ def self.find_all(options = {})
103
+ raise ArgumentError, "Options must be a hash" unless options.kind_of? Hash
104
+
105
+ result = Array.new
106
+ options[:output] = "summary"
107
+ params = post_parameters("index", options)
108
+ url = parameters_to_url("documents", params)
109
+ http = http_connection
110
+
111
+ request = Net::HTTP::Get.new(url, {'User-Agent' => Vuzit::Service.user_agent})
112
+ response = http.start { http.request(request) }
113
+
114
+ # TODO: Check if response.code.to_i != 200
115
+
116
+ begin
117
+ doc = REXML::Document.new(response.body)
118
+ rescue Exception => ex
119
+ raise Vuzit::ClientException.new("XML error: #{ex.message}")
120
+ end
121
+
122
+ if doc.root == nil
123
+ raise Vuzit::ClientException.new("No response from server");
124
+ end
125
+
126
+ code = doc.root.elements['code']
127
+ if code != nil
128
+ raise Vuzit::ClientException.new(doc.root.elements['msg'].text, code.text.to_i);
129
+ end
130
+
131
+ doc.root.elements.each("document") do |node|
132
+ result << xml_to_document(node)
133
+ end
104
134
 
105
135
  return result
106
136
  end
@@ -115,12 +145,20 @@ module Vuzit
115
145
 
116
146
  params = post_parameters("create", options)
117
147
  response = nil
118
-
119
- File.open(file, "rb") do |f|
120
- params[:upload] = f
121
- response = send_request 'create', params
148
+
149
+ # Determine type and set to IO for data such as that from a database
150
+ case file
151
+ when IO
152
+ f = file
153
+ when String
154
+ f = File.open(file, 'rb')
155
+ else
156
+ raise ArgumentError, 'Expects String or IO argument'
122
157
  end
123
158
 
159
+ params[:upload] = f
160
+ response = send_request 'create', params
161
+
124
162
  # TODO: check the response.code.to_i to make sure it's 201
125
163
 
126
164
  begin
@@ -151,6 +189,23 @@ module Vuzit
151
189
 
152
190
  private
153
191
 
192
+ # Converts an XML object to a Document instance.
193
+ def self.xml_to_document(node)
194
+ result = Vuzit::Document.new
195
+
196
+ result.send(:set_id, node_value(node, 'web_id'))
197
+ result.send(:set_title, node_value(node, 'title'))
198
+ result.send(:set_subject, node_value(node, 'subject'))
199
+ result.send(:set_page_count, node_value_int(node, 'page_count'))
200
+ result.send(:set_page_width, node_value_int(node, 'width'))
201
+ result.send(:set_page_height, node_value_int(node, 'height'))
202
+ result.send(:set_file_size, node_value_int(node, 'file_size'))
203
+ result.send(:set_status, node_value_int(node, 'status'))
204
+ result.send(:set_excerpt, node_value(node, 'excerpt'))
205
+
206
+ return result
207
+ end
208
+
154
209
  # Private setter methods so that you can set the internal variables but
155
210
  # not allow the setting of the public methods.
156
211
  def set_id(value) @id = value; end
@@ -161,5 +216,6 @@ module Vuzit
161
216
  def set_page_width(value) @page_width = value; end
162
217
  def set_page_height(value) @page_height = value; end
163
218
  def set_file_size(value) @file_size = value; end
219
+ def set_excerpt(value) @excerpt = value; end
164
220
  end
165
221
  end
@@ -47,7 +47,7 @@ module Vuzit
47
47
  @@public_key = nil
48
48
  @@private_key = nil
49
49
  @@service_url = 'http://vuzit.com'
50
- @@product_name = 'VuzitRuby Library 1.2.1'
50
+ @@product_name = 'VuzitRuby Library 2.0.0'
51
51
  @@user_agent = @@product_name
52
52
 
53
53
  # TODO: For all of the set variables do not allow nil values
@@ -103,7 +103,7 @@ module Vuzit
103
103
  # Returns The signature string. NOTE: If you are going to use this
104
104
  # with the Vuzit Javascript API then the value must be encoded with the
105
105
  # CGI.escape function. See the Wiki example for more information.
106
- def self.signature(service, id = '', time = nil, pages = '', label = '')
106
+ def self.signature(service, id = '', time = nil, options = {})
107
107
  if Vuzit::Service.public_key == nil || Vuzit::Service.private_key == nil
108
108
  raise Vuzit::ClientException.new("The public_key or private_key variables are nil")
109
109
  end
@@ -117,7 +117,14 @@ module Vuzit
117
117
  raise Vuzit::ClientException.new("Vuzit::Service.private_key not set")
118
118
  end
119
119
 
120
- msg = "#{service}#{id}#{@@public_key}#{time}#{pages}#{label}"
120
+ msg = "#{service}#{id}#{@@public_key}#{time}"
121
+
122
+ ['included_pages', 'watermark', 'query'].each do |item|
123
+ if options.include?(item.to_sym)
124
+ msg << options[item.to_sym].to_s
125
+ end
126
+ end
127
+
121
128
  hmac = hmac_sha1(@@private_key, msg)
122
129
  result = Base64::encode64(hmac).chomp
123
130
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vuzitruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Matzelle
@@ -9,11 +9,14 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-31 00:00:00 -04:00
12
+ date: 2010-02-08 00:00:00 -05:00
13
13
  default_executable: vuzitcl
14
14
  dependencies: []
15
15
 
16
- description: This is a library for the Vuzit Web Services API. For more information on the platform, visit http://vuzit.com/developer
16
+ description: |-
17
+ This is a library for the Vuzit Web Services API. For
18
+ more information on the platform, visit
19
+ http://vuzit.com/developer
17
20
  email: support@vuzit.com
18
21
  executables:
19
22
  - vuzitcl
@@ -31,6 +34,8 @@ files:
31
34
  - lib/vuzitruby/service.rb
32
35
  has_rdoc: true
33
36
  homepage: http://vuzit.com/
37
+ licenses: []
38
+
34
39
  post_install_message:
35
40
  rdoc_options:
36
41
  - --main
@@ -52,9 +57,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
57
  requirements: []
53
58
 
54
59
  rubyforge_project: vuzitruby
55
- rubygems_version: 1.3.1
60
+ rubygems_version: 1.3.5
56
61
  signing_key:
57
- specification_version: 2
62
+ specification_version: 3
58
63
  summary: Ruby client library for the Vuzit Web Services API
59
64
  test_files: []
60
65