nsisam 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/VERSION +1 -1
- data/lib/nsisam/fake_client.rb +26 -6
- data/nsisam.gemspec +8 -5
- data/spec/fake_client_spec.rb +42 -2
- metadata +21 -5
data/Gemfile
CHANGED
@@ -4,6 +4,7 @@ source "http://rubygems.org"
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
gem "json"
|
6
6
|
gem "sinatra"
|
7
|
+
gem "webmock", github: "douglascamata/webmock"
|
7
8
|
|
8
9
|
# Add dependencies to develop your gem here.
|
9
10
|
# Include everything needed to run rake, tests, features, etc.
|
@@ -11,6 +12,6 @@ group :development do
|
|
11
12
|
gem "rake"
|
12
13
|
gem "yard"
|
13
14
|
gem "rspec", "~> 2.8.0"
|
14
|
-
gem "bundler", "~> 1.
|
15
|
+
gem "bundler", "~> 1.2.0"
|
15
16
|
gem "jeweler", "~> 1.8.3"
|
16
17
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/nsisam/fake_client.rb
CHANGED
@@ -1,25 +1,36 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'base64'
|
3
3
|
require File.dirname(__FILE__) + '/response'
|
4
|
+
require 'webmock'
|
5
|
+
include WebMock::API
|
6
|
+
WebMock.allow_net_connect!
|
7
|
+
|
4
8
|
|
5
9
|
module NSISam
|
6
10
|
class FakeClient
|
7
11
|
|
8
12
|
attr_accessor :expire
|
13
|
+
attr_reader :host, :port
|
9
14
|
|
10
|
-
def initialize
|
15
|
+
def initialize(host="localhost", port="8888")
|
11
16
|
@storage = {}
|
17
|
+
@host = host
|
18
|
+
@port = port
|
12
19
|
end
|
13
20
|
|
14
21
|
def store(data)
|
15
|
-
key = Time.now.
|
22
|
+
key = Time.now.nsec.to_s
|
16
23
|
@storage[key] = JSON.load(data.to_json) unless @expire
|
24
|
+
if data.kind_of?(Hash) and data.has_key?(:file) and data.has_key?(:filename)
|
25
|
+
stub_request(:get, "http://#{@host}:#{@port}/file/#{key}").to_return(body: Base64.decode64(data[:file]))
|
26
|
+
end
|
17
27
|
Response.new 'key' => key, 'checksum' => 0
|
18
28
|
end
|
19
29
|
|
20
|
-
def store_file(file, type=:file)
|
30
|
+
def store_file(file, filename, type=:file)
|
21
31
|
key = Time.now.to_i.to_s
|
22
|
-
@storage[key] = {type.to_s => Base64.encode64(file)}.to_json unless @expire
|
32
|
+
@storage[key] = {type.to_s => Base64.encode64(file), filename: filename}.to_json unless @expire
|
33
|
+
stub_request(:get, "http://#{@host}:#{@port}/file/#{key}").to_return(body: file)
|
23
34
|
Response.new "key" => key, "checksum" => 0
|
24
35
|
end
|
25
36
|
|
@@ -54,12 +65,21 @@ module NSISam
|
|
54
65
|
if @expire
|
55
66
|
@storage.delete(key)
|
56
67
|
else
|
57
|
-
@storage[key] = value
|
68
|
+
@storage[key] = value
|
58
69
|
end
|
59
|
-
Response.new 'key' => key, 'checksum' => 0
|
70
|
+
Response.new 'key' => key, 'checksum' => 0
|
60
71
|
else
|
61
72
|
raise NSISam::Errors::Client::KeyNotFoundError
|
62
73
|
end
|
63
74
|
end
|
75
|
+
|
76
|
+
def update_file(key, file, filename)
|
77
|
+
hash = {file: file, filename: filename}
|
78
|
+
@storage[key] = hash
|
79
|
+
remove_request_stub(:get, "http://#{@host}:#{@port}/file/#{key}")
|
80
|
+
stub_request(:get, "http://#{@host}:#{@port}/file/#{key}").to_return(body: file)
|
81
|
+
Response.new "key" => key, "checksum" => 0
|
82
|
+
end
|
83
|
+
|
64
84
|
end
|
65
85
|
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.
|
8
|
+
s.version = "0.7.0"
|
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-09-
|
12
|
+
s.date = "2012-09-26"
|
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 = [
|
@@ -55,27 +55,30 @@ Gem::Specification.new do |s|
|
|
55
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
56
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
57
57
|
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
|
58
|
+
s.add_runtime_dependency(%q<webmock>, [">= 0"])
|
58
59
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
59
60
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
60
61
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
|
62
63
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
63
64
|
else
|
64
65
|
s.add_dependency(%q<json>, [">= 0"])
|
65
66
|
s.add_dependency(%q<sinatra>, [">= 0"])
|
67
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
66
68
|
s.add_dependency(%q<rake>, [">= 0"])
|
67
69
|
s.add_dependency(%q<yard>, [">= 0"])
|
68
70
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
69
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
71
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.0"])
|
70
72
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
71
73
|
end
|
72
74
|
else
|
73
75
|
s.add_dependency(%q<json>, [">= 0"])
|
74
76
|
s.add_dependency(%q<sinatra>, [">= 0"])
|
77
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
75
78
|
s.add_dependency(%q<rake>, [">= 0"])
|
76
79
|
s.add_dependency(%q<yard>, [">= 0"])
|
77
80
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
78
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
81
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.0"])
|
79
82
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
80
83
|
end
|
81
84
|
end
|
data/spec/fake_client_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'net/http'
|
2
3
|
|
3
4
|
describe "NSISam::FakeClient" do
|
4
5
|
before :all do
|
@@ -13,7 +14,7 @@ describe "NSISam::FakeClient" do
|
|
13
14
|
end
|
14
15
|
|
15
16
|
it "can store a file" do
|
16
|
-
response = @nsisam.store_file("some file not in base64")
|
17
|
+
response = @nsisam.store_file("some file not in base64", 'dumb.txt')
|
17
18
|
response.should_not be_nil
|
18
19
|
response.key.should_not be_nil
|
19
20
|
response.checksum.should_not be_nil
|
@@ -43,7 +44,7 @@ describe "NSISam::FakeClient" do
|
|
43
44
|
end
|
44
45
|
|
45
46
|
it "can retrieve a stored file" do
|
46
|
-
resp = @nsisam.store_file("file not in base64")
|
47
|
+
resp = @nsisam.store_file("file not in base64", 'dumb.txt')
|
47
48
|
response = @nsisam.get_file(resp.key)
|
48
49
|
response.data.should_not be_nil
|
49
50
|
end
|
@@ -55,4 +56,43 @@ describe "NSISam::FakeClient" do
|
|
55
56
|
@nsisam.get(response.key).data.should == "updated"
|
56
57
|
response.checksum.should_not be_nil
|
57
58
|
end
|
59
|
+
|
60
|
+
context "can host files" do
|
61
|
+
it "stored by #store_file" do
|
62
|
+
response = @nsisam.store_file("file not in base64", 'dumb.txt')
|
63
|
+
response.key.should_not be_nil
|
64
|
+
request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
|
65
|
+
request.body.should == "file not in base64"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "stored by #store in a dict with file and filename" do
|
69
|
+
data = {file: Base64.encode64('a file'), filename: 'dumb.txt'}
|
70
|
+
response = @nsisam.store(data)
|
71
|
+
request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
|
72
|
+
request.body.should == "a file"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should update the hosted file when the file is updated through #store" do
|
76
|
+
data = {file: Base64.encode64('a file'), filename: 'dumb.txt'}
|
77
|
+
response = @nsisam.store(data)
|
78
|
+
request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
|
79
|
+
request.body.should == "a file"
|
80
|
+
|
81
|
+
data = {file: Base64.encode64('another file'), filename: 'dumb.txt'}
|
82
|
+
response = @nsisam.store(data)
|
83
|
+
request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
|
84
|
+
request.body.should == "another file"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should update the hosted file when the file is updated through #store_file" do
|
88
|
+
response = @nsisam.store_file('a file', 'dumb.txt')
|
89
|
+
request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
|
90
|
+
request.body.should == "a file"
|
91
|
+
|
92
|
+
response = @nsisam.update_file(response.key, 'another file', 'dumb.txt')
|
93
|
+
request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
|
94
|
+
request.body.should == "another file"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
58
98
|
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
|
+
version: 0.7.0
|
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-09-
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rake
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +114,7 @@ dependencies:
|
|
98
114
|
requirements:
|
99
115
|
- - ~>
|
100
116
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.
|
117
|
+
version: 1.2.0
|
102
118
|
type: :development
|
103
119
|
prerelease: false
|
104
120
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +122,7 @@ dependencies:
|
|
106
122
|
requirements:
|
107
123
|
- - ~>
|
108
124
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.
|
125
|
+
version: 1.2.0
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
127
|
name: jeweler
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
188
|
version: '0'
|
173
189
|
segments:
|
174
190
|
- 0
|
175
|
-
hash:
|
191
|
+
hash: 2819258548481392356
|
176
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
193
|
none: false
|
178
194
|
requirements:
|