vuzitruby 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/vuzitcl CHANGED
@@ -349,10 +349,10 @@ def print_usage_event
349
349
  puts "usage: event [OPTIONS] WEB_ID"
350
350
  puts ""
351
351
  puts "Valid options:"
352
- puts " -e, --event Event type to load"
353
- puts " -c, --custom Custom value to load"
354
- puts " -l, --limit Limits the number of results"
355
- puts " -o, --offset Offset the results at this number"
352
+ puts " -e, --event Event type to load"
353
+ puts " -c, --custom Custom value to load"
354
+ puts " -l, --limit Limits the number of results"
355
+ puts " -o, --offset Offset the results at this number"
356
356
  puts ""
357
357
  print_usage_global
358
358
  end
@@ -381,9 +381,9 @@ def print_usage_page
381
381
  puts "usage: page [OPTIONS] WEB_ID"
382
382
  puts ""
383
383
  puts "Valid options:"
384
- puts " -i, --included Set range of pages to load (e.g '5,10-19')"
385
- puts " -l, --limit Limits the results to a number"
386
- puts " -o, --offset Offsets the results at this number"
384
+ puts " -i, --included Set range of pages to load (e.g '5,10-19')"
385
+ puts " -l, --limit Limits the results to a number"
386
+ puts " -o, --offset Offsets the results at this number"
387
387
  puts ""
388
388
  print_usage_global
389
389
  end
@@ -394,9 +394,10 @@ def print_usage_search
394
394
  puts "usage: search [OPTIONS]"
395
395
  puts ""
396
396
  puts "Valid options:"
397
- puts " -q, --query Query keywords"
398
- puts " -l, --limit Limits the results to a number"
399
- puts " -o, --offset Offsets the results at this number"
397
+ puts " -q, --query Query keywords"
398
+ puts " -o, --offset Offsets the results at this number"
399
+ puts " -l, --limit Limits the results to a number"
400
+ puts " -O, --output Output more document info including title and excerpt"
400
401
  puts ""
401
402
  print_usage_global
402
403
  end
