redphone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ pagerduty_service_key.txt
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in redphone.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => "test"
5
+
6
+ Rake::TestTask.new do |test|
7
+ test.pattern = "test/*_test.rb"
8
+ end
data/lib/redphone.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "redphone/version"
2
+
3
+ module Redphone
4
+ # Hello World!
5
+ end
@@ -0,0 +1,30 @@
1
+ require "rubygems" if RUBY_VERSION < "1.9.0"
2
+ require "net/http"
3
+ require "uri"
4
+ require "json"
5
+
6
+ def http_request(options={})
7
+ raise "Missing URI" if options[:uri].nil?
8
+ method = options[:method] || "get"
9
+ uri = URI.parse(options[:uri])
10
+ body = options[:body] || nil
11
+ http = Net::HTTP.new(uri.host, uri.port)
12
+ if options[:ssl] == true
13
+ http.use_ssl = true
14
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
15
+ end
16
+ request = case method
17
+ when "get"
18
+ Net::HTTP::Get.new(uri.request_uri)
19
+ when "post"
20
+ Net::HTTP::Post.new(uri.request_uri)
21
+ when "put"
22
+ Net::HTTP::Put.new(uri.request_uri)
23
+ when "delete"
24
+ Net::HTTP::Delete.new(uri.request_uri)
25
+ else
26
+ raise "Unknown HTTP method: #{method}"
27
+ end
28
+ request.body = body
29
+ http.request(request)
30
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), 'helpers')
2
+
3
+ module Redphone
4
+ class Pagerduty
5
+ def initialize(options={})
6
+ raise "You must supply a service key" if options[:service_key].nil?
7
+ @service_key = options[:service_key]
8
+ end
9
+
10
+ def integration_api(request_body)
11
+ response = http_request(
12
+ :method => "post",
13
+ :ssl => true,
14
+ :uri => "https://events.pagerduty.com/generic/2010-04-15/create_event.json",
15
+ :body => request_body.merge({:service_key => @service_key}).to_json
16
+ )
17
+ response.body
18
+ end
19
+
20
+ def trigger_incident(options={})
21
+ raise "You must supply a description" if options[:description].nil?
22
+ request_body = options.merge!({:event_type => "trigger"})
23
+ integration_api(request_body)
24
+ end
25
+
26
+ def resolve_incident(options={})
27
+ raise "You must supply a incident key" if options[:incident_key].nil?
28
+ request_body = options.merge!({:event_type => "resolve"})
29
+ integration_api(request_body)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Redphone
2
+ VERSION = "0.0.1"
3
+ end
data/redphone.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "redphone/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "redphone"
7
+ s.version = Redphone::VERSION
8
+ s.authors = ["Sean Porter"]
9
+ s.email = ["portertech@gmail.com"]
10
+ s.homepage = "https://github.com/portertech/redphone"
11
+ s.summary = %q{A rubygem for talking to monitoring service APIs}
12
+ s.description = %q{A rubygem for talking to monitoring service APIs}
13
+
14
+ s.rubyforge_project = "redphone"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "json"
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "minitest"
24
+ end
@@ -0,0 +1,27 @@
1
+ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
2
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
3
+ gem 'minitest'
4
+ require 'minitest/autorun'
5
+ require 'redphone/pagerduty'
6
+
7
+ SERVICE_KEY = File.open("pagerduty_service_key.txt", "rb").read.gsub("\n", "")
8
+
9
+ class TestRedphonePagerduty < MiniTest::Unit::TestCase
10
+ i_suck_and_my_tests_are_order_dependent!
11
+
12
+ def setup
13
+ @pagerduty = Redphone::Pagerduty.new(:service_key => SERVICE_KEY)
14
+ end
15
+
16
+ def test_trigger_incident
17
+ trigger = @pagerduty.trigger_incident(:description => "Testing Redphone Rubygem.", :incident_key => "redphone/test")
18
+ response = JSON.parse(trigger)
19
+ assert_equal 'success', response['status']
20
+ end
21
+
22
+ def test_resolve_incident
23
+ resolve = @pagerduty.resolve_incident(:incident_key => "redphone/test")
24
+ response = JSON.parse(resolve)
25
+ assert_equal 'success', response['status']
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redphone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Porter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70304409137140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70304409137140
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70304409136720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70304409136720
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70304409136220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70304409136220
47
+ description: A rubygem for talking to monitoring service APIs
48
+ email:
49
+ - portertech@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Rakefile
57
+ - lib/redphone.rb
58
+ - lib/redphone/helpers.rb
59
+ - lib/redphone/pagerduty.rb
60
+ - lib/redphone/version.rb
61
+ - redphone.gemspec
62
+ - test/pagerduty_test.rb
63
+ homepage: https://github.com/portertech/redphone
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project: redphone
83
+ rubygems_version: 1.8.10
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: A rubygem for talking to monitoring service APIs
87
+ test_files:
88
+ - test/pagerduty_test.rb