bolster 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/bolster.rb +15 -9
- data/lib/bolster/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dc598e35aac4a69466775b6bdfbea7a74b6594f
|
4
|
+
data.tar.gz: 31575d6f5fb0e0e4272fc6db25f1d5e6c2554775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 129c938ed56ef0df819f60e0fda04f03b791f1f2520986632ddbffb4d0dd5977cad61d27285908ac58acd99d50bb88c9008c5f4d295f10bd8f137067b6377eeb
|
7
|
+
data.tar.gz: f68dd83e6cfa25aeaf88137acf48881ef3c2a6e1977236455ec40a6fefa5c86dc696785b84b9f0e115a57c2f874d2aba552604a376e1151918f3217066139ab9
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Bolster
|
2
2
|
|
3
|
-
|
3
|
+
Basic RESTful (insert buzzwords here) CouchDB wrapper.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,14 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
require 'bolster'
|
23
|
+
|
24
|
+
couch = Bolster::Server.new('localhost', '5984')
|
25
|
+
puts couch.get('/')
|
26
|
+
|
27
|
+
#=> {"couchdb":"Welcome","uuid":"...","version":"1.5.0","vendor":{"version":"1.5.0","name":"The Apache Software Foundation"}}
|
28
|
+
```
|
22
29
|
|
23
30
|
## Contributing
|
24
31
|
|
data/lib/bolster.rb
CHANGED
@@ -1,44 +1,50 @@
|
|
1
1
|
require 'bolster/version'
|
2
2
|
require 'net/http'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
module Bolster
|
5
6
|
class Server
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
-
@port = port
|
7
|
+
def initialize(uri, options = {})
|
8
|
+
@uri = URI(uri)
|
9
9
|
@options = options
|
10
10
|
end
|
11
11
|
|
12
12
|
def delete(uri)
|
13
|
-
res = request(Net::HTTP::Delete.new(uri))
|
13
|
+
res = request(Net::HTTP::Delete.new(@uri.request_uri + uri))
|
14
14
|
res.body
|
15
15
|
end
|
16
16
|
|
17
17
|
def get(uri)
|
18
|
-
res = request(Net::HTTP::Get.new(uri))
|
18
|
+
res = request(Net::HTTP::Get.new(@uri.request_uri + uri))
|
19
19
|
res.body
|
20
20
|
end
|
21
21
|
|
22
22
|
def put(uri, json)
|
23
|
-
req = Net::HTTP::Put.new(uri)
|
23
|
+
req = Net::HTTP::Put.new(@uri.request_uri + uri)
|
24
24
|
req['content-type'] = 'application/json'
|
25
25
|
req.body = json
|
26
26
|
request(req)
|
27
27
|
end
|
28
28
|
|
29
29
|
def post(uri, json)
|
30
|
-
req = Net::HTTP::Post.new(uri)
|
30
|
+
req = Net::HTTP::Post.new(@uri.request_uri + uri)
|
31
31
|
req['content-type'] = 'application/json'
|
32
32
|
req.body = json
|
33
33
|
request(req)
|
34
34
|
end
|
35
35
|
|
36
36
|
def request(req)
|
37
|
+
http = Net::HTTP.new(@uri.hostname, @uri.port)
|
38
|
+
if @uri.class == URI::HTTPS
|
39
|
+
require 'net/https'
|
40
|
+
http.use_ssl = true
|
41
|
+
end
|
42
|
+
|
37
43
|
if @options.has_key?(:user) && @options.has_key?(:password)
|
38
44
|
req.basic_auth(@options[:user], @options[:password])
|
39
45
|
end
|
40
46
|
|
41
|
-
res =
|
47
|
+
res = http.start { |h| h.request(req) }
|
42
48
|
unless res.kind_of?(Net::HTTPSuccess)
|
43
49
|
handle_error(req, res)
|
44
50
|
end
|
@@ -53,4 +59,4 @@ module Bolster
|
|
53
59
|
raise e
|
54
60
|
end
|
55
61
|
end
|
56
|
-
end
|
62
|
+
end
|
data/lib/bolster/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Bolster
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
2
|
+
VERSION = '0.0.6'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bolster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Rische
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|