grendel-ruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Grendel::Link" do
4
+ # before do
5
+ # @client = Grendel::Client.new("http://grendel")
6
+ # @user_id = "alice"
7
+ # @password = "s3kret"
8
+ # @user = Grendel::User.new(@client, :id => @user_id, :password => @password)
9
+ # @document = Grendel::Document.new(@user, :name => "document1.txt")
10
+ # @uri = "#{@user_id}:#{@password}@grendel/users/#{@user_id}/documents/#{@document.name}/links"
11
+ # end
12
+ end
@@ -0,0 +1,91 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ # - get a list of documents a user has linked to them
4
+ # docs = user.linked_documents.list
5
+ # - retrieve a linked document
6
+ # doc = user.linked_documents.find("owner_user_id", "document.txt")
7
+ # - delete a linked document
8
+ # user.linked_documents.delete("owner_user_id", "document.txt")
9
+
10
+ describe "Grendel::LinkedDocumentManager" do
11
+ before do
12
+ @client = Grendel::Client.new("http://grendel")
13
+ @user_id = "alice"
14
+ @password = "s3kret"
15
+ @user = Grendel::User.new(@client, :id => @user_id, :password => @password)
16
+ @document = Grendel::Document.new(@user, :name => "document1.txt")
17
+ @base_uri = "#{@user_id}:#{@password}@grendel/users/#{@user_id}/linked-documents"
18
+ end
19
+
20
+ describe "list" do
21
+ before do
22
+ stub_json_request(:get, @base_uri, %{{
23
+ "linked-documents":[
24
+ {
25
+ "name":"document1.txt",
26
+ "uri":"http://grendel/users/alice/linked-documents/bob/document1.txt",
27
+ "owner":{
28
+ "id": "bob",
29
+ "uri": "http://grendel/users/bob"
30
+ }
31
+ },
32
+ {
33
+ "name":"document2.txt",
34
+ "uri":"http://grendel/users/alice/linked-documents/carol/document2.txt",
35
+ "owner":{
36
+ "id": "carol",
37
+ "uri": "http://grendel/users/carol"
38
+ }
39
+ }
40
+
41
+ ]
42
+ }})
43
+ end
44
+
45
+ it "should return an array of all linked documents" do
46
+ docs = @user.linked_documents.list
47
+ docs.length.should == 2
48
+ docs[0].name.should == "document1.txt"
49
+ docs[0].uri.should == "/users/alice/linked-documents/bob/document1.txt"
50
+ docs[0].owner.id.should == "bob"
51
+ docs[0].owner.uri.should == "/users/bob"
52
+ docs[1].name.should == "document2.txt"
53
+ docs[1].uri.should == "/users/alice/linked-documents/carol/document2.txt"
54
+ docs[1].owner.id.should == "carol"
55
+ docs[1].owner.uri.should == "/users/carol"
56
+ end
57
+ end
58
+
59
+ describe "find" do
60
+ before do
61
+ stub_json_request(:get, @base_uri + "/bob/document1.txt", "yay for me", :content_type => "text/plain")
62
+ stub_json_request(:get, @base_uri + "/carol/notfound.txt", "", :status => "404 Not Found")
63
+ end
64
+
65
+ it "should return the document" do
66
+ doc = @user.linked_documents.find("bob", "document1.txt")
67
+ doc.name.should == "document1.txt"
68
+ doc.content_type.should == "text/plain"
69
+ doc.data.should == "yay for me"
70
+ doc.owner.id.should == "bob"
71
+ end
72
+
73
+ it "should raise an exception if the document is not found" do
74
+ lambda {
75
+ @user.linked_documents.find("carol", "notfound.txt")
76
+ }.should raise_error(Grendel::Client::HTTPException) {|error| error.message.should match("404")} # change to should == "404 Not Found" once WebMock supports status messages
77
+ end
78
+ end
79
+
80
+ describe "delete" do
81
+ before do
82
+ stub_json_request(:delete, @base_uri + "/bob/document.txt", "", :status => "204 No Content")
83
+ @linked_document = Grendel::LinkedDocument.new(@user, :name => "document.txt", :owner => {:id => "bob"})
84
+ end
85
+
86
+ it "should send a properly-formatted request" do
87
+ @user.linked_documents.delete("bob", "document.txt")
88
+ request(:delete, @base_uri + "/bob/document.txt").should have_been_made.once
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Grendel::LinkedDocument" do
4
+ before do
5
+ @client = Grendel::Client.new("http://grendel")
6
+ @user_id = "alice"
7
+ @password = "s3kret"
8
+ @user = Grendel::User.new(@client, :id => @user_id, :password => @password)
9
+ @base_uri = "#{@user_id}:#{@password}@grendel/users/#{@user_id}/linked-documents"
10
+ end
11
+
12
+ describe "delete" do
13
+ before do
14
+ stub_json_request(:delete, @base_uri + "/bob/document.txt", "", :status => "204 No Content")
15
+ @linked_document = Grendel::LinkedDocument.new(@user, :name => "document.txt", :owner => {:id => "bob"})
16
+ end
17
+
18
+ it "should send a properly-formatted request" do
19
+ @linked_document.delete
20
+ request(:delete, @base_uri + "/bob/document.txt").should have_been_made.once
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Grendel::User" do
4
+ before do
5
+ @client = Grendel::Client.new("http://grendel")
6
+ end
7
+
8
+ describe "list" do
9
+ before do
10
+ stub_json_request(:get, "grendel/users", %{{
11
+ "users":[
12
+ {"id":"alice", "uri":"http://grendel/users/alice"},
13
+ {"id":"bob", "uri":"http://grendel/users/bob"}
14
+ ]
15
+ }})
16
+ end
17
+
18
+ it "should return an array of all users" do
19
+ users = @client.users.list
20
+ users.length.should == 2
21
+ users[0].id.should == "alice"
22
+ users[0].uri.should == "/users/alice"
23
+ users[1].id.should == "bob"
24
+ users[1].uri.should == "/users/bob"
25
+ end
26
+ end
27
+
28
+ describe "find" do
29
+ before do
30
+ stub_json_request(:get, "grendel/users/alice", %{{
31
+ "id":"alice",
32
+ "modified-at":"20091227T211121Z",
33
+ "created-at":"20091227T211120Z",
34
+ "keys":['2048-RSA/0A895A19', '2048-RSA/39D1621B']
35
+ }})
36
+ stub_json_request(:get, "grendel/users/nobody", "", :status => "404 Not Found")
37
+ end
38
+
39
+ it "should return the user" do
40
+ user = @client.users.find("alice")
41
+ user.id.should == "alice"
42
+ user.modified_at.should == DateTime.parse("20091227T211121Z")
43
+ user.created_at.should == DateTime.parse("20091227T211120Z")
44
+ user.keys.length.should == 2
45
+ end
46
+
47
+ it "should raise an exception if the user is not found" do
48
+ lambda {
49
+ @client.users.find("nobody")
50
+ }.should raise_error(Grendel::Client::HTTPException) {|error| error.message.should match("404")} # change to should == "404 Not Found" once WebMock supports status messages
51
+ end
52
+ end
53
+
54
+ describe "create" do
55
+ describe "a successful request" do
56
+ before do
57
+ @user_id = "bob"
58
+ @password = "s3kret"
59
+ @uri = "http://grendel/users/#{@user_id}"
60
+ stub_json_request(:post, "grendel/users", "", :status => "201 Created", "Location" => @uri)
61
+ end
62
+
63
+ it "should send a properly-formatted request" do
64
+ @client.users.create(@user_id, @password)
65
+ params = { :id => @user_id, :password => @password }
66
+ request(:post, "grendel/users").with(:body => params.to_json).should have_been_made.once
67
+ end
68
+
69
+ it "should return a user" do
70
+ user = @client.users.create(@user_id, @password)
71
+ user.id.should == @user_id
72
+ user.password.should == @password
73
+ user.uri.should == "/users/bob"
74
+ end
75
+ end
76
+
77
+ describe "an unsuccessful request" do
78
+ before do
79
+ stub_json_request(:post, "grendel/users", "", :status => "422 Unprocessable Entity")
80
+ end
81
+
82
+ it "should raise an exception if the user already exists" do
83
+ lambda {
84
+ @client.users.create("joe","exists")
85
+ }.should raise_error(Grendel::Client::HTTPException) {|error| error.message.should match("422")}
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Grendel::User" do
4
+ before do
5
+ @client = Grendel::Client.new("http://grendel")
6
+ end
7
+
8
+ describe "new" do
9
+ it "should strip the protocol and host from the uri" do
10
+ user = Grendel::User.new(@client, :id => "alice", :uri => "http://grendel/users/alice")
11
+ user.uri.should == "/users/alice"
12
+ end
13
+ end
14
+
15
+ describe "change_password" do
16
+ before do
17
+ @old_password = "s3kret"
18
+ @new_password = "newpass"
19
+ @user = Grendel::User.new(@client, :id => "alice", :password => @old_password)
20
+ @url = "#{@user.id}:#{@user.password}@grendel/users/#{@user.id}"
21
+ stub_json_request(:put, @url, "", :status => "204 No Content")
22
+ end
23
+
24
+ it "should send a properly-formatted request" do
25
+ @user.change_password(@new_password)
26
+ params = { "password" => @new_password }
27
+ request(:put, @url).with(:body => params.to_json).should have_been_made.once
28
+ end
29
+
30
+ it "should return a User with the new password" do
31
+ lambda {
32
+ @user.change_password(@new_password)
33
+ }.should change(@user, :password).from(@old_password).to(@new_password)
34
+ end
35
+ end
36
+
37
+ describe "delete" do
38
+ before do
39
+ @user = Grendel::User.new(@client, :id => "alice", :password => "s3kret")
40
+ @url = "#{@user.id}:#{@user.password}@grendel/users/#{@user.id}"
41
+ stub_json_request(:delete, @url, "", :status => "204 No Content")
42
+ end
43
+
44
+ it "should send a properly-formatted request" do
45
+ @user.delete
46
+ request(:delete, @url).should have_been_made.once
47
+ end
48
+ end
49
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'grendel'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'webmock/rspec'
8
+
9
+ include WebMock
10
+
11
+ Spec::Runner.configure do |config|
12
+ WebMock.disable_net_connect!
13
+
14
+ # helper to add Content-Type: application/json to each request
15
+ def stub_json_request(method, uri, body, headers = {})
16
+ headers = headers.update("Content-Type" => "application/json")
17
+ status = headers.delete(:status) || "200 OK"
18
+ stub_request(method, uri).
19
+ to_return(:body => body, :status => status, :headers => headers)
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grendel-ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Brad Greenlee
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-24 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: httparty
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: rspec
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 1
53
+ - 2
54
+ - 9
55
+ version: 1.2.9
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: |-
59
+ Grendel is a RESTful web service which allows for the secure storage of users'
60
+ documents. Grendel-Ruby provides a Ruby API for Grendel.
61
+ email: brad@wesabe.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - LICENSE.md
68
+ - README.md
69
+ files:
70
+ - .document
71
+ - .gitignore
72
+ - LICENSE.md
73
+ - README.md
74
+ - Rakefile
75
+ - TODO.md
76
+ - VERSION
77
+ - grendel-ruby.gemspec
78
+ - lib/core_ext/hash.rb
79
+ - lib/grendel.rb
80
+ - lib/grendel/client.rb
81
+ - lib/grendel/document.rb
82
+ - lib/grendel/document_manager.rb
83
+ - lib/grendel/link.rb
84
+ - lib/grendel/link_manager.rb
85
+ - lib/grendel/linked_document.rb
86
+ - lib/grendel/linked_document_manager.rb
87
+ - lib/grendel/user.rb
88
+ - lib/grendel/user_manager.rb
89
+ - spec/grendel/client_spec.rb
90
+ - spec/grendel/document_manager_spec.rb
91
+ - spec/grendel/document_spec.rb
92
+ - spec/grendel/link_manager_spec.rb
93
+ - spec/grendel/link_spec.rb
94
+ - spec/grendel/linked_document_manager_spec.rb
95
+ - spec/grendel/linked_document_spec.rb
96
+ - spec/grendel/user_manager_spec.rb
97
+ - spec/grendel/user_spec.rb
98
+ - spec/spec.opts
99
+ - spec/spec_helper.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/wesabe/grendel-ruby
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options:
106
+ - --charset=UTF-8
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.3.6
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Ruby interface to Wesabe's Grendel
130
+ test_files:
131
+ - spec/grendel/client_spec.rb
132
+ - spec/grendel/document_manager_spec.rb
133
+ - spec/grendel/document_spec.rb
134
+ - spec/grendel/link_manager_spec.rb
135
+ - spec/grendel/link_spec.rb
136
+ - spec/grendel/linked_document_manager_spec.rb
137
+ - spec/grendel/linked_document_spec.rb
138
+ - spec/grendel/user_manager_spec.rb
139
+ - spec/grendel/user_spec.rb
140
+ - spec/spec_helper.rb