yogo-persevere 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.txt +90 -0
- data/Rakefile +12 -0
- data/lib/persevere.rb +71 -0
- data/test/test_persevere.rb +52 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
= ruby persevere client
|
2
|
+
|
3
|
+
* http://github.com/irjudson/persevere
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
Currently this provides a very simple RESTful interface to persevere. Data to be stored in persevere should be sent as hashes. To make this more robust it should provide some schema/table support, plus validate data against the schema/table. This exists in persevere, but is not exposed by this wrapper.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
#!/usr/bin/env ruby
|
16
|
+
#
|
17
|
+
require 'persevere'
|
18
|
+
|
19
|
+
#
|
20
|
+
# Create an object to interact with Persevere
|
21
|
+
#
|
22
|
+
p = Persevere.new('http://localhost:8080')
|
23
|
+
|
24
|
+
#
|
25
|
+
# Test POST to create a new class
|
26
|
+
#
|
27
|
+
print "\nTesting POST..."
|
28
|
+
tstObj = { 'id' => 'tstObj', 'extends' => { '$ref' => 'Object' } }
|
29
|
+
result = p.create('/Class/', tstObj)
|
30
|
+
print "Response:\n"
|
31
|
+
puts result
|
32
|
+
|
33
|
+
#
|
34
|
+
# Test GET to retrieve the list of classes from Persvr
|
35
|
+
#
|
36
|
+
print "\nTesting GET..."
|
37
|
+
result = p.retrieve('/Class')
|
38
|
+
print "Response:\n"
|
39
|
+
puts result
|
40
|
+
|
41
|
+
#
|
42
|
+
# Test PUT to modify an existing class
|
43
|
+
#
|
44
|
+
print "\nTesting PUT..."
|
45
|
+
tstObj['tstAttribute'] = 42
|
46
|
+
result = p.update('/Class/tstObj', tstObj)
|
47
|
+
print "Response:\n"
|
48
|
+
puts result
|
49
|
+
|
50
|
+
#
|
51
|
+
# Test DELETE to remove the previously created and modified class
|
52
|
+
#
|
53
|
+
print "\nTesting DELETE..."
|
54
|
+
result = p.delete('/Class/tstObj')
|
55
|
+
print "Response:\n"
|
56
|
+
puts result
|
57
|
+
|
58
|
+
== REQUIREMENTS:
|
59
|
+
|
60
|
+
* Persevere installed somewhere
|
61
|
+
* JSON gem
|
62
|
+
|
63
|
+
== INSTALL:
|
64
|
+
|
65
|
+
sudo gem install persevere
|
66
|
+
|
67
|
+
== LICENSE:
|
68
|
+
|
69
|
+
(The MIT License)
|
70
|
+
|
71
|
+
Copyright (c) 2009 Montana State University
|
72
|
+
|
73
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
74
|
+
a copy of this software and associated documentation files (the
|
75
|
+
'Software'), to deal in the Software without restriction, including
|
76
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
77
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
78
|
+
permit persons to whom the Software is furnished to do so, subject to
|
79
|
+
the following conditions:
|
80
|
+
|
81
|
+
The above copyright notice and this permission notice shall be
|
82
|
+
included in all copies or substantial portions of the Software.
|
83
|
+
|
84
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
87
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
88
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
89
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
90
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/persevere.rb'
|
6
|
+
|
7
|
+
Hoe.spec('persevere') do |p|
|
8
|
+
# p.rubyforge_name = 'perseverex' # if different than lowercase project name
|
9
|
+
p.developer('Ivan R. Judson', 'irjudson@gmail.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
# vim: syntax=Ruby
|
data/lib/persevere.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Yogo Data Management Toolkit : Persevere Wrapper
|
3
|
+
# (c) 2008-2009 Montana State University
|
4
|
+
# Ivan R. Judson
|
5
|
+
#
|
6
|
+
# This provides a relatively simple interface to access the Persevere
|
7
|
+
# JSON data store. More information about Persevere can be found here:
|
8
|
+
# http://www.persvr.org/
|
9
|
+
#
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
class PersevereResult
|
17
|
+
attr_reader :location, :code, :message, :body
|
18
|
+
|
19
|
+
def PersevereResult.make(response)
|
20
|
+
return PersevereResult.new(response["Location"], response.code,
|
21
|
+
response.msg, response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(location, code, message, body)
|
25
|
+
@location = location
|
26
|
+
@code = code
|
27
|
+
@message = message
|
28
|
+
@body = body
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
super + " < Location: #{ @location } Code: #{ @code } Message: #{ @message } >"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Persevere
|
37
|
+
VERSION = '1.1'
|
38
|
+
ACCEPT = { 'Accept' => 'application/json' }
|
39
|
+
|
40
|
+
attr_accessor :server_url, :pservr
|
41
|
+
|
42
|
+
|
43
|
+
def initialize(url)
|
44
|
+
@server_url = url
|
45
|
+
server = URI.parse(@server_url)
|
46
|
+
@persevere = Net::HTTP.new(server.host, server.port)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Pass in a resource hash
|
50
|
+
def create(path, resource)
|
51
|
+
json_blob = resource.to_json
|
52
|
+
response = @persevere.send_request('POST', path, json_blob, ACCEPT)
|
53
|
+
return PersevereResult.make(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
def retrieve(path)
|
57
|
+
response = @persevere.send_request('GET', path, nil, ACCEPT)
|
58
|
+
return PersevereResult.make(response)
|
59
|
+
end
|
60
|
+
|
61
|
+
def update(path, resource)
|
62
|
+
json_blob = resource.to_json
|
63
|
+
response = @persevere.send_request('PUT', path, json_blob, ACCEPT)
|
64
|
+
return PersevereResult.make(response)
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete(path)
|
68
|
+
response = @persevere.send_request('DELETE', path, nil, ACCEPT)
|
69
|
+
return PersevereResult.make(response)
|
70
|
+
end
|
71
|
+
end # class Persevere
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
require 'rubygems'
|
4
|
+
require 'persevere'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Create an object to interact with Persevere
|
8
|
+
#
|
9
|
+
p = Persevere.new('http://localhost:8080')
|
10
|
+
|
11
|
+
#
|
12
|
+
# Test POST to create a new class
|
13
|
+
#
|
14
|
+
print "\nTesting POST..."
|
15
|
+
blobObj = {
|
16
|
+
'id' => 'Blob',
|
17
|
+
'extends' => { '$ref' => 'Object' },
|
18
|
+
'properties' => {
|
19
|
+
'id' => { },
|
20
|
+
'cid' => { },
|
21
|
+
'parent' => { },
|
22
|
+
'data' => { }
|
23
|
+
}
|
24
|
+
}
|
25
|
+
result = p.create('/Class/', blobObj)
|
26
|
+
print "Response:\n"
|
27
|
+
puts result.inspect
|
28
|
+
|
29
|
+
#
|
30
|
+
# Test GET to retrieve the list of classes from Persvr
|
31
|
+
#
|
32
|
+
print "\nTesting GET..."
|
33
|
+
result = p.retrieve('/Class')
|
34
|
+
print "Response:\n"
|
35
|
+
puts result.inspect
|
36
|
+
|
37
|
+
#
|
38
|
+
# Test PUT to modify an existing class
|
39
|
+
#
|
40
|
+
print "\nTesting PUT..."
|
41
|
+
blobObj['tstAttribute'] = 42
|
42
|
+
result = p.update('/Class/Blob', blobObj)
|
43
|
+
print "Response:\n"
|
44
|
+
puts result.inspect
|
45
|
+
|
46
|
+
#
|
47
|
+
# Test DELETE to remove the previously created and modified class
|
48
|
+
#
|
49
|
+
#print "\nTesting DELETE..."
|
50
|
+
#result = p.delete('/Class/Blob')
|
51
|
+
#print "Response:\n"
|
52
|
+
#puts result
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yogo-persevere
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan R. Judson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.0
|
24
|
+
version:
|
25
|
+
description: This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
|
26
|
+
email:
|
27
|
+
- irjudson [a] gmail [d] com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- lib/persevere.rb
|
42
|
+
- test/test_persevere.rb
|
43
|
+
has_rdoc: false
|
44
|
+
homepage: http://github.com/irjudson/persevere
|
45
|
+
licenses:
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.txt
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: persevere
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
|
71
|
+
test_files:
|
72
|
+
- test/test_persevere.rb
|