riakrest 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +20 -0
- data/README.rdoc +3 -3
- data/VERSION +1 -1
- data/examples/auto_update_data.rb +1 -1
- data/examples/auto_update_links.rb +1 -1
- data/examples/basic_client.rb +1 -1
- data/examples/basic_resource.rb +1 -1
- data/examples/{linked_resource.rb → linked_resources.rb} +6 -11
- data/examples/{multiple_resources.rb → multiple_pov.rb} +2 -1
- data/examples/{json_data_resource.rb → ruby_json_data.rb} +1 -1
- data/lib/riakrest/core/jiak_client.rb +33 -10
- data/lib/riakrest/resource/jiak_resource.rb +8 -4
- data/lib/riakrest.rb +7 -8
- data/spec/resource/jiak_resource_spec.rb +7 -0
- metadata +10 -11
- data/lib/riakrest/version.rb +0 -7
- /data/examples/{links_only.rb → links_only_pov.rb} +0 -0
data/History.txt
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
+
=== 0.0.3 2009-11-03
|
2
|
+
|
3
|
+
* Mods:
|
4
|
+
- Switched to jeweler for managing gem
|
5
|
+
- Allow passing an array for specifying schema fields/masks
|
6
|
+
- Added convenience accessors to rsrc.jiak
|
7
|
+
- Allow setting proxy on core client
|
8
|
+
|
9
|
+
Clean-up:
|
10
|
+
- More examples futzing.
|
11
|
+
|
1
12
|
=== 0.0.2 2009-10-30
|
2
13
|
|
14
|
+
* Mods:
|
15
|
+
- Fixed corner case for auto_post false / auto_update true.
|
16
|
+
- Explicitly reserve jiak field in user data classes.
|
17
|
+
- Changed walk to query. Kept walk as an alias.
|
18
|
+
|
3
19
|
* Clean-up:
|
20
|
+
- DRY'd some code
|
21
|
+
- Examples
|
22
|
+
|
4
23
|
|
5
24
|
=== 0.0.1 2009-10-20
|
6
25
|
|
7
26
|
* Initial release:
|
27
|
+
- To github, anyway. git log shows the prior activity.
|
data/README.rdoc
CHANGED
@@ -53,7 +53,7 @@ sudo gem install riakrest
|
|
53
53
|
end
|
54
54
|
|
55
55
|
remy = Person.new(:name => 'remy',:age => 10) # (auto-post)
|
56
|
-
puts remy.name # => "remy"
|
56
|
+
puts remy.name # => "remy"
|
57
57
|
|
58
58
|
puts Person.get('remy').name # => "remy" (from Jiak server)
|
59
59
|
puts Person.get('remy').age # => 10 (from Jiak server)
|
@@ -62,9 +62,9 @@ sudo gem install riakrest
|
|
62
62
|
puts Person.get('remy').age # => 11 (from Jiak server)
|
63
63
|
|
64
64
|
callie = Person.new(:name => 'Callie', :age => 13)
|
65
|
-
remy.link(callie,'sister')
|
65
|
+
remy.link(callie,'sister') # link from remy to callie
|
66
66
|
|
67
|
-
sisters = remy.query(Person,'sister')
|
67
|
+
sisters = remy.query(Person,'sister') # use link to get 'sister'
|
68
68
|
puts sisters[0].eql?(callie) # => true
|
69
69
|
|
70
70
|
remy.delete
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/examples/basic_client.rb
CHANGED
data/examples/basic_resource.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'riakrest'
|
2
2
|
include RiakRest
|
3
3
|
|
4
4
|
PersonData = JiakDataHash.create(:name)
|
@@ -10,8 +10,6 @@ class Parent
|
|
10
10
|
server 'http://localhost:8002/jiak'
|
11
11
|
group 'parents'
|
12
12
|
data_class PersonData
|
13
|
-
auto_post true
|
14
|
-
auto_update true
|
15
13
|
end
|
16
14
|
Child = Parent.copy(:group => 'children')
|
17
15
|
|
@@ -32,10 +30,6 @@ child_parents = parent_children.inject({}) do |build, (p,cs)|
|
|
32
30
|
end
|
33
31
|
|
34
32
|
# store data and relationships
|
35
|
-
Parent.auto_post false
|
36
|
-
Parent.auto_update false
|
37
|
-
Child.auto_post false
|
38
|
-
Child.auto_update false
|
39
33
|
parent_children.each do |pname,cnames|
|
40
34
|
p = Parent.new(:name => pname).post
|
41
35
|
cnames.each do |cname|
|
@@ -50,10 +44,6 @@ parent_children.each do |pname,cnames|
|
|
50
44
|
end
|
51
45
|
p.update
|
52
46
|
end
|
53
|
-
Parent.auto_post true
|
54
|
-
Parent.auto_update true
|
55
|
-
Child.auto_post true
|
56
|
-
Child.auto_update true
|
57
47
|
|
58
48
|
# retrieve parents
|
59
49
|
parents = parent_children.keys.map {|p| Parent.get(p)}
|
@@ -84,6 +74,10 @@ c3sp = c3.query(Parent,'parent',Child,'child',Parent,'parent')
|
|
84
74
|
c3p.each {|p| c3sp.delete_if{|sp| p.eql?(sp)}}
|
85
75
|
puts c3sp[0].name # => "p1"
|
86
76
|
|
77
|
+
# turn on auto-update at class level
|
78
|
+
Parent.auto_update true
|
79
|
+
Child.auto_update true
|
80
|
+
|
87
81
|
# add sibling links
|
88
82
|
children.each do |c|
|
89
83
|
siblings = c.query(Parent,'parent',Child,'child').delete_if{|s| s.eql?(c)}
|
@@ -114,5 +108,6 @@ op = parents.inject([]) do |build,parent|
|
|
114
108
|
end
|
115
109
|
puts op[0].name # => 'p1'
|
116
110
|
|
111
|
+
# clean-up by deleting everybody
|
117
112
|
parents.each {|p| p.delete}
|
118
113
|
children.each {|c| c.delete}
|
@@ -19,22 +19,50 @@ module RiakRest
|
|
19
19
|
# :startdoc:
|
20
20
|
|
21
21
|
# :call-seq:
|
22
|
-
# JiakClient.new(uri) -> uri
|
22
|
+
# JiakClient.new(uri,opts={}) -> uri
|
23
23
|
#
|
24
24
|
# Create a new client for Riak RESTful (Jiak) interaction with the server at
|
25
|
-
# the specified URI.
|
25
|
+
# the specified URI. Go through a proxy if proxy option specified.
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# Valid options:
|
28
|
+
# <code>:proxy</code> Proxy server URI
|
28
29
|
#
|
29
|
-
|
30
|
+
# Raise JiakClientException if server or proxy (if exists) URI are not strings.
|
31
|
+
#
|
32
|
+
def initialize(uri='http://127.0.0.1:8002/jiak/', opts={})
|
33
|
+
server(uri)
|
34
|
+
proxy(opts[:proxy]) if(opts[:proxy])
|
35
|
+
end
|
36
|
+
|
37
|
+
# :call-seq:
|
38
|
+
# server(uri) -> string
|
39
|
+
#
|
40
|
+
# Set the Jiak server URI for the client.
|
41
|
+
#
|
42
|
+
# Raise JiakClientException if server URI is not string.
|
43
|
+
def server(uri)
|
30
44
|
unless uri.is_a?(String)
|
31
|
-
raise JiakClientException, "Jiak server URI
|
45
|
+
raise JiakClientException, "Jiak server URI should be a string."
|
32
46
|
end
|
33
47
|
@uri = uri
|
34
48
|
@uri += '/' unless @uri.end_with?('/')
|
35
49
|
@uri
|
36
50
|
end
|
37
51
|
|
52
|
+
# :call-seq:
|
53
|
+
# proxy(uri) -> string
|
54
|
+
#
|
55
|
+
# Set Jiak interaction to go through a proxy.
|
56
|
+
#
|
57
|
+
# Raise JiakClientException if proxy URI is not string.
|
58
|
+
def proxy(uri)
|
59
|
+
unless uri.is_a?(String)
|
60
|
+
raise JiakClientException, "Proxy URI should be a string."
|
61
|
+
end
|
62
|
+
@proxy = uri
|
63
|
+
RestClient.proxy = uri
|
64
|
+
end
|
65
|
+
|
38
66
|
# :call-seq:
|
39
67
|
# set_schema(bucket) -> nil
|
40
68
|
#
|
@@ -178,11 +206,6 @@ module RiakRest
|
|
178
206
|
begin
|
179
207
|
uri = jiak_uri(bucket,key,req_params)
|
180
208
|
resp = RestClient.get(uri, :accept => APP_JSON)
|
181
|
-
|
182
|
-
# puts
|
183
|
-
# puts "---CxDEBUG---"
|
184
|
-
# puts " #{resp}"
|
185
|
-
|
186
209
|
JiakObject.from_jiak(JSON.parse(resp),bucket.data_class)
|
187
210
|
rescue RestClient::ResourceNotFound => err
|
188
211
|
raise JiakResourceNotFound, "failed get: #{err.message}"
|
@@ -25,12 +25,16 @@ module RiakRest
|
|
25
25
|
module ClassMethods
|
26
26
|
|
27
27
|
# :call-seq:
|
28
|
-
# JiakServer.server(uri)
|
28
|
+
# JiakServer.server(uri,opts={})
|
29
29
|
#
|
30
|
-
# Set the URI for Jiak server interaction.
|
31
|
-
|
30
|
+
# Set the URI for Jiak server interaction. Go through a proxy if proxy
|
31
|
+
# option specified.
|
32
|
+
#
|
33
|
+
# Valid options:
|
34
|
+
# <code>:proxy</code> Proxy server URI.
|
35
|
+
def server(uri,opts={})
|
32
36
|
jiak.uri = uri
|
33
|
-
jiak.server = JiakClient.new(uri)
|
37
|
+
jiak.server = JiakClient.new(uri,opts)
|
34
38
|
uri
|
35
39
|
end
|
36
40
|
|
data/lib/riakrest.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
# See README.rdoc for the RiakRest license.
|
2
|
-
|
3
2
|
begin
|
4
3
|
require 'json'
|
5
4
|
rescue LoadError
|
6
5
|
raise "RiakRest requires json for REST JSON messaging."
|
7
6
|
end
|
7
|
+
|
8
8
|
begin
|
9
9
|
require 'restclient'
|
10
10
|
rescue LoadError
|
11
11
|
raise <<EOM
|
12
12
|
RiakRest requires the restclient gem for making REST calls.
|
13
13
|
gem install rest-client
|
14
|
-
|
15
14
|
EOM
|
16
15
|
end
|
17
16
|
|
18
17
|
require 'uri'
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
$:.include?(
|
19
|
+
dirname = File.dirname(__FILE__)
|
20
|
+
$:.unshift(dirname) unless
|
21
|
+
$:.include?(dirname) ||
|
22
|
+
$:.include?(File.expand_path(dirname))
|
23
23
|
|
24
24
|
# RiakRest provides structured, RESTful interaction with a Riak document
|
25
25
|
# store. In Riak parlance, this JSON data exchange is called Jiak. RiakRest
|
@@ -134,10 +134,10 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
134
134
|
# </code>
|
135
135
|
# Ah, that feels better. Go forth and Riak!
|
136
136
|
module RiakRest
|
137
|
+
version_file = File.join(File.dirname(__FILE__),"..","VERSION")
|
138
|
+
VERSION = IO.read(version_file).chomp
|
137
139
|
end
|
138
140
|
|
139
|
-
require 'riakrest/version'
|
140
|
-
|
141
141
|
require 'riakrest/core/exceptions'
|
142
142
|
require 'riakrest/core/jiak_bucket'
|
143
143
|
require 'riakrest/core/jiak_client'
|
@@ -148,7 +148,6 @@ require 'riakrest/core/jiak_schema'
|
|
148
148
|
require 'riakrest/core/query_link'
|
149
149
|
|
150
150
|
require 'riakrest/data/jiak_data_hash'
|
151
|
-
|
152
151
|
require 'riakrest/resource/jiak_resource'
|
153
152
|
|
154
153
|
# Extend Array with convenience methods for comparing array contents.
|
@@ -8,6 +8,7 @@ describe "JiakResource default" do
|
|
8
8
|
group 'group'
|
9
9
|
data_class F1F2
|
10
10
|
end
|
11
|
+
Rsrc.pov
|
11
12
|
|
12
13
|
before do
|
13
14
|
@server = 'http://localhost:8002/jiak/'
|
@@ -114,6 +115,7 @@ describe "JiakResource default class-level auto-post/auto-update" do
|
|
114
115
|
group 'people'
|
115
116
|
data_class PersonData
|
116
117
|
end
|
118
|
+
Person.pov
|
117
119
|
|
118
120
|
before do
|
119
121
|
@name = 'p default'
|
@@ -164,6 +166,7 @@ describe "JiakResource class auto-post" do
|
|
164
166
|
group 'people'
|
165
167
|
data_class PersonData
|
166
168
|
end
|
169
|
+
Person.pov
|
167
170
|
|
168
171
|
before do
|
169
172
|
@name = 'p auto-post'
|
@@ -245,6 +248,7 @@ describe "JiakResource class auto-update" do
|
|
245
248
|
auto_post true
|
246
249
|
auto_update true
|
247
250
|
end
|
251
|
+
Dog.pov
|
248
252
|
|
249
253
|
before do
|
250
254
|
@pname = 'p auto-update'
|
@@ -341,6 +345,7 @@ describe "JiakResource simple" do
|
|
341
345
|
auto_post true
|
342
346
|
auto_update true
|
343
347
|
end
|
348
|
+
Dog.pov
|
344
349
|
|
345
350
|
before do
|
346
351
|
@pname = 'p'
|
@@ -403,6 +408,8 @@ describe "JiakResource complex" do
|
|
403
408
|
group 'parents'
|
404
409
|
data_class PersonData
|
405
410
|
end
|
411
|
+
Parent.pov
|
412
|
+
|
406
413
|
Child = Parent.copy(:group => 'children')
|
407
414
|
|
408
415
|
it "should do multi-step relationships" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riakrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Rogers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,10 +62,10 @@ files:
|
|
62
62
|
- examples/auto_update_links.rb
|
63
63
|
- examples/basic_client.rb
|
64
64
|
- examples/basic_resource.rb
|
65
|
-
- examples/
|
66
|
-
- examples/
|
67
|
-
- examples/
|
68
|
-
- examples/
|
65
|
+
- examples/linked_resources.rb
|
66
|
+
- examples/links_only_pov.rb
|
67
|
+
- examples/multiple_pov.rb
|
68
|
+
- examples/ruby_json_data.rb
|
69
69
|
- lib/riakrest.rb
|
70
70
|
- lib/riakrest/core/exceptions.rb
|
71
71
|
- lib/riakrest/core/jiak_bucket.rb
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- lib/riakrest/core/query_link.rb
|
78
78
|
- lib/riakrest/data/jiak_data_hash.rb
|
79
79
|
- lib/riakrest/resource/jiak_resource.rb
|
80
|
-
- lib/riakrest/version.rb
|
81
80
|
- spec/core/exceptions_spec.rb
|
82
81
|
- spec/core/jiak_bucket_spec.rb
|
83
82
|
- spec/core/jiak_client_spec.rb
|
@@ -134,7 +133,7 @@ test_files:
|
|
134
133
|
- examples/auto_update_links.rb
|
135
134
|
- examples/basic_client.rb
|
136
135
|
- examples/basic_resource.rb
|
137
|
-
- examples/
|
138
|
-
- examples/
|
139
|
-
- examples/
|
140
|
-
- examples/
|
136
|
+
- examples/linked_resources.rb
|
137
|
+
- examples/links_only_pov.rb
|
138
|
+
- examples/multiple_pov.rb
|
139
|
+
- examples/ruby_json_data.rb
|
data/lib/riakrest/version.rb
DELETED
File without changes
|