trafficbroker-redalert 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +34 -0
- data/lib/alerts/gateway.rb +53 -0
- data/lib/redalert.rb +11 -0
- metadata +75 -0
data/README
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= Cardwall Alerts
|
2
|
+
|
3
|
+
== SYNOPSIS
|
4
|
+
|
5
|
+
Red Alert makes it easier to post alerts to the cardwall
|
6
|
+
|
7
|
+
|
8
|
+
== USAGE
|
9
|
+
|
10
|
+
Create a gateway to the cardwall with credentials for an account that has access to all the projects that you want to post alerts to.
|
11
|
+
|
12
|
+
require 'redalert'
|
13
|
+
|
14
|
+
alert_gateway = CardWall::Alerts::Gateway.new(username, password)
|
15
|
+
|
16
|
+
Then get posting.
|
17
|
+
|
18
|
+
alert_gateway.post("Project name", "Alert title", "This is the body of the alert")
|
19
|
+
|
20
|
+
To post files.
|
21
|
+
|
22
|
+
alert_gateway.post("Project name", "Alert title", "This is the body of the alert", :file_name => "some_name.csv", :file_body => "Yabadabadoo")
|
23
|
+
|
24
|
+
|
25
|
+
== REQUIREMENTS
|
26
|
+
|
27
|
+
You need these gems installed:
|
28
|
+
- openssl
|
29
|
+
- rest-client
|
30
|
+
- multipart-post
|
31
|
+
|
32
|
+
== INSTALL
|
33
|
+
|
34
|
+
sudo gem install redalert-0.0.1.gem
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module CardWall
|
2
|
+
module Alerts
|
3
|
+
class AlertPostError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class Gateway
|
7
|
+
|
8
|
+
def initialize(username, password, cardwall_url = "https://www.cardwall.co.uk")
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
@base_url = cardwall_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(project, title, body, file = nil)
|
15
|
+
url = URI.parse(URI.escape("#{@base_url}/projects/#{project}/alerts"))
|
16
|
+
puts "posting to: #{url}"
|
17
|
+
|
18
|
+
req = Net::HTTP::Post::Multipart.new url.path, request_hash(title, body, file)
|
19
|
+
req.basic_auth @username, @password
|
20
|
+
|
21
|
+
http = Net::HTTP.new(url.host, url.port)
|
22
|
+
http.use_ssl = true if url.port == 443
|
23
|
+
result = http.start do |http|
|
24
|
+
http.request(req)
|
25
|
+
end
|
26
|
+
|
27
|
+
return if result.is_a?(Net::HTTPSuccess)
|
28
|
+
|
29
|
+
puts "Result: #{result.inspect}"
|
30
|
+
puts "Could not post alert: #{result.body}"
|
31
|
+
|
32
|
+
result.error!
|
33
|
+
rescue Net::HTTPServerException, Errno::ECONNREFUSED => e
|
34
|
+
raise AlertPostError.new(e.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def request_hash(title, body, file)
|
38
|
+
request_hash = {"title" => title, "body" => body}
|
39
|
+
|
40
|
+
if file
|
41
|
+
s = StringIO.new("", "w+")
|
42
|
+
gz = Zlib::GzipWriter.new(s)
|
43
|
+
gz.write file[:file_body]
|
44
|
+
gz.close
|
45
|
+
|
46
|
+
request_hash["file"] = UploadIO.new(StringIO.new(s.string), "text/plain", file[:file_name])
|
47
|
+
end
|
48
|
+
|
49
|
+
return request_hash
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/redalert.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trafficbroker-redalert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abhinay Mehta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: multipart-post
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: abhinay.mehta@trafficbroker.co.uk
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- lib/redalert.rb
|
46
|
+
- lib/alerts/gateway.rb
|
47
|
+
has_rdoc: false
|
48
|
+
homepage: https://www.cardwall.co.uk
|
49
|
+
licenses:
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.5
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: Makes it easier to send alerts to cardwall.
|
74
|
+
test_files: []
|
75
|
+
|