conduit-sdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +122 -0
- data/Rakefile +2 -0
- data/conduit.gemspec +23 -0
- data/lib/conduit.rb +89 -0
- data/lib/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b1523f3b4dd9019a07e73f39320df07cbf79d58
|
4
|
+
data.tar.gz: 880a5e757a3bfb43b1ab53b3accfb4f25fd84db8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 832552cea615906e25bdf00a1e2cd0abb2601bd9a3adcaa082bc0ba65a1bda81bfd0a21c21b7ddf13349146cc57c7798af1108d858ff21c427da7d75081df5b1
|
7
|
+
data.tar.gz: 31ce006881e556c5535fd3c6cdd6bc09a559df0d67c55bbe36922e38240325eaa037544e1c6375527ca78028fe4fcc847e5531f649ae75cacfe45fd75c436892
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Joe Bellus
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Ruby SDK for Conduit
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'conduit-sdk'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install conduit-sdk
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Create a client
|
22
|
+
|
23
|
+
To create a client you will need an administrative access key and key name. These can be generated from the conduit CLI on the server.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Conduit::Client.new(hostAddress, keyName, keySecret)
|
27
|
+
```
|
28
|
+
|
29
|
+
### Register a mailbox
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
client = Conduit::Client.new(hostAddress, keyName, keySecret)
|
33
|
+
client.register("my.mailbox.name")
|
34
|
+
```
|
35
|
+
|
36
|
+
This will register a new mailbox with the server, it will raise Conduit::APIError on failure.
|
37
|
+
|
38
|
+
### Deregister a mailbox
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
client = Conduit::Client.new(hostAddress, keyName, keySecret)
|
42
|
+
client.deregister("my.mailbox.name")
|
43
|
+
```
|
44
|
+
|
45
|
+
This will delete a mailbox and purge its messages, it will raise Conduit::APIError on failure.
|
46
|
+
|
47
|
+
### Getting system statistics
|
48
|
+
|
49
|
+
The system_stats method will return a number of metrics.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
client = Conduit::Client.new(hostAddress, keyName, keySecret)
|
53
|
+
stats = client.system.stats
|
54
|
+
puts stats[:field]
|
55
|
+
```
|
56
|
+
|
57
|
+
#### Fields
|
58
|
+
|
59
|
+
* _totalMailboxes_ - The total number of mailboxes registered in the system.
|
60
|
+
* _messageCount_ - The total number of messages that have passed through the system.
|
61
|
+
* _pendingMessages_ - The current number of messages waiting to be delivered.
|
62
|
+
* _connectedClients_ - The current number of clients that are connected to the server.
|
63
|
+
* _dbVersion_ - The server database version.
|
64
|
+
* _threads_ - The number of active threads the server is using.
|
65
|
+
* _cpuCount_ - The number of CPUs available to the server.
|
66
|
+
* _memory_ - The total allocated memory the server is currently using.
|
67
|
+
* _filesCount_ - The total number of script assets stored on the server.
|
68
|
+
* _filesSize_ - The size on disk of all script assets the server is holding.
|
69
|
+
|
70
|
+
### Getting client statistics
|
71
|
+
|
72
|
+
The system_stats method will return a number of metrics.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
client = Conduit::Client.new(hostAddress, keyName, keySecret)
|
76
|
+
stats = client.client_stats.clients.each do |client|
|
77
|
+
puts client[:field]
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
#### Fields
|
82
|
+
|
83
|
+
* _version_ - The client's last reported Conduit version.
|
84
|
+
* _online_ - True if the client is currently connected.
|
85
|
+
* _mailbox_ - The client's mailbox name.
|
86
|
+
* _lastSeenAt_ - A date/time string when the client last checked for messages.
|
87
|
+
* _host_ - The IP address of the client.
|
88
|
+
|
89
|
+
### Listing deployments
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
client = Conduit::Client.new(hostAddress, keyName, keySecret)
|
93
|
+
client.list_deployments(_options_).deployments.each do |d|
|
94
|
+
puts d[:field]
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
#### Options
|
99
|
+
|
100
|
+
* _deploymentId_ - The name of a specific deployment. If specified the response will contain a :responses array which will contain information on the client responses to the deployment.
|
101
|
+
* _nameSearch_ - A glob pattern for searching deployment names (ex: "Upgrade*").
|
102
|
+
* _keySearch_ - A glob pattern for searching for deployments based on the keyname that deployed them (ex: ops.*).
|
103
|
+
* _count_ - The number of deployments to return.
|
104
|
+
|
105
|
+
#### Fields
|
106
|
+
|
107
|
+
* _name_ - The name of the deployment
|
108
|
+
* _createdAt_ A date string representing the creation time of the deployment.
|
109
|
+
* _pendignMessages_ - The number of messages that have not been picked up.
|
110
|
+
* _totalMessages_ - The total number of messages deployed.
|
111
|
+
* _responseCount_ - The number of responses received
|
112
|
+
* _responses_ - An array of hashses for the client responses to the deployments. Each has has the follwoing keys: Mailbox, Response, RespondedAt, and IsError. This value is only present if a specific deploymentId was specifeid.
|
113
|
+
* _deployedBy_ - The access key name used to create the deployment.
|
114
|
+
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
1. Fork it ( https://github.com/[my-github-username]/conduit-ruby/fork )
|
119
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
120
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
121
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
122
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/conduit.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conduit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conduit-sdk"
|
8
|
+
spec.version = Conduit::VERSION
|
9
|
+
spec.authors = ["Joe Bellus"]
|
10
|
+
spec.email = ["joe@5sigma.io"]
|
11
|
+
spec.summary = %q{Ruby bindings for Conduit.}
|
12
|
+
spec.description = %q{An API SDK for communicating with a Conduit server.}
|
13
|
+
spec.homepage = "http://conduit.5sigma.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/conduit.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
#require "conduit/version"
|
2
|
+
require "openssl"
|
3
|
+
require "base64"
|
4
|
+
require "net/http"
|
5
|
+
require "json"
|
6
|
+
require 'securerandom'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
module Conduit
|
10
|
+
|
11
|
+
class ApiError < StandardError; end
|
12
|
+
|
13
|
+
class ApiClient
|
14
|
+
attr_accessor :host, :access_key_name, :access_key_secret
|
15
|
+
def initialize(host, key_name, key_secret)
|
16
|
+
@host = host
|
17
|
+
@access_key_name = key_name
|
18
|
+
@access_key_secret = key_secret
|
19
|
+
end
|
20
|
+
|
21
|
+
def sign!(request)
|
22
|
+
request[:requestTime] = Time.new.strftime("%Y-%m-%dT%H:%M:%S%:z")
|
23
|
+
request[:token] = SecureRandom.uuid
|
24
|
+
data = request[:token] + request[:requestTime]
|
25
|
+
hmac = OpenSSL::HMAC.digest("sha256", @access_key_secret, data)
|
26
|
+
request[:keyName] = @access_key_name
|
27
|
+
request[:signature] = Base64.encode64(hmac)
|
28
|
+
end
|
29
|
+
|
30
|
+
def request(endpoint, request)
|
31
|
+
uri = URI("http://#{@host}/#{endpoint}")
|
32
|
+
req = Net::HTTP::Post.new(uri)
|
33
|
+
req.content_type = 'application/json'
|
34
|
+
sign! request
|
35
|
+
req.body = JSON.generate(request)
|
36
|
+
res = Net::HTTP.new(uri.hostname, uri.port).start {|h| h.request(req) }
|
37
|
+
if res.code == "200"
|
38
|
+
return JSON.parse(res.body)
|
39
|
+
end
|
40
|
+
if res.code == "404"
|
41
|
+
raise ApiError, "Endpoint not found"
|
42
|
+
end
|
43
|
+
if res.code == "400"
|
44
|
+
raise ApiError, JSON.parse(res.body)[:error]
|
45
|
+
end
|
46
|
+
puts res.code
|
47
|
+
end
|
48
|
+
|
49
|
+
def register(mailbox_name)
|
50
|
+
request "register", {mailbox: mailbox_name}
|
51
|
+
end
|
52
|
+
|
53
|
+
def deregister(mailbox_name)
|
54
|
+
request "deregister", {mailbox: mailbox_name}
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_message()
|
58
|
+
request "get", {mailbox: mailbox_name}
|
59
|
+
end
|
60
|
+
|
61
|
+
def system_stats()
|
62
|
+
request "stats", {}
|
63
|
+
end
|
64
|
+
|
65
|
+
def client_stats()
|
66
|
+
request "stats/clients", {}
|
67
|
+
end
|
68
|
+
|
69
|
+
def list_deployments(opts = {})
|
70
|
+
request = {}
|
71
|
+
request[:deploymentId] = opts[:id] || ""
|
72
|
+
request[:nameSearch] = opts[:name] || ""
|
73
|
+
request[:keySearch] = opts[:keyName] || ""
|
74
|
+
request[:count] = opts[:count] || 10
|
75
|
+
request "deploy/list", request
|
76
|
+
end
|
77
|
+
|
78
|
+
def deploy(mailboxes, script, opts = {})
|
79
|
+
request = {body: script}
|
80
|
+
request[:mailboxes] = mailboxes if mailboxes.is_a Array
|
81
|
+
request[:pattern] = mailboxes if mailboxes.is_a String
|
82
|
+
request[:deploymentName] = opts[:name] if opts[:name]
|
83
|
+
request[:asset] = opts[:asset] if opts[:asset]
|
84
|
+
request "put", request
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conduit-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe Bellus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: An API SDK for communicating with a Conduit server.
|
42
|
+
email:
|
43
|
+
- joe@5sigma.io
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- conduit.gemspec
|
54
|
+
- lib/conduit.rb
|
55
|
+
- lib/version.rb
|
56
|
+
homepage: http://conduit.5sigma.io
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Ruby bindings for Conduit.
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|