Skip to content

Commit 846276b

Browse files
author
Michael Klishin
committed
Initial commit
0 parents  commit 846276b

File tree

11 files changed

+530
-0
lines changed

11 files changed

+530
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source 'https://rubygems.org'
2+
3+
group :development, :test do
4+
gem "rspec"
5+
gem "json"
6+
gem "bunny", ">= 0.9.0.pre3"
7+
end
8+
9+
# Specify your gem's dependencies in superintendent.gemspec
10+
gemspec

LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2012 Michael Klishin
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Superintendent, a RabbitMQ HTTP API Client for Ruby
2+
3+
TODO: Write a gem description
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
gem 'superintendent'
10+
11+
And then execute:
12+
13+
$ bundle
14+
15+
Or install it yourself as:
16+
17+
$ gem install superintendent
18+
19+
## Usage
20+
21+
TODO: Write usage instructions here
22+
23+
## Contributing
24+
25+
1. Fork it
26+
2. Create your feature branch (`git checkout -b my-new-feature`)
27+
3. Commit your changes (`git commit -am 'Add some feature'`)
28+
4. Push to the branch (`git push origin my-new-feature`)
29+
5. Create new Pull Request
30+
31+
32+
## License & Copyright
33+
34+
Double-licensed under the MIT and Mozilla Public License (same as RabbitMQ).
35+
36+
(c) Michael S. Klishin, 2012-2013.

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

lib/superintendent.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "superintendent/version"
2+
require "superintendent/client"

lib/superintendent/client.rb

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
require "hashie"
2+
require "faraday"
3+
require "faraday_middleware"
4+
require "multi_json"
5+
6+
# for URI encoding
7+
require "cgi"
8+
9+
module Superintendent
10+
class Client
11+
12+
#
13+
# API
14+
#
15+
16+
def self.connect(endpoint, options = {})
17+
new(endpoint, options)
18+
end
19+
20+
def initialize(endpoint, options = {})
21+
@endpoint = endpoint
22+
@options = options
23+
24+
initialize_connection(endpoint, options)
25+
end
26+
27+
def overview
28+
response = @connection.get("/api/overview")
29+
Hashie::Mash.new(response.body)
30+
end
31+
32+
def list_nodes
33+
response = @connection.get("/api/nodes")
34+
response.body.map { |i| Hashie::Mash.new(i) }
35+
end
36+
37+
def node_info(name)
38+
response = @connection.get("/api/nodes/#{uri_encode(name)}")
39+
Hashie::Mash.new(response.body)
40+
end
41+
42+
def list_extensions
43+
response = @connection.get("/api/extensions")
44+
response.body.map { |i| Hashie::Mash.new(i) }
45+
end
46+
47+
def list_definitions
48+
response = @connection.get("/api/definitions")
49+
response.body.map { |i| Hashie::Mash.new(i) }
50+
end
51+
52+
def upload_definitions(defs)
53+
raise NotImplementedError.new
54+
end
55+
56+
def list_connections
57+
response = @connection.get("/api/connections")
58+
response.body.map { |i| Hashie::Mash.new(i) }
59+
end
60+
61+
def connection_info(name)
62+
response = @connection.get("/api/connections/#{uri_encode(name)}")
63+
Hashie::Mash.new(response.body)
64+
end
65+
66+
def close_connection(name)
67+
response = @connection.delete("/api/connections/#{uri_encode(name)}")
68+
Hashie::Mash.new(response.body)
69+
end
70+
71+
def list_channels
72+
response = @connection.get("/api/channels")
73+
response.body.map { |i| Hashie::Mash.new(i) }
74+
end
75+
76+
def channel_info(name)
77+
response = @connection.get("/api/channels/#{uri_encode(name)}")
78+
Hashie::Mash.new(response.body)
79+
end
80+
81+
def list_exchanges(vhost = nil)
82+
path = if vhost.nil?
83+
"/api/exchanges"
84+
else
85+
"/api/exchanges/#{uri_encode(vhost)}"
86+
end
87+
88+
response = @connection.get(path)
89+
response.body.map { |i| Hashie::Mash.new(i) }
90+
end
91+
92+
def exchange_info(vhost, name)
93+
response = @connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}")
94+
Hashie::Mash.new(response.body)
95+
end
96+
97+
def list_bindings_by_source(vhost, exchange)
98+
response = @connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/source")
99+
response.body.map { |i| Hashie::Mash.new(i) }
100+
end
101+
102+
def list_bindings_by_destination(vhost, exchange)
103+
response = @connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/destination")
104+
response.body.map { |i| Hashie::Mash.new(i) }
105+
end
106+
107+
108+
protected
109+
110+
def initialize_connection(endpoint, options = {})
111+
@connection = Faraday.new(:url => endpoint) do |conn|
112+
conn.basic_auth options.fetch(:username, "guest"), options.fetch(:password, "guest")
113+
conn.use FaradayMiddleware::FollowRedirects, :limit => 3
114+
conn.response :json, :content_type => /\bjson$/
115+
116+
conn.adapter options.fetch(:adapter, Faraday.default_adapter)
117+
end
118+
end
119+
120+
def uri_encode(s)
121+
CGI.escape(s)
122+
end
123+
124+
end # Client
125+
end # Superintendent

lib/superintendent/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Superintendent
2+
VERSION = "1.0.0.pre1"
3+
end

0 commit comments

Comments
 (0)