voltrb 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ VoltRB is a gem client for VoltDB that uses the JSON interface.
4
4
 
5
5
  = Installing VoltRb
6
6
 
7
- Get from RubyForge.
7
+ Get from RubyGems.org:
8
8
 
9
9
  % gem install voltrb
10
10
 
@@ -40,12 +40,12 @@ Or we can specify options as a hash.
40
40
 
41
41
  client = VoltRb::Client.new({:host => "voltdbhost", :port => 8888})
42
42
 
43
- Right now, VoltRb only knows two:
43
+ The following options are recognized:
44
44
 
45
45
  * host - should point to the name or IP address of the VoltDB instance.
46
46
  * port - in case the instance isn't listening on the default port (8080).
47
-
48
- There are no options yet for authentication since the JSON interface doesn't implement any. See Notes for more.
47
+ * username
48
+ * password
49
49
 
50
50
  == Stored Procedure Invocation
51
51
 
@@ -113,30 +113,6 @@ Standard Ruby errors will be raised in case of network connection problems. Volt
113
113
 
114
114
  at Insert.run(Insert.java:19)
115
115
  ========================================================
116
-
117
- = Notes
118
-
119
- == User Authentication
120
-
121
- As of VoltDB v1.1, the JSON interface does not implement any form of authentication.
122
-
123
- The following text was taken from VoltDB's JSON documentation:
124
-
125
- <em>Note that there is currently no way to authenticate the client interface using JSON. In other words, the JSON interface operates as an "anonymous" client. If security is enabled for the database, use of the JSON interface is essentially disabled because any attempt to execute a stored procedure will result in a protection violation.</em>
126
-
127
- This forum thread says they expect to have the feature in v1.2
128
-
129
- http://community.voltdb.com/node/241
130
-
131
- == Unicode Strings
132
-
133
- As of v1.1 VoltDB's JSON interface does not properly return UTF-8 strings so non-Latin characters don't display correctly.
134
-
135
- http://community.voltdb.com/node/263
136
-
137
- The fix is now in their trunk version. It'll be included in the next official release of VoltDB (v1.2). Or you can build directly from trunk.
138
-
139
- svn checkout http://svnmirror.voltdb.com/eng/trunk/
140
116
 
141
117
  = License
142
118
 
@@ -9,4 +9,5 @@ require 'voltrb/exceptions'
9
9
  require 'voltrb/volt_table'
10
10
  require 'voltrb/procedure_response'
11
11
  require 'voltrb/client'
12
+ require 'voltrb/version'
12
13
 
@@ -3,6 +3,7 @@ require 'rest_client'
3
3
  require 'date'
4
4
  require 'time'
5
5
  require 'bigdecimal'
6
+ require 'digest/sha1'
6
7
 
7
8
  module VoltRb
8
9
  # This is the main class we use to interact with the VoltDB instance.
@@ -48,7 +49,7 @@ module VoltRb
48
49
  # We can find the details of the error by inspecting status_string or app_status_string.
49
50
  # See VoltError for more.
50
51
  class Client
51
- attr_reader :host, :port
52
+ attr_reader :host, :port, :username
52
53
  attr_accessor :api_root
53
54
 
54
55
  # Calling new without any arguments will create a client and have it connect to the VoltDB instance running
@@ -56,16 +57,17 @@ module VoltRb
56
57
  # Pass an options hash to modify these defaults.
57
58
  # client = VoltRb::Client.new({:host => "voltdb_server", :port => 8888})
58
59
  #
59
- # Right now, only two options are recognized:
60
+ # The following options are recognized:
60
61
  # * host - the machine name or IP address
61
62
  # * port - other than the default
63
+ # * username
64
+ # * password
62
65
  #
63
- # <em>Note on user authentication:</em>
64
- # As of v1.1, the VoltDB JSON interface does not implement any form of authentication.
65
- # See the README[link:files/README.html] for more.
66
66
  def initialize(options = {})
67
67
  @host = options[:host] || "localhost"
68
68
  @port = options[:port] || 8080
69
+ @username= options[:username]
70
+ @hashed_password = Digest::SHA1.hexdigest(options[:password]) if options[:password]
69
71
  @api_root = "http://#{@host}:#{@port}/api/1.0/"
70
72
  end
71
73
 
@@ -87,12 +89,20 @@ module VoltRb
87
89
  # In case of errors, handle the usual Ruby errors and the VoltDB-specfic VoltError (this inherits from StandardError).
88
90
  def call_procedure(procedure_name, *args)
89
91
  params = args.inject([]) { |o,e| o << prep_param(e); o }
90
- response = RestClient.post(@api_root, :Procedure => procedure_name.to_s, :Parameters => params.to_json, :content_type => "text/plain; charset=UTF-8", :accept => :json)
92
+ payload = {:Procedure => procedure_name.to_s, :Parameters => params.to_json}
93
+ if @username
94
+ payload[:User] = @username
95
+ payload[:Hashedpassword] = @hashed_password
96
+ end
97
+ response = RestClient.post(@api_root, payload, :content_type => "text/plain; charset=UTF-8", :accept => :json)
91
98
  proc_resp = ProcedureResponse.new(response)
92
99
  raise(VoltError.new(proc_resp.status, proc_resp.status_string, proc_resp.app_status, proc_resp.app_status_string), "A VoltDB procedure error occurred. See the exception object for details.") if proc_resp.raw["status"] != 1 or proc_resp.raw["appstatus"] != -128
93
100
  proc_resp
94
101
  end
95
102
 
103
+ # Alias for call_procedure. Term used in other client libraries.
104
+ alias :invoke :call_procedure
105
+
96
106
  private
97
107
  def prep_param(val)
98
108
  case val
@@ -1,5 +1,5 @@
1
1
  module VoltRb
2
2
  # This gem's version.
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
 
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Junjun Olympia
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-07 00:00:00 +08:00
18
+ date: 2010-11-01 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency