em-swirl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +22 -0
  2. data/README.md +78 -0
  3. data/lib/em-swirl.rb +27 -0
  4. metadata +106 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007, 2008, 2009 Blake Mizerany
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ EM-Swirl
2
+ =====
3
+
4
+ Swirl is an evented EC2 version agnostic client for EC2 written in Ruby. It gets
5
+ out of your way.
6
+
7
+ The secret is it's simple input extraction and output compacting. Your
8
+ input parameters and `expand`ed and EC2's (terrible) xml output is
9
+ `compact`ed.
10
+
11
+
12
+ Some simple examples:
13
+
14
+ # Input
15
+ { "InstanceId" => ["i-123k2h1", "i-0234d3"] }
16
+
17
+ is `expand`ed to:
18
+
19
+ { "InstanceId.0" => "i-123k2h1", "InstanceId.1" => "i-0234d3" }
20
+
21
+ in the case that `.n` isn't at the end of the key:
22
+
23
+ { "Foo.#.Bar" => ["a", "b"] }
24
+
25
+ is `expand`ed to:
26
+
27
+ { "Foo.0.Bar" => "a", "Foo.1.Bar" => "b" }
28
+
29
+ and
30
+
31
+ # Output
32
+ {
33
+ "reservationSet" => {
34
+ "item" => {
35
+ "instancesSet" => { "item" => [ ... ] }
36
+ }
37
+ }
38
+ }
39
+
40
+ and it's variations are now `compact`ed to:
41
+
42
+ {
43
+ "reservationSet" => {
44
+ "instancesSet" => [ { ... }, { ... } ]
45
+ }
46
+ }
47
+
48
+
49
+ Some things worth noting is that compact ignores Symbols. This
50
+ allows you to pass the params into `call` and use them later
51
+ without affecting the API call (i.e. chain of responsibility); a
52
+ nifty trick we use in (Rack)[http://github.com/rack/rack]
53
+
54
+ Use
55
+ ---
56
+
57
+ require 'swirl/ec2/em'
58
+
59
+ EM.run do
60
+ ec2 = Swirl::EC2.new
61
+
62
+ # Describe all instances
63
+ ec2.call "DescribeInstances" do |reservation_set|
64
+ p reservation_set
65
+ end
66
+
67
+ # Describe specific instances
68
+ r = ec2.call "DescribeInstances", "InstanceId" => ["i-38hdk2f", "i-93nndch"] do |reservation_set|
69
+ p reservation_set
70
+ end
71
+
72
+ # Catch an error if the request gets one
73
+ # NOTE: If you don't catch errors, they will be swollowed
74
+ r.error do |e|
75
+ p e
76
+ end
77
+
78
+ end
data/lib/em-swirl.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'swirl/ec2'
2
+ require 'em-http'
3
+
4
+ module Swirl
5
+ class EC2
6
+ def post(body, &blk)
7
+ headers = { "Content-Type" => "application/x-www-form-urlencoded" }
8
+
9
+ http = EM::HttpRequest.new(@url.to_s)
10
+ req = http.post(:head => headers, :body => body)
11
+
12
+ req.callback do
13
+ begin
14
+ blk.call(req.response_header.status, req.response)
15
+ rescue => e
16
+ req.fail(e)
17
+ end
18
+ end
19
+
20
+ def req.error(&blk)
21
+ errback(&blk)
22
+ end
23
+
24
+ req
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-swirl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Blake Mizerany
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-22 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: swirl
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: em-http-request
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 0
48
+ - 3
49
+ - 0
50
+ version: 0.3.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: An evented, version agnostic EC2 ruby driver
54
+ email:
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - README.md
61
+ - LICENSE
62
+ files:
63
+ - LICENSE
64
+ - README.md
65
+ - lib/em-swirl.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/bmizerany/em-swirl
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --line-numbers
73
+ - --inline-source
74
+ - --title
75
+ - em-swirl
76
+ - --main
77
+ - README.rdoc
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project: em-swirl
101
+ rubygems_version: 1.5.2
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: An evented, version agnostic EC2 ruby driver
105
+ test_files: []
106
+