couch-client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.1.2. Attachment now typecasts fields for stub values.
2
+
1
3
  v0.1.1. Fixing Manifest contents and adding Rails information to README.
2
4
 
3
5
  v0.1.0. Adding rake tasks to sync and manage database functions and design documents. Also added support for list and show functions; as well as fulltext administration.
data/Manifest CHANGED
@@ -4,7 +4,6 @@ Manifest
4
4
  README.markdown
5
5
  Rakefile
6
6
  TODO
7
- couch-client.gemspec
8
7
  lib/couch-client.rb
9
8
  lib/couch-client/attachment.rb
10
9
  lib/couch-client/attachment_list.rb
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{couch-client}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Robert Sosinski"]
9
- s.date = %q{2010-11-11}
9
+ s.date = %q{2010-11-16}
10
10
  s.description = %q{A Ruby interface for CouchDB}
11
11
  s.email = %q{email@robertsosinski.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.markdown", "TODO", "lib/couch-client.rb", "lib/couch-client/attachment.rb", "lib/couch-client/attachment_list.rb", "lib/couch-client/collection.rb", "lib/couch-client/connection.rb", "lib/couch-client/connection_handler.rb", "lib/couch-client/consistent_hash.rb", "lib/couch-client/database.rb", "lib/couch-client/design.rb", "lib/couch-client/document.rb", "lib/couch-client/hookup.rb", "lib/couch-client/rake_task.rb", "lib/couch-client/row.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.markdown", "Rakefile", "TODO", "couch-client.gemspec", "lib/couch-client.rb", "lib/couch-client/attachment.rb", "lib/couch-client/attachment_list.rb", "lib/couch-client/collection.rb", "lib/couch-client/connection.rb", "lib/couch-client/connection_handler.rb", "lib/couch-client/consistent_hash.rb", "lib/couch-client/database.rb", "lib/couch-client/design.rb", "lib/couch-client/document.rb", "lib/couch-client/hookup.rb", "lib/couch-client/rake_task.rb", "lib/couch-client/row.rb", "spec/attachment_list_spec.rb", "spec/attachment_spec.rb", "spec/collection_spec.rb", "spec/conection_handler_spec.rb", "spec/connection_spec.rb", "spec/consistent_hash_spec.rb", "spec/couch-client_spec.rb", "spec/database_spec.rb", "spec/design_spec.rb", "spec/designs/create/people/fulltext/by_name/index.js", "spec/designs/create/people/validate_on_update.js", "spec/designs/create/people/views/all/map.js", "spec/designs/create/people/views/sum/map.js", "spec/designs/create/people/views/sum/reduce.js", "spec/designs/update/people/fulltext/by_name/index.js", "spec/designs/update/people/validate_on_update.js", "spec/designs/update/people/views/sum/map.js", "spec/designs/update/people/views/sum/reduce.js", "spec/document_spec.rb", "spec/files/image.png", "spec/files/plain.txt", "spec/hookup_spec.rb", "spec/rake_task_spec.rb", "spec/row_spec.rb", "spec/spec_helper.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.markdown", "Rakefile", "TODO", "lib/couch-client.rb", "lib/couch-client/attachment.rb", "lib/couch-client/attachment_list.rb", "lib/couch-client/collection.rb", "lib/couch-client/connection.rb", "lib/couch-client/connection_handler.rb", "lib/couch-client/consistent_hash.rb", "lib/couch-client/database.rb", "lib/couch-client/design.rb", "lib/couch-client/document.rb", "lib/couch-client/hookup.rb", "lib/couch-client/rake_task.rb", "lib/couch-client/row.rb", "spec/attachment_list_spec.rb", "spec/attachment_spec.rb", "spec/collection_spec.rb", "spec/conection_handler_spec.rb", "spec/connection_spec.rb", "spec/consistent_hash_spec.rb", "spec/couch-client_spec.rb", "spec/database_spec.rb", "spec/design_spec.rb", "spec/designs/create/people/fulltext/by_name/index.js", "spec/designs/create/people/validate_on_update.js", "spec/designs/create/people/views/all/map.js", "spec/designs/create/people/views/sum/map.js", "spec/designs/create/people/views/sum/reduce.js", "spec/designs/update/people/fulltext/by_name/index.js", "spec/designs/update/people/validate_on_update.js", "spec/designs/update/people/views/sum/map.js", "spec/designs/update/people/views/sum/reduce.js", "spec/document_spec.rb", "spec/files/image.png", "spec/files/plain.txt", "spec/hookup_spec.rb", "spec/rake_task_spec.rb", "spec/row_spec.rb", "spec/spec_helper.rb", "couch-client.gemspec"]
14
14
  s.homepage = %q{http://github.com/robertsosinski/couch-client}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Couch-client", "--main", "README.markdown"]
16
16
  s.require_paths = ["lib"]
@@ -15,7 +15,7 @@ require 'couch-client/rake_task' if defined?(Rake)
15
15
 
16
16
  # The CouchClient module is the overall container of all CouchClient logic.
17
17
  module CouchClient
18
- VERSION = "0.1.0"
18
+ VERSION = "0.1.2"
19
19
 
20
20
  class Error < Exception; end
21
21
 
@@ -9,8 +9,16 @@ module CouchClient
9
9
  # Attachment is constructed with the id of the document it is attached to,
10
10
  # the filename, file stub and connection object.
11
11
  def initialize(id, name, stub, connection)
12
+ # Ensure that `revpos` and `length` fields are numbers, not strings, or couchdb will thow an error.
13
+ ["revpos", "length"].each do |field|
14
+ stub[field] &&= stub[field].to_i
15
+ end
16
+
17
+ # Ensure that `stub` is a boolean, not a string, or couchdb will throw an error
18
+ stub["stub"] &&= true
19
+
12
20
  self.merge!(stub)
13
-
21
+
14
22
  @id = id
15
23
  @name = name
16
24
  @connection = connection
@@ -4,6 +4,7 @@ require 'json'
4
4
  module CouchClient
5
5
  class InvalidHTTPVerb < Exception; end
6
6
  class InvalidJSONData < Exception; end
7
+ class ConnectionFailed < Exception; end
7
8
 
8
9
  # Hookup is the basic HTTP interface that connects CouchClient to CouchDB.
9
10
  # Hookup can use any HTTP library if the conventions listed below are followed.
@@ -70,15 +71,28 @@ module CouchClient
70
71
  easy.userpwd = handler.password
71
72
  end
72
73
 
74
+ # Setup error class with message
75
+ connection_error = lambda do
76
+ raise ConnectionFailed.new("could not connect to the database server at '#{handler.uri}'")
77
+ end
78
+
73
79
  easy = case verb
74
80
  when :head, :get, :delete
75
81
  # head, get and delete http methods only take a uri string and options block
76
- Curl::Easy.send("http_#{verb}", handler.uri(path, query), &options)
82
+ begin
83
+ Curl::Easy.send("http_#{verb}", handler.uri(path, query), &options)
84
+ rescue Curl::Err::ConnectionFailedError
85
+ connection_error.call
86
+ end
77
87
  when :post, :put
78
88
  # post and put http methods take a uri string, data string and options block
79
89
  # also convert the hash into json if the content_type of the request is json
80
90
  data = data.to_json if content_type == "application/json"
81
- Curl::Easy.send("http_#{verb}", handler.uri(path, query), data, &options)
91
+ begin
92
+ Curl::Easy.send("http_#{verb}", handler.uri(path, query), data, &options)
93
+ rescue Curl::Err::ConnectionFailedError
94
+ connection_error.call
95
+ end
82
96
  else
83
97
  raise InvalidHTTPVerb.new("only `head`, `get`, `post`, `put` and `delete` are supported")
84
98
  end
@@ -42,6 +42,16 @@ describe CouchClient::Attachment do
42
42
  @couch.database.delete!
43
43
  end
44
44
 
45
+ describe '#initialize' do
46
+ it 'should typecast fields to the currect type' do
47
+ attachment = CouchClient::Attachment.new("123abc", "text.txt", {"content_type" => "text/plain", "revpos" => "3", "length" => "123", "stub" => "true"}, true)
48
+ attachment["content_type"].should eql("text/plain")
49
+ attachment["revpos"].should eql(3)
50
+ attachment["length"].should eql(123)
51
+ attachment["stub"].should be_true
52
+ end
53
+ end
54
+
45
55
  describe '#uri' do
46
56
  it 'should yield the uri for the attachment' do
47
57
  @attachment_plain.uri.should eql([@couch.hookup.handler.uri, @alice.id, "plain.txt"].join("/"))
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robert Sosinski
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-11 00:00:00 -05:00
17
+ date: 2010-11-16 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -108,7 +108,6 @@ files:
108
108
  - README.markdown
109
109
  - Rakefile
110
110
  - TODO
111
- - couch-client.gemspec
112
111
  - lib/couch-client.rb
113
112
  - lib/couch-client/attachment.rb
114
113
  - lib/couch-client/attachment_list.rb
@@ -147,6 +146,7 @@ files:
147
146
  - spec/rake_task_spec.rb
148
147
  - spec/row_spec.rb
149
148
  - spec/spec_helper.rb
149
+ - couch-client.gemspec
150
150
  has_rdoc: true
151
151
  homepage: http://github.com/robertsosinski/couch-client
152
152
  licenses: []