rubineti 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.0
@@ -21,64 +21,46 @@ module Rubineti
21
21
  # +user+: A String containing the username for use in HTTP Basic auth.
22
22
  # +password+: A String containing the password for use in HTTP Basic auth.
23
23
  # +host+: A String with the host to connect.
24
- #
25
- # TODO: force required fields.
26
-
27
- def initialize params
28
- @user = params[:user]
29
- @password = params[:password]
30
- @host = params[:host]
31
- @port = params[:port] || 5080
32
- @scheme = params[:scheme] || "https"
33
- end
34
24
 
35
- ##
36
- # Perform an HTTP get.
37
- # +path+: A String with the path to the HTTP resource.
38
- # +params+: A Hash with the following keys:
39
- # - +:query+: Query String in the format "foo=bar"
40
- # - +:body+: A sub Hash to be JSON encoded, and posted in
41
- # the message body.
25
+ def initialize options
26
+ @user = options[:user]
27
+ @password = options[:password]
28
+ @host = options[:host]
29
+ @port = options[:port] || 5080
30
+ @scheme = options[:scheme] || "https"
42
31
 
43
- def get path, params = {}
44
- parse response_for(Net::HTTP::Get, path, params)
32
+ requires [:user, :password, :host]
45
33
  end
46
34
 
47
35
  ##
48
- # Perform an HTTP put.
36
+ # Perform an HTTP get, delete, post, or put.
49
37
  # +path+: A String with the path to the HTTP resource.
50
38
  # +params+: A Hash with the following keys:
51
39
  # - +:query+: Query String in the format "foo=bar"
52
40
  # - +:body+: A sub Hash to be JSON encoded, and posted in
53
41
  # the message body.
54
42
 
55
- def delete path, params = {}
56
- parse response_for(Net::HTTP::Delete, path, params)
43
+ %w(get delete post put).each do |verb|
44
+ define_method verb do |*args|
45
+ path = args[0]
46
+ params = args[1] || {}
47
+ clazz = eval "Net::HTTP::#{verb.capitalize}"
48
+
49
+ parse response_for(clazz, path, params)
50
+ end
57
51
  end
58
52
 
59
53
  ##
60
- # Perform an HTTP get.
61
- # +path+: A String with the path to the HTTP resource.
62
- # +params+: A Hash with the following keys:
63
- # - +:query+: Query String in the format "foo=bar"
64
- # - +:body+: A sub Hash to be JSON encoded, and posted in
65
- # the message body.
54
+ # :method: get
66
55
 
67
- def post path, params = {}
68
- parse response_for(Net::HTTP::Post, path, params)
69
- end
56
+ ##
57
+ # :method: delete
70
58
 
71
59
  ##
72
- # Perform an HTTP put.
73
- # +path+: A String with the path to the HTTP resource.
74
- # +params+: A Hash with the following keys:
75
- # - +:query+: Query String in the format "foo=bar"
76
- # - +:body+: A sub Hash to be JSON encoded, and posted in
77
- # the message body.
60
+ # :method: post
78
61
 
79
- def put path, params = {}
80
- parse response_for(Net::HTTP::Put, path, params)
81
- end
62
+ ##
63
+ # :method: put
82
64
 
83
65
  private
84
66
  ##
@@ -118,8 +100,11 @@ module Rubineti
118
100
  ::Yajl::Encoder.encode hash
119
101
  end
120
102
 
121
- #def requires key
122
- # raise StandardError.new "FATAL: Rubineti::Compute#initialize :#{key} required."
123
- #end
103
+ def requires args
104
+ args.each do |arg|
105
+ raise StandardError.new "FATAL: Rubineti::Compute#initialize :#{arg} required." if
106
+ self.instance_variable_get(:"@#{arg}").nil?
107
+ end
108
+ end
124
109
  end
125
110
  end
data/rubineti.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubineti}
8
- s.version = "1.0.2"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["retr0h"]
12
- s.date = %q{2010-11-29}
12
+ s.date = %q{2010-12-07}
13
13
  s.email = %q{john@dewey.ws}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -16,7 +16,7 @@ describe Rubineti::Compute do
16
16
 
17
17
  VCR.use_cassette "node_list" do
18
18
  response = Connection.node_list node_name
19
-
19
+
20
20
  response.must_be_kind_of Hash
21
21
  end
22
22
  end
@@ -11,12 +11,12 @@ describe Rubineti::Compute do
11
11
  }
12
12
  end
13
13
 
14
- describe "#initialize" do
15
- #it "requires params" do
16
- # @valid_params.keys.each do |param|
17
- # lambda { Rubineti::Compute.new @valid_params.reject { |k,v| k == param } }.must_raise StandardError
18
- # end
19
- #end
14
+ describe "#requires" do
15
+ [:user, :password, :host].each do |opt|
16
+ it "has required '#{opt}' option" do
17
+ lambda { Rubineti::Compute.new @valid_params.reject { |k,v| k == opt } }.must_raise StandardError
18
+ end
19
+ end
20
20
  end
21
21
 
22
22
  describe "#response_for" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 2
9
- version: 1.0.2
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - retr0h
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-29 00:00:00 -08:00
17
+ date: 2010-12-07 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency