sovaa 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,29 +42,34 @@ module Sovaa
42
42
  def put(uri, doc=nil, headers={})
43
43
  doc = Yajl::Encoder.encode(doc) if doc
44
44
  response = request(:put, uri, doc, headers)
45
- JsonResponse.new(response.body, response.headers['ETag'])
45
+ parsed_response(response)
46
46
  end
47
47
 
48
48
  def get(uri)
49
49
  response = request(:get, uri)
50
- JsonResponse.new(response.body, response.headers['ETag'])
50
+ parsed_response(response)
51
51
  end
52
52
 
53
53
  def post(uri, doc=nil)
54
54
  doc = Yajl::Encoder.encode(doc) if doc
55
55
  response = request(:post, uri, doc)
56
- JsonResponse.new(response.body, response.headers['ETag'])
56
+ parsed_response(response)
57
57
  end
58
58
 
59
59
  def delete(uri)
60
60
  response = request(:delete, uri)
61
- JsonResponse.new(response.body, response.headers['ETag'])
61
+ parsed_response(response)
62
62
  end
63
63
 
64
64
  def copy(uri, destination)
65
65
  headers = {'X-HTTP-Method-Override' => 'COPY', 'Destination' => destination}
66
66
  response = request(:post, uri, nil, headers)
67
- JsonResponse.new(response.body, response.headers['ETag'])
67
+ parsed_response(response)
68
+ end
69
+
70
+ def parsed_response(response)
71
+ parsed = Yajl::Parser.parse(response.body)
72
+ parsed.is_a?(Hash) ? JsonResponse.new(parsed, response.headers['ETag']) ? parsed
68
73
  end
69
74
 
70
75
  private
@@ -3,7 +3,7 @@ module Sovaa
3
3
  attr_reader :etag
4
4
  def initialize(json, etag)
5
5
  super()
6
- self.merge!(Yajl::Parser.parse(json))
6
+ self.merge!(json)
7
7
  @etag = etag
8
8
  end
9
9
  end
@@ -38,11 +38,16 @@ module Sovaa
38
38
  HTTP.post "#{@uri}/_restart"
39
39
  end
40
40
 
41
+ # Fetch a list of uuids
42
+ def uuids(count = @uuid_batch_count)
43
+ HTTP.get("#{@uri}/_uuids?count=#{count}")["uuids"]
44
+ end
45
+
41
46
  # Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs.
42
47
  def next_uuid(count = @uuid_batch_count)
43
48
  @uuids ||= []
44
49
  if @uuids.empty?
45
- @uuids = HTTP.get("#{@uri}/_uuids?count=#{count}")["uuids"]
50
+ @uuids = uuids
46
51
  end
47
52
  @uuids.pop
48
53
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sovaa"
3
- s.version = "0.0.6"
4
- s.date = "2011-03-19"
3
+ s.version = "0.0.7"
4
+ s.date = "2011-04-24"
5
5
  s.summary = "CouchDB library"
6
6
  s.email = "jonathan.stott@gmail.com"
7
7
  s.homepage = "http://github.com/namelessjon/couchrest"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sovaa
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jonathan Stott
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-19 00:00:00 +00:00
13
+ date: 2011-04-24 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency