nsisam 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "json"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rake"
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.8.3"
15
+ gem "simplecov"
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Douglas Camata
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = nsisam
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to nsisam
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Douglas Camata. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "nsisam"
18
+ gem.homepage = "http://github.com/nsi-iff/nsisam-ruby"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A simple gem to access a SAM service.}
21
+ gem.description = %Q{A simple gem to access a SAM node. For more info about SAM
22
+ visit www.github.com/nsi-iff/sam_buildout.}
23
+ gem.email = "d.camata@gmail.com"
24
+ gem.authors = ["Douglas Camata"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "nsisam #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/client.rb ADDED
@@ -0,0 +1,56 @@
1
+ require "json"
2
+ require "net/http"
3
+
4
+ module Client
5
+ class Client
6
+
7
+ def initialize(url)
8
+ user_and_pass = url.match(/(\w+):(\w+)/)
9
+ @user, @password = user_and_pass[1], user_and_pass[2]
10
+ @url = url.match(/@(\w*)/)[1]
11
+ @port = url.match(/[0-9]{4}/)[0]
12
+ end
13
+
14
+ def store(data)
15
+ request_data = {:value => data}.to_json
16
+ request = prepare_request :PUT, request_data
17
+ execute_request(request)
18
+ end
19
+
20
+ def delete(key)
21
+ request_data = {:key => key}.to_json
22
+ request = prepare_request :DELETE, request_data
23
+ execute_request(request)
24
+ end
25
+
26
+ def get(key)
27
+ request_data = {:key => key}.to_json
28
+ request = prepare_request :GET, request_data
29
+ execute_request(request)
30
+ end
31
+
32
+ def update(key, value)
33
+ request_data = {:key => key, :value => value}.to_json
34
+ request = prepare_request :POST, request_data
35
+ execute_request(request)
36
+ end
37
+
38
+ private
39
+
40
+ def prepare_request(verb, body)
41
+ verb = verb.to_s.capitalize!
42
+ request = Net::HTTP.const_get("#{verb}").new '/'
43
+ request.body = body
44
+ request.basic_auth @user, @password
45
+ request
46
+ end
47
+
48
+ def execute_request(request)
49
+ response = Net::HTTP.start @url, @port do |http|
50
+ http.request(request)
51
+ end
52
+ JSON.parse(response.body)
53
+ end
54
+
55
+ end
56
+ end
data/lib/nsisam.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'client'
2
+
3
+ module NSISam
4
+ include Client
5
+
6
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe NSISam do
4
+
5
+ before :all do
6
+ @nsisam = NSISam::Client.new 'http://test:test@localhost:8888'
7
+ @keys = Array.new
8
+ end
9
+
10
+ after :all do
11
+ @keys.each { |key| @nsisam.delete(key) }
12
+ end
13
+
14
+ it "can store a value in SAM" do
15
+ response = @nsisam.store("something")
16
+ response.should_not be_nil
17
+ response.should have_key("key")
18
+ response.should have_key("checksum")
19
+
20
+ @keys.push(response["key"])
21
+ end
22
+
23
+ it "can delete a stored value" do
24
+ key = @nsisam.store("delete this")["key"]
25
+ response = @nsisam.delete(key)
26
+ response["deleted"].should be_true
27
+ end
28
+
29
+ it "can retrieve a stored value" do
30
+ key = @nsisam.store("retrieve this")["key"]
31
+ response = @nsisam.get(key)
32
+ response["data"].should == "retrieve this"
33
+
34
+ @keys.push(key)
35
+ end
36
+
37
+ it "can update values in keys already stored" do
38
+ key = @nsisam.store("update this")["key"]
39
+ response = @nsisam.update(key, "updated")
40
+ response["key"].should == key
41
+ response.should have_key("checksum")
42
+
43
+ @keys.push(key)
44
+ end
45
+
46
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'nsisam'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nsisam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Douglas Camata
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70359173552000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70359173552000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70359173566740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70359173566740
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70359173565780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.8.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70359173565780
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70359173564980 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70359173564980
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70359173564040 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70359173564040
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70359173584480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70359173584480
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &70359173577380 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70359173577380
91
+ description: ! "A simple gem to access a SAM node. For more info about SAM\n visit
92
+ www.github.com/nsi-iff/sam_buildout."
93
+ email: d.camata@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.rdoc
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ - Rakefile
106
+ - VERSION
107
+ - lib/client.rb
108
+ - lib/nsisam.rb
109
+ - spec/nsisam_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: http://github.com/nsi-iff/nsisam-ruby
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
125
+ - 0
126
+ hash: -2847547609533104459
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.15
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: A simple gem to access a SAM service.
139
+ test_files: []