@@ -0,0 +1,98 @@
1
+ require 'rexml/document'
2
+
3
+ module Vuzit
4
+
5
+ # Class for loading document event analytics.
6
+ class Event < Base
7
+ attr_reader :web_id
8
+ attr_reader :event
9
+ attr_reader :remote_host
10
+ attr_reader :referer
11
+ attr_reader :user_agent
12
+ attr_reader :custom
13
+ attr_reader :requested_at
14
+ attr_reader :page
15
+ attr_reader :duration
16
+
17
+ # Constructor.
18
+ def initialize #:nodoc:
19
+ # Set the defaults
20
+ @web_id = @page = @duration = -1
21
+ @event = @remote_host = @referer = @user_agent = @custom = @requested_at = nil
22
+ end
23
+
24
+ # Performs a search to return all documents as defined by the options.
25
+ def self.find_all(id, options = {})
26
+ raise Vuzit::ClientException.new("id cannot be null") if id.nil?
27
+ raise ArgumentError, "Options must be a hash" unless options.kind_of? Hash
28
+
29
+ result = Array.new
30
+ params = post_parameters("show", options, id)
31
+ params[:web_id] = id
32
+ url = parameters_to_url("events.xml", params)
33
+ http = http_connection
34
+
35
+ request = Net::HTTP::Get.new(url, {'User-Agent' => Vuzit::Service.user_agent})
36
+ response = http.start { http.request(request) }
37
+
38
+ # TODO: Check if response.code.to_i != 200
39
+
40
+ begin
41
+ doc = REXML::Document.new(response.body)
42
+ rescue Exception => ex
43
+ raise Vuzit::ClientException.new("XML error: #{ex.message}")
44
+ end
45
+
46
+ if doc.root == nil
47
+ raise Vuzit::ClientException.new("No response from server");
48
+ end
49
+
50
+ code = doc.root.elements['code']
51
+ if code != nil
52
+ raise Vuzit::ClientException.new(doc.root.elements['msg'].text, code.text.to_i);
53
+ end
54
+
55
+ doc.root.elements.each("event") do |node|
56
+ result << xml_to_event(node)
57
+ end
58
+
59
+ return result
60
+ end
61
+
62
+ private
63
+
64
+ # Converts an XML object to an Event instance.
65
+ def self.xml_to_event(node)
66
+ result = Vuzit::Event.new
67
+
68
+ id = node_value(node, "web_id")
69
+ if id == nil
70
+ raise Vuzit::ClientException.new("Unknown error occurred: #{response_body}");
71
+ end
72
+
73
+ result.send(:set_web_id, id)
74
+ result.send(:set_event, node_value(node, 'event'))
75
+ result.send(:set_remote_host, node_value(node, 'remote_host'))
76
+ result.send(:set_referer, node_value(node, 'referer'))
77
+ result.send(:set_user_agent, node_value(node, 'user_agent'))
78
+ result.send(:set_custom, node_value(node, 'custom'))
79
+ result.send(:set_requested_at, node_value_int(node, 'requested_at'))
80
+ result.send(:set_page, node_value_int(node, 'page'))
81
+ result.send(:set_duration, node_value_int(node, 'duration'))
82
+
83
+ return result
84
+ end
85
+
86
+ # Private setter methods so that you can set the internal variables but
87
+ # not allow the setting of the public methods.
88
+ def set_web_id(value) @web_id = value; end
89
+ def set_event(value) @event = value; end
90
+ def set_remote_host(value) @remote_host = value; end
91
+ def set_referer(value) @referer = value; end
92
+ def set_user_agent(value) @user_agent = value; end
93
+ def set_custom(value) @custom = value; end
94
+ def set_requested_at(value) @requested_at = Time.at(value); end
95
+ def set_page(value) @page = value; end
96
+ def set_duration(value) @duration = value; end
97
+ end
98
+ end
@@ -0,0 +1,70 @@
1
+ require 'rexml/document'
2
+
3
+ module Vuzit
4
+
5
+ # Class for loading the Vuzit pages API.
6
+ class Page < Base
7
+ attr_reader :number
8
+ attr_reader :text
9
+
10
+ # Constructor.
11
+ def initialize #:nodoc:
12
+ # Set the defaults
13
+ @number = -1
14
+ @text = nil
15
+ end
16
+
17
+ # Performs a search to return all documents as defined by the options.
18
+ def self.find_all(id, options = {})
19
+ raise Vuzit::ClientException.new("id cannot be null") if id.nil?
20
+ raise ArgumentError, "Options must be a hash" unless options.kind_of? Hash
21
+
22
+ result = Array.new
23
+ params = post_parameters("index", options, id)
24
+ url = parameters_to_url("documents/#{id}/pages.xml", params)
25
+ http = http_connection
26
+
27
+ request = Net::HTTP::Get.new(url, {'User-Agent' => Vuzit::Service.user_agent})
28
+ response = http.start { http.request(request) }
29
+
30
+ # TODO: Check if response.code.to_i != 200
31
+
32
+ begin
33
+ doc = REXML::Document.new(response.body)
34
+ rescue Exception => ex
35
+ raise Vuzit::ClientException.new("XML error: #{ex.message}")
36
+ end
37
+
38
+ if doc.root == nil
39
+ raise Vuzit::ClientException.new("No response from server");
40
+ end
41
+
42
+ code = doc.root.elements['code']
43
+ if code != nil
44
+ raise Vuzit::ClientException.new(doc.root.elements['msg'].text, code.text.to_i); end
45
+
46
+ doc.root.elements.each("page") do |node|
47
+ result << xml_to_page(node)
48
+ end
49
+
50
+ return result
51
+ end
52
+
53
+ private
54
+
55
+ # Converts an XML object to a Page instance.
56
+ def self.xml_to_page(node)
57
+ result = Vuzit::Page.new
58
+
59
+ result.send(:set_number, node_value_int(node, 'number'))
60
+ result.send(:set_text, node_value(node, 'text'))
61
+
62
+ return result
63
+ end
64
+
65
+ # Private setter methods so that you can set the internal variables but
66
+ # not allow the setting of the public methods.
67
+ def set_number(value) @number = value; end
68
+ def set_text(value) @text = value; end
69
+ end
70
+ 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 2.1.0'
50
+ @@product_name = 'VuzitRuby Library 2.1.1'
51
51
  @@user_agent = @@product_name
52
52
 
53
53
  # TODO: For all of the set variables do not allow nil values
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: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Matzelle
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-20 00:00:00 -04:00
12
+ date: 2010-04-22 00:00:00 -04:00
13
13
  default_executable: vuzitcl
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,8 @@ files:
29
29
  - lib/vuzitruby.rb
30
30
  - lib/vuzitruby/base.rb
31
31
  - lib/vuzitruby/document.rb
32
+ - lib/vuzitruby/event.rb
33
+ - lib/vuzitruby/page.rb
32
34
  - lib/vuzitruby/client_exception.rb
33
35
  - lib/vuzitruby/service.rb
34
36
  has_rdoc: true