easy-exist 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -0
- data/README.md +69 -0
- data/lib/easy-exist/db.rb +44 -15
- data/lib/easy-exist/refinements.rb +3 -0
- data/lib/easy-exist/refinements/refined_false.rb +15 -0
- data/lib/easy-exist/refinements/refined_object.rb +14 -0
- data/lib/easy-exist/refinements/refined_true.rb +15 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d1eb0ca0e2cb7fa7dda0f716bfbf44a2612d8f6
|
4
|
+
data.tar.gz: 5812002fc185fad22ceedc2dddff05199b39ab47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396c06df38683de2d340677a97ddfd69f3e2285cbcd6cae960173a457408bc192ce546d094bd85a0179f45c82486039b970d53a473e3d2646a245a8292e146a7
|
7
|
+
data.tar.gz: b7caea117548987334ce85ce126f614dd8fdfd243c9070e7b8260932429d353a41ab8019de902feb5f7eb408beffb71e9620617bcc43e1dae207840608c4ff2a
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tom Cass
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/easy-exist.svg)](http://badge.fury.io/rb/easy-exist)
|
2
|
+
|
3
|
+
# Easy-Exist
|
4
|
+
|
5
|
+
An easy to use gem to interact with eXist-db via its REST API.
|
6
|
+
|
7
|
+
|
8
|
+
## Code Example
|
9
|
+
|
10
|
+
```
|
11
|
+
require 'easy-exist'
|
12
|
+
|
13
|
+
# connect
|
14
|
+
db = EasyExist::DB.new("http://localhost:8080", {
|
15
|
+
username: "user", password: "easy"
|
16
|
+
})
|
17
|
+
|
18
|
+
# add a document
|
19
|
+
body = "<message><body>Hello World</body></message>"
|
20
|
+
db.put("/my-collection/my-document", body)
|
21
|
+
|
22
|
+
# get document body
|
23
|
+
doc = db.get("/my-collection/my-document")
|
24
|
+
|
25
|
+
# query for all message bodies
|
26
|
+
bodies = db.query("collection('my-collection')/message/body");
|
27
|
+
|
28
|
+
# delete the document
|
29
|
+
db.delete("/my-collection/my-document")
|
30
|
+
```
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Simply add easy-exist to your Gemfile
|
35
|
+
|
36
|
+
```
|
37
|
+
source 'https://rubygems.org'
|
38
|
+
gem 'easy-exist'
|
39
|
+
```
|
40
|
+
|
41
|
+
Then install via bundler
|
42
|
+
|
43
|
+
`bundle install`
|
44
|
+
|
45
|
+
## Running Tests
|
46
|
+
|
47
|
+
RSpec is used for tests.
|
48
|
+
The tests run against a local exist-db instance under a "test-user" account. If you want to run the tests yourself, ensure that this test-user account has been created. You can update the connection properties in `spec/db_spec.rb`
|
49
|
+
|
50
|
+
```
|
51
|
+
let(:db) {
|
52
|
+
EasyExist::DB.new("http://localhost:8088", {
|
53
|
+
username: "test-user",
|
54
|
+
password: "password"
|
55
|
+
})
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
## API Reference
|
60
|
+
|
61
|
+
See the [Docs][easy-exist-docs]
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
1. Fork the project.
|
65
|
+
2. Create your branch
|
66
|
+
3. Commit your changes with tests
|
67
|
+
4. Create a Pull Request
|
68
|
+
|
69
|
+
[easy-exist-docs]: http://casst01.github.io/easy-exist/docs
|
data/lib/easy-exist/db.rb
CHANGED
@@ -19,9 +19,9 @@ module EasyExist
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
# Retrieves the document at the specified
|
22
|
+
# Retrieves the document at the specified URI from the store.
|
23
23
|
#
|
24
|
-
# @param document_uri [String] the
|
24
|
+
# @param document_uri [String] the URI of the document to retrieve.
|
25
25
|
# relative to the collection specified on initialization otherwise '/db'.
|
26
26
|
# @return [String] the contents of the document at 'document_uri'
|
27
27
|
def get(document_uri)
|
@@ -30,23 +30,20 @@ module EasyExist
|
|
30
30
|
res.success? ? res.body : handle_error(res)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Puts the given document content at the specified
|
33
|
+
# Puts the given document content at the specified URI
|
34
34
|
#
|
35
|
-
# @param document_uri [String] the
|
35
|
+
# @param document_uri [String] the URI at wich to store the document.
|
36
36
|
# relative to the collection specified on initialization otherwise '/db'.
|
37
37
|
# @return [HTTParty::Response] the response object
|
38
38
|
def put(document_uri, document)
|
39
39
|
validate_uri(document_uri)
|
40
|
-
res =
|
41
|
-
body: document,
|
42
|
-
headers: { "Content-Type" => "application/xml"},
|
43
|
-
}))
|
40
|
+
res = put_document(document_uri, document, "application/xml")
|
44
41
|
res.success? ? res : handle_error(res)
|
45
42
|
end
|
46
43
|
|
47
|
-
# Deletes the document at the specified
|
44
|
+
# Deletes the document at the specified URI from the store
|
48
45
|
#
|
49
|
-
# @param document_uri [String] the
|
46
|
+
# @param document_uri [String] the URI of the document to delete.
|
50
47
|
# relative to the collection specified on initialization otherwise '/db'.
|
51
48
|
# @return [HTTParty::Response] the response object
|
52
49
|
def delete(document_uri)
|
@@ -55,11 +52,11 @@ module EasyExist
|
|
55
52
|
res.success? ? res : handle_error(res)
|
56
53
|
end
|
57
54
|
|
58
|
-
# Determines if the document at the specified
|
55
|
+
# Determines if the document at the specified URI exists in the store
|
59
56
|
#
|
60
57
|
# @param document_uri [String] the uri of the document to check.
|
61
58
|
# relative to the collection specified on initialization otherwise '/db'.
|
62
|
-
# @return [TrueClass | FalseClass]
|
59
|
+
# @return [TrueClass | FalseClass]
|
63
60
|
def exists?(document_uri)
|
64
61
|
validate_uri(document_uri)
|
65
62
|
HTTParty.get(document_uri, @default_opts).success?
|
@@ -81,6 +78,25 @@ module EasyExist
|
|
81
78
|
res.success? ? res.body : handle_error(res)
|
82
79
|
end
|
83
80
|
|
81
|
+
# Stores the given query at the specified URI
|
82
|
+
#
|
83
|
+
# @param query_uri [String] the URI of the query to run
|
84
|
+
# @param query [String] the query body
|
85
|
+
# @return [HTTParty::Response] the response object
|
86
|
+
def store_query(query_uri, query)
|
87
|
+
validate_uri(query_uri)
|
88
|
+
res = put_document(query_uri, query, "application/xquery")
|
89
|
+
res.success? ? res : handle_error(res)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the results of running the query stored at the specified URI
|
93
|
+
#
|
94
|
+
# @param query_uri [String] the URI of the query to run
|
95
|
+
# @return [String] the query results
|
96
|
+
def execute_stored_query(query_uri)
|
97
|
+
self.get(query_uri)
|
98
|
+
end
|
99
|
+
|
84
100
|
private
|
85
101
|
# Raises an error based on a HTTParty::Response.
|
86
102
|
# HTTParty:Response objects contain a reference to the Net::HTTResponse object.
|
@@ -92,9 +108,9 @@ module EasyExist
|
|
92
108
|
res.response.value
|
93
109
|
end
|
94
110
|
|
95
|
-
# Raises an error if the
|
111
|
+
# Raises an error if the specified URI does not start with a '/'
|
96
112
|
#
|
97
|
-
# @param uri [String] the
|
113
|
+
# @param uri [String] the URI to validate
|
98
114
|
def validate_uri(uri)
|
99
115
|
raise ArgumentError, 'URI must contain preceding "/"' if uri[0] != '/';
|
100
116
|
end
|
@@ -105,5 +121,18 @@ module EasyExist
|
|
105
121
|
def validate_opts(opts)
|
106
122
|
validate_uri(opts[:collection]) unless opts[:collection].nil? || opts[:collection].empty?
|
107
123
|
end
|
124
|
+
|
125
|
+
# Stores a document at the specified URI and with the specified content type
|
126
|
+
#
|
127
|
+
# @param uri [String] the URI under which to store the document
|
128
|
+
# @param document [String] the document body
|
129
|
+
# @param content_type [String] the MIME Type of the document
|
130
|
+
# @return [HTTParty::Response] the response object
|
131
|
+
def put_document(uri, document, content_type)
|
132
|
+
HTTParty.put(uri, @default_opts.merge({
|
133
|
+
body: document,
|
134
|
+
headers: { "Content-Type" => content_type},
|
135
|
+
}))
|
136
|
+
end
|
108
137
|
end
|
109
|
-
end
|
138
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module EasyExist
|
2
|
+
|
3
|
+
# Module for refining Object
|
4
|
+
module RefinedObject
|
5
|
+
refine Object do
|
6
|
+
|
7
|
+
# Determine if this object is a boolean. (A TrueClass or a FalseClass)
|
8
|
+
# @return [Boolean]
|
9
|
+
def is_a_boolean?
|
10
|
+
self.is_a?(TrueClass) || self.is_a?(FalseClass)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-exist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Cass
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -136,10 +136,16 @@ executables: []
|
|
136
136
|
extensions: []
|
137
137
|
extra_rdoc_files: []
|
138
138
|
files:
|
139
|
+
- LICENSE.md
|
140
|
+
- README.md
|
139
141
|
- lib/easy-exist.rb
|
140
142
|
- lib/easy-exist/db.rb
|
141
143
|
- lib/easy-exist/query_request.rb
|
142
|
-
|
144
|
+
- lib/easy-exist/refinements.rb
|
145
|
+
- lib/easy-exist/refinements/refined_false.rb
|
146
|
+
- lib/easy-exist/refinements/refined_object.rb
|
147
|
+
- lib/easy-exist/refinements/refined_true.rb
|
148
|
+
homepage: http://casst01.github.io/easy-exist
|
143
149
|
licenses:
|
144
150
|
- MIT
|
145
151
|
metadata: {}
|