nsisam 0.4.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,7 @@
1
1
  = nsisam
2
2
 
3
- Just a simple and lightweight package to access a SAM node using Ruby.
3
+ Just a simple and lightweight package to access a SAM node using Ruby. It also includes a simple fake client to
4
+ be used in your application when a real server is not available to receive requests.
4
5
 
5
6
  == Contributing to nsisam
6
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.2
@@ -0,0 +1,39 @@
1
+ module NSISam
2
+ class FakeClient
3
+ def initialize
4
+ @storage = {}
5
+ end
6
+
7
+ def store(data)
8
+ key = Time.now.to_i.to_s
9
+ @storage[key] = data
10
+ {'key' => key, 'checksum' => 0}
11
+ end
12
+
13
+ def get(key, expected_checksum=nil)
14
+ if @storage.has_key?(key)
15
+ {'data' => @storage[key]}
16
+ else
17
+ raise NSISam::Errors::Client::KeyNotFoundError
18
+ end
19
+ end
20
+
21
+ def delete(key)
22
+ if @storage.has_key?(key)
23
+ @storage.delete key
24
+ {'deleted' => true}
25
+ else
26
+ raise NSISam::Errors::Client::KeyNotFoundError
27
+ end
28
+ end
29
+
30
+ def update(key, value)
31
+ if @storage.has_key?(key)
32
+ @storage[key] = value
33
+ {'key' => key, 'checksum' => 0}
34
+ else
35
+ raise NSISam::Errors::Client::KeyNotFoundError
36
+ end
37
+ end
38
+ end
39
+ end
data/lib/nsisam.rb CHANGED
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/nsisam/client'
2
2
  require File.dirname(__FILE__) + '/nsisam/configuration'
3
3
  require File.dirname(__FILE__) + '/nsisam/errors'
4
4
  require File.dirname(__FILE__) + '/nsisam/fake_server'
5
+ require File.dirname(__FILE__) + '/nsisam/fake_client'
5
6
 
6
7
  module NSISam
7
8
  end
data/nsisam.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "nsisam"
8
- s.version = "0.4.0"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Douglas Camata"]
12
- s.date = "2012-05-08"
12
+ s.date = "2012-05-10"
13
13
  s.description = "A simple gem to access a SAM node. For more info about SAM\n visit www.github.com/nsi-iff/sam_buildout."
14
14
  s.email = "d.camata@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -28,9 +28,11 @@ Gem::Specification.new do |s|
28
28
  "lib/nsisam/client.rb",
29
29
  "lib/nsisam/configuration.rb",
30
30
  "lib/nsisam/errors.rb",
31
+ "lib/nsisam/fake_client.rb",
31
32
  "lib/nsisam/fake_server.rb",
32
33
  "nsisam.gemspec",
33
34
  "spec/configuration_spec.rb",
35
+ "spec/fake_client_spec.rb",
34
36
  "spec/nsisam_spec.rb",
35
37
  "spec/spec_helper.rb"
36
38
  ]
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "NSISam::FakeClient" do
4
+ before :all do
5
+ @nsisam = NSISam::FakeClient.new
6
+ end
7
+
8
+ it "can store a value" do
9
+ response = @nsisam.store("something")
10
+ response.should_not be_nil
11
+ response.should have_key("key")
12
+ response.should have_key("checksum")
13
+ end
14
+
15
+ it "can delete a stored value" do
16
+ resp = @nsisam.store("delete this")
17
+ response = @nsisam.delete(resp["key"])
18
+ response["deleted"].should be_true
19
+ end
20
+
21
+ it "raises error when key not found" do
22
+ expect { @nsisam.delete("i dont exist") }.to
23
+ raise_error(NSISam::Errors::Client::KeyNotFoundError)
24
+
25
+ expect { @nsisam.get("i dont exist") }.to
26
+ raise_error(NSISam::Errors::Client::KeyNotFoundError)
27
+
28
+ expect { @nsisam.update("i dont exist", "nothing") }.to
29
+ raise_error(NSISam::Errors::Client::KeyNotFoundError)
30
+ end
31
+
32
+ it "can retrieve a stored value" do
33
+ resp = @nsisam.store("retrieve this")
34
+ response = @nsisam.get(resp['key'])
35
+ response["data"].should == "retrieve this"
36
+ end
37
+
38
+ it "can update values in keys already stored" do
39
+ resp = @nsisam.store("update this")
40
+ response = @nsisam.update(resp['key'], "updated")
41
+ response["key"].should == resp['key']
42
+ @nsisam.get(response['key'])['data'].should == "updated"
43
+ response.should have_key("checksum")
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsisam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -143,9 +143,11 @@ files:
143
143
  - lib/nsisam/client.rb
144
144
  - lib/nsisam/configuration.rb
145
145
  - lib/nsisam/errors.rb
146
+ - lib/nsisam/fake_client.rb
146
147
  - lib/nsisam/fake_server.rb
147
148
  - nsisam.gemspec
148
149
  - spec/configuration_spec.rb
150
+ - spec/fake_client_spec.rb
149
151
  - spec/nsisam_spec.rb
150
152
  - spec/spec_helper.rb
151
153
  homepage: http://github.com/nsi-iff/nsisam-ruby
@@ -163,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
165
  version: '0'
164
166
  segments:
165
167
  - 0
166
- hash: -1798483526539682580
168
+ hash: -1697488961065118787
167
169
  required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  none: false
169
171
  requirements: