nsicloudooo 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.3.0
@@ -1,15 +1,31 @@
1
1
  require "json"
2
2
  require "net/http"
3
3
  require File.dirname(__FILE__) + '/errors'
4
+ require File.dirname(__FILE__) + '/configuration'
4
5
 
5
6
  module NSICloudooo
6
7
  class Client
7
8
 
8
- def initialize(url)
9
- user_and_pass = url.match(/(\w+):(\w+)/)
10
- @user, @password = user_and_pass[1], user_and_pass[2]
11
- @url = url.match(/@(.*):/)[1]
12
- @port = url.match(/([0-9]+)(\/)?$/)[1]
9
+ # Initialize a client to a CloudoooManager node
10
+ #
11
+ # @param [Hash] options used to connect to the desired CloudoooManager
12
+ # @options options [String] host to connect
13
+ # @options options [String] port to connect
14
+ # @options options [String] user to authenticatie with
15
+ # @options options [String] password to the refered user
16
+ #
17
+ # @return [Client] the object itself
18
+ # @example
19
+ # nsisam = NSISam::Client.new host: 'localhost', port: '8886', user: 'test', password: 'test'
20
+ #
21
+ # @note if you had used the 'configure' method, you can use it without parameters
22
+ # and those you provided before will be used (see Client#configure)
23
+ def initialize(params = {})
24
+ params = Configuration.settings.merge(params)
25
+ @user = params[:user]
26
+ @password = params[:password]
27
+ @host = params[:host]
28
+ @port = params[:port]
13
29
  end
14
30
 
15
31
  # Send a document be granulated by a nsi.cloudooo node
@@ -115,6 +131,14 @@ module NSICloudooo
115
131
  execute_request(request)
116
132
  end
117
133
 
134
+ # Pre-configure the NSICloudooo module with default params for the NSICloudooo::Client
135
+ #
136
+ # @yield a Configuration object (see {NSICloudooo::Client::Configuration})
137
+ #
138
+ def self.configure(&block)
139
+ Configuration.instance_eval(&block)
140
+ end
141
+
118
142
  private
119
143
 
120
144
  def insert_download_data(options)
@@ -137,7 +161,7 @@ module NSICloudooo
137
161
 
138
162
  def execute_request(request)
139
163
  begin
140
- response = Net::HTTP.start @url, @port do |http|
164
+ response = Net::HTTP.start @host, @port do |http|
141
165
  http.request(request)
142
166
  end
143
167
  rescue Errno::ECONNREFUSED => e
@@ -0,0 +1,58 @@
1
+ module NSICloudooo
2
+ class Client
3
+ class Configuration
4
+ class << self
5
+ # Set the default {NSICloudooo::Client} user
6
+ #
7
+ #
8
+ # @param [String] user to set
9
+ #
10
+ # @return [String] the user set
11
+ def user(user = nil)
12
+ @user = user unless user.nil?
13
+ @user
14
+ end
15
+
16
+ # Set the default {NSICloudooo::Client} password
17
+ #
18
+ #
19
+ # @param [String] password to set
20
+ #
21
+ # @return [String] the password set
22
+ def password(password = nil)
23
+ @password = password unless password.nil?
24
+ @password
25
+ end
26
+
27
+ # Set the default {NSICloudooo::Client} host
28
+ #
29
+ #
30
+ # @param [String] host to set
31
+ #
32
+ # @return [String] the host set
33
+ def host(host = nil)
34
+ @host = host unless host.nil?
35
+ @host
36
+ end
37
+
38
+ # Set the default {NSICloudooo::Client} port
39
+ #
40
+ #
41
+ # @param [String] port to set
42
+ #
43
+ # @return [String] the port set
44
+ def port(port = nil)
45
+ @port = port unless port.nil?
46
+ @port
47
+ end
48
+
49
+ # See how are the settings
50
+ #
51
+ # @return [Hash] actual settings
52
+ def settings
53
+ {user: @user, password: @password, host: @host, port: @port}
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
data/nsicloudooo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "nsicloudooo"
8
- s.version = "0.2.9"
8
+ s.version = "0.3.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-04-28"
12
+ s.date = "2012-05-16"
13
13
  s.description = "A simple gem to access a nsi.cloudooo node"
14
14
  s.email = "d.camata@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -26,16 +26,18 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "lib/nsicloudooo.rb",
28
28
  "lib/nsicloudooo/client.rb",
29
+ "lib/nsicloudooo/configuration.rb",
29
30
  "lib/nsicloudooo/errors.rb",
30
31
  "lib/nsicloudooo/fake_server.rb",
31
32
  "nsicloudooo.gemspec",
33
+ "spec/configuration_spec.rb",
32
34
  "spec/nsicloudooo_spec.rb",
33
35
  "spec/spec_helper.rb"
34
36
  ]
35
37
  s.homepage = "http://github.com/nsi-iff/nsicloudooo-ruby.git"
36
38
  s.licenses = ["MIT"]
37
39
  s.require_paths = ["lib"]
38
- s.rubygems_version = "1.8.21"
40
+ s.rubygems_version = "1.8.24"
39
41
  s.summary = "A simple gem to access a nsi.cloudooo node"
40
42
 
41
43
  if s.respond_to? :specification_version then
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "NSICloudooo::Client::Configuration" do
4
+ Configuration = NSICloudooo::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
@@ -6,7 +6,8 @@ $folder = File.expand_path(File.dirname(__FILE__))
6
6
  describe NSICloudooo do
7
7
 
8
8
  before :all do
9
- @nsicloudooo = NSICloudooo::Client.new 'http://test:test@localhost:9886'
9
+ @nsicloudooo = NSICloudooo::Client.new user: 'test', password: 'test',
10
+ host: 'localhost', port: '9886'
10
11
  @fake_cloudooo = NSICloudooo::FakeServerManager.new.start_server
11
12
  end
12
13
 
@@ -16,7 +17,8 @@ describe NSICloudooo do
16
17
 
17
18
  context "cannot connect to the server" do
18
19
  it "throws error if couldn't connec to the server" do
19
- nsicloudooo = NSICloudooo::Client.new 'http://test:test@localhost:4000'
20
+ nsicloudooo = NSICloudooo::Client.new user: 'test', password: 'test',
21
+ host: 'localhost', port: '4000'
20
22
  expect { nsicloudooo.granulate(:file => 'document', :filename => "teste.odt") }.to \
21
23
  raise_error(NSICloudooo::Errors::Client::ConnectionRefusedError)
22
24
  end
@@ -31,7 +33,7 @@ describe NSICloudooo do
31
33
 
32
34
  it "should throw error if any required parameter is missing" do
33
35
  expect { @nsicloudooo.granulate(:file => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
34
- expect { @nsicloudooo.granulate(:sam_uid => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
36
+ expect { @nsicloudooo.granulate(:cloudooo_uid => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
35
37
  expect { @nsicloudooo.granulate(:filename => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
36
38
  end
37
39
  end
@@ -89,5 +91,32 @@ describe NSICloudooo do
89
91
  end
90
92
  end
91
93
 
94
+ context "get configuration" do
95
+ before do
96
+ NSICloudooo::Client.configure do
97
+ user "why"
98
+ password "chunky"
99
+ host "localhost"
100
+ port "8888"
101
+ end
102
+ end
103
+
104
+ it "by configure" do
105
+ cloudooo = NSICloudooo::Client.new
106
+ cloudooo.instance_variable_get(:@user).should == "why"
107
+ cloudooo.instance_variable_get(:@password).should == "chunky"
108
+ cloudooo.instance_variable_get(:@host).should == "localhost"
109
+ cloudooo.instance_variable_get(:@port).should == "8888"
110
+ end
111
+
112
+ it "by initialize parameters" do
113
+ cloudooo = NSICloudooo::Client.new(user: 'luckystiff', password: 'bacon', host: 'why.com', port: '9999')
114
+ cloudooo.instance_variable_get(:@user).should == "luckystiff"
115
+ cloudooo.instance_variable_get(:@password).should == "bacon"
116
+ cloudooo.instance_variable_get(:@host).should == "why.com"
117
+ cloudooo.instance_variable_get(:@port).should == "9999"
118
+ end
119
+ end
120
+
92
121
  end
93
122
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsicloudooo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.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-04-28 00:00:00.000000000 Z
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -124,9 +124,11 @@ files:
124
124
  - VERSION
125
125
  - lib/nsicloudooo.rb
126
126
  - lib/nsicloudooo/client.rb
127
+ - lib/nsicloudooo/configuration.rb
127
128
  - lib/nsicloudooo/errors.rb
128
129
  - lib/nsicloudooo/fake_server.rb
129
130
  - nsicloudooo.gemspec
131
+ - spec/configuration_spec.rb
130
132
  - spec/nsicloudooo_spec.rb
131
133
  - spec/spec_helper.rb
132
134
  homepage: http://github.com/nsi-iff/nsicloudooo-ruby.git
@@ -144,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
146
  version: '0'
145
147
  segments:
146
148
  - 0
147
- hash: 1769661169347116718
149
+ hash: -4092089429222275052
148
150
  required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  none: false
150
152
  requirements:
@@ -153,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  version: '0'
154
156
  requirements: []
155
157
  rubyforge_project:
156
- rubygems_version: 1.8.21
158
+ rubygems_version: 1.8.24
157
159
  signing_key:
158
160
  specification_version: 3
159
161
  summary: A simple gem to access a nsi.cloudooo node