nsisam 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/lib/nsisam/client.rb +27 -8
- data/lib/nsisam/configuration.rb +31 -0
- data/lib/nsisam.rb +2 -0
- data/nsisam.gemspec +7 -5
- data/spec/configuration_spec.rb +36 -0
- data/spec/nsisam_spec.rb +30 -2
- metadata +7 -5
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/nsisam/client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "json"
|
2
2
|
require "net/http"
|
3
3
|
require "digest"
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + '/configuration'
|
4
6
|
require File.dirname(__FILE__) + '/errors'
|
5
7
|
|
6
8
|
module NSISam
|
@@ -8,15 +10,17 @@ module NSISam
|
|
8
10
|
|
9
11
|
# Initialize a client to a SAM node hosted at a specific url
|
10
12
|
#
|
11
|
-
# @param [
|
13
|
+
# @param [Hash] optional hash with user, password, host and port of the SAM node
|
12
14
|
# @return [Client] the object itself
|
13
15
|
# @example
|
14
|
-
# nsisam = NSISam::Client.new
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@
|
16
|
+
# nsisam = NSISam::Client.new user: 'username' password: 'pass',
|
17
|
+
# host: 'localhost', port: '8888'
|
18
|
+
def initialize(params = {})
|
19
|
+
params = Configuration.settings.merge(params)
|
20
|
+
@user = params[:user]
|
21
|
+
@password = params[:password]
|
22
|
+
@host = params[:host]
|
23
|
+
@port = params[:port]
|
20
24
|
end
|
21
25
|
|
22
26
|
# Store a given data in SAM
|
@@ -93,6 +97,21 @@ module NSISam
|
|
93
97
|
execute_request(request)
|
94
98
|
end
|
95
99
|
|
100
|
+
# Configure the default values for NSISam::Client objects
|
101
|
+
#
|
102
|
+
# @param [Block]
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# NSISam::Client.configure do
|
106
|
+
# user "why"
|
107
|
+
# password "chunky"
|
108
|
+
# host "localhost"
|
109
|
+
# port "8888"
|
110
|
+
# end
|
111
|
+
def self.configure(&block)
|
112
|
+
Configuration.instance_eval(&block)
|
113
|
+
end
|
114
|
+
|
96
115
|
private
|
97
116
|
|
98
117
|
def prepare_request(verb, body)
|
@@ -105,7 +124,7 @@ module NSISam
|
|
105
124
|
|
106
125
|
def execute_request(request)
|
107
126
|
begin
|
108
|
-
response = Net::HTTP.start @
|
127
|
+
response = Net::HTTP.start @host, @port do |http|
|
109
128
|
http.request(request)
|
110
129
|
end
|
111
130
|
rescue Errno::ECONNREFUSED => e
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module NSISam
|
2
|
+
class Client
|
3
|
+
class Configuration
|
4
|
+
class << self
|
5
|
+
def user(user = nil)
|
6
|
+
@user = user unless user.nil?
|
7
|
+
@user
|
8
|
+
end
|
9
|
+
|
10
|
+
def password(password = nil)
|
11
|
+
@password = password unless password.nil?
|
12
|
+
@password
|
13
|
+
end
|
14
|
+
|
15
|
+
def host(host = nil)
|
16
|
+
@host = host unless host.nil?
|
17
|
+
@host
|
18
|
+
end
|
19
|
+
|
20
|
+
def port(port = nil)
|
21
|
+
@port = port unless port.nil?
|
22
|
+
@port
|
23
|
+
end
|
24
|
+
|
25
|
+
def settings
|
26
|
+
{user: @user, password: @password, host: @host, port: @port}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/nsisam.rb
CHANGED
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.4.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-
|
12
|
+
s.date = "2012-05-08"
|
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 = [
|
@@ -26,9 +26,11 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"lib/nsisam.rb",
|
28
28
|
"lib/nsisam/client.rb",
|
29
|
+
"lib/nsisam/configuration.rb",
|
29
30
|
"lib/nsisam/errors.rb",
|
30
31
|
"lib/nsisam/fake_server.rb",
|
31
32
|
"nsisam.gemspec",
|
33
|
+
"spec/configuration_spec.rb",
|
32
34
|
"spec/nsisam_spec.rb",
|
33
35
|
"spec/spec_helper.rb"
|
34
36
|
]
|
@@ -47,7 +49,7 @@ Gem::Specification.new do |s|
|
|
47
49
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
48
50
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
49
51
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
50
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
|
51
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
52
54
|
else
|
53
55
|
s.add_dependency(%q<json>, [">= 0"])
|
@@ -55,7 +57,7 @@ Gem::Specification.new do |s|
|
|
55
57
|
s.add_dependency(%q<rake>, [">= 0"])
|
56
58
|
s.add_dependency(%q<yard>, [">= 0"])
|
57
59
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
58
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.0"])
|
59
61
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
60
62
|
end
|
61
63
|
else
|
@@ -64,7 +66,7 @@ Gem::Specification.new do |s|
|
|
64
66
|
s.add_dependency(%q<rake>, [">= 0"])
|
65
67
|
s.add_dependency(%q<yard>, [">= 0"])
|
66
68
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
67
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.0"])
|
68
70
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
69
71
|
end
|
70
72
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "NSISam::Client::Configuration" do
|
4
|
+
Configuration = NSISam::Client::Configuration
|
5
|
+
|
6
|
+
it "set and return user" do
|
7
|
+
Configuration.user 'why'
|
8
|
+
Configuration.user.should == 'why'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "set and return password" do
|
12
|
+
Configuration.password 'admin123'
|
13
|
+
Configuration.password.should == 'admin123'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "set and return host" do
|
17
|
+
Configuration.host '192.168.0.100'
|
18
|
+
Configuration.host.should == '192.168.0.100'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "set and return port" do
|
22
|
+
Configuration.port '8888'
|
23
|
+
Configuration.port.should == '8888'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "return a hash of attributes" do
|
27
|
+
Configuration.instance_eval do
|
28
|
+
user "why"
|
29
|
+
password "chunky"
|
30
|
+
host "localhost"
|
31
|
+
port "8888"
|
32
|
+
end
|
33
|
+
Configuration.settings.should == {user: "why", password: "chunky",
|
34
|
+
host: "localhost", port: "8888"}
|
35
|
+
end
|
36
|
+
end
|
data/spec/nsisam_spec.rb
CHANGED
@@ -3,7 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe NSISam do
|
4
4
|
|
5
5
|
before :all do
|
6
|
-
@nsisam = NSISam::Client.new '
|
6
|
+
@nsisam = NSISam::Client.new user: 'test', password: 'test',
|
7
|
+
host: 'localhost', port: '8888'
|
7
8
|
@keys = Array.new
|
8
9
|
@fake_sam = NSISam::FakeServerManager.new.start_server
|
9
10
|
end
|
@@ -14,7 +15,8 @@ describe NSISam do
|
|
14
15
|
|
15
16
|
context "cannot connect to server" do
|
16
17
|
it "throws error if couldn't connect to the server" do
|
17
|
-
sam = NSISam::Client.new '
|
18
|
+
sam = NSISam::Client.new user: 'test', password: 'test',
|
19
|
+
host: 'localhost', port: '4000'
|
18
20
|
expect { sam.store('anything') }.to raise_error(NSISam::Errors::Client::ConnectionRefusedError)
|
19
21
|
end
|
20
22
|
end
|
@@ -78,4 +80,30 @@ describe NSISam do
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
83
|
+
context "get configuration" do
|
84
|
+
before do
|
85
|
+
NSISam::Client.configure do
|
86
|
+
user "why"
|
87
|
+
password "chunky"
|
88
|
+
host "localhost"
|
89
|
+
port "8888"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "by configure" do
|
94
|
+
sam = NSISam::Client.new
|
95
|
+
sam.instance_variable_get(:@user).should == "why"
|
96
|
+
sam.instance_variable_get(:@password).should == "chunky"
|
97
|
+
sam.instance_variable_get(:@host).should == "localhost"
|
98
|
+
sam.instance_variable_get(:@port).should == "8888"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "by initialize parameters" do
|
102
|
+
sam = NSISam::Client.new(user: 'luckystiff', password: 'bacon', host: 'why.com', port: '9999')
|
103
|
+
sam.instance_variable_get(:@user).should == "luckystiff"
|
104
|
+
sam.instance_variable_get(:@password).should == "bacon"
|
105
|
+
sam.instance_variable_get(:@host).should == "why.com"
|
106
|
+
sam.instance_variable_get(:@port).should == "9999"
|
107
|
+
end
|
108
|
+
end
|
81
109
|
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.4.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-
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.
|
101
|
+
version: 1.1.0
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.
|
109
|
+
version: 1.1.0
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: jeweler
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,9 +141,11 @@ files:
|
|
141
141
|
- VERSION
|
142
142
|
- lib/nsisam.rb
|
143
143
|
- lib/nsisam/client.rb
|
144
|
+
- lib/nsisam/configuration.rb
|
144
145
|
- lib/nsisam/errors.rb
|
145
146
|
- lib/nsisam/fake_server.rb
|
146
147
|
- nsisam.gemspec
|
148
|
+
- spec/configuration_spec.rb
|
147
149
|
- spec/nsisam_spec.rb
|
148
150
|
- spec/spec_helper.rb
|
149
151
|
homepage: http://github.com/nsi-iff/nsisam-ruby
|
@@ -161,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
163
|
version: '0'
|
162
164
|
segments:
|
163
165
|
- 0
|
164
|
-
hash: -
|
166
|
+
hash: -1798483526539682580
|
165
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
168
|
none: false
|
167
169
|
requirements:
|