Skip to content
Browse files

first commit

  • Loading branch information...
1 parent 69d8894 commit aac419edb73231e4b7c5ee0c138860b6887e721c @charliesome charliesome committed
Showing with 108 additions and 111 deletions.
  1. +6 −41 .gitignore
  2. +0 −5 Gemfile
  3. +2 −2 LICENSE.txt
  4. +34 −0 README.md
  5. +0 −19 README.rdoc
  6. +3 −19 Rakefile
  7. +63 −0 lib/pagerduty.rb
  8. +0 −18 test/helper.rb
  9. +0 −7 test/test_pagerduty.rb
View
47 .gitignore
@@ -1,42 +1,7 @@
-# rcov generated
-coverage
-
-# rdoc generated
+*.lock
rdoc
-
-# yard generated
-doc
-.yardoc
-
-# bundler
-.bundle
-
-# jeweler generated
-pkg
-
-# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
-#
-# * Create a file at ~/.gitignore
-# * Include files you want ignored
-# * Run: git config --global core.excludesfile ~/.gitignore
-#
-# After doing this, these files will be ignored in all your git projects,
-# saving you from having to 'pollute' every project you touch with them
-#
-# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
-#
-# For MacOS:
-#
-#.DS_Store
-#
-# For TextMate
-#*.tmproj
-#tmtags
-#
-# For emacs:
-#*~
-#\#*
-#.\#*
-#
-# For vim:
-#*.swp
+*.log
+.DS_Store
+*.swp
+*.swo
+pkg
View
5 Gemfile
@@ -1,13 +1,8 @@
source "http://rubygems.org"
-# Add dependencies required to use your gem here.
-# Example:
-# gem "activesupport", ">= 2.3.5"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
- gem "rcov", ">= 0"
end
View
4 LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2010 charliesome
+Copyright (c) 2010 Envato & Charlie Somerville
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
34 README.md
@@ -0,0 +1,34 @@
+pagerduty
+=========
+
+Provides a simple interface for calling into the [Pagerduty](http://pagerduty.com) API.
+
+Installation
+------------
+
+Make sure you have installed the two gems that pagerduty depends on: `json` and `curb`. Then install pagerduty with this command:
+
+ gem install pagerduty
+
+Usage
+-----
+
+Pagerduty exposes three classes, `Pagerduty`, `PagerdutyIncident` and `PagerdutyException`. Instances of `PagerdutyIncident` are created and returned for every API call.
+
+`Pagerduty`'s constructor takes a single argument - your `service_key`. You can then use the method `trigger` to trigger a new incident with Pagerduty:
+
+ require 'pagerduty'
+ p = Pagerduty.new "your_pagerduty_service_key"
+ incident = p.trigger "Everything went down!"
+
+Incidents can be retriggered, acknowledged with the `PagerdutyIncident#acknowledge` method, and resolved with `PagerdutyIncident#resolve`.
+
+Additionally, all API methods (`trigger`, `acknowledge`, `resolve`) take an optional second parameter `details`, which should be a hash containing any extra information that should be recorded with Pagerduty.
+
+If the Pagerduty API does not return success, a `PagerdutyException` will be thrown which has the properties `pagerduty_instance` (the instance of either `Pagerduty` or `PagerdutyException` that caused the exception) and `api_response`, which is a hash representation of the JSON response from the Pagerduty API.
+
+Copyright
+---------
+
+Copyright (c) 2010 [Envato](http://envato.com) & [Charlie Somerville](http://charliesomerville.com). See LICENSE.txt for further details.
+
View
19 README.rdoc
@@ -1,19 +0,0 @@
-= pagerduty
-
-Description goes here.
-
-== Contributing to pagerduty
-
-* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
-* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
-* Fork the project
-* Start a feature/bugfix branch
-* Commit and push until you are happy with your contribution
-* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
-* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
-
-== Copyright
-
-Copyright (c) 2010 charliesome. See LICENSE.txt for
-further details.
-
View
22 Rakefile
@@ -13,10 +13,10 @@ require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "pagerduty"
- gem.homepage = "http://github.com/charliesome/pagerduty"
+ gem.homepage = "http://github.com/envato/pagerduty"
gem.license = "MIT"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
+ gem.summary = "Pagerduty API client library"
+ gem.description = "Provides a simple interface for calling into the Pagerduty API"
gem.email = "charlie@charliesomerville.com"
gem.authors = ["charliesome"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
@@ -26,22 +26,6 @@ Jeweler::Tasks.new do |gem|
end
Jeweler::RubygemsDotOrgTasks.new
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
-end
-
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
-end
-
-task :default => :test
-
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
View
63 lib/pagerduty.rb
@@ -0,0 +1,63 @@
+require 'json'
+require 'curb'
+
+class PagerdutyException < Exception
+ attr_reader :pagerduty_instance, :api_response
+
+ def initialize(instance, resp)
+ @pagerduty_instance = instance
+ @api_response = resp
+ end
+end
+
+class Pagerduty
+
+ attr_reader :service_key, :incident_key
+
+ def initialize(service_key)
+ @service_key = service_key
+ @incident_key = nil
+ end
+
+ def trigger(description, details = {})
+ resp = api_call("trigger", description, details = {})
+ throw PagerdutyException.new(self, resp) unless resp["status"] == "success"
+
+ PagerdutyIncident.new @service_key, resp["incident_key"]
+ end
+
+protected
+ def api_call(event_type, description, details = {})
+ params = { :event_type => event_type, :service_key => @service_key, :description => description, :details => details }
+ params.merge!({ :incident_key => @incident_key }) unless @incident_key == nil
+
+ curl = Curl::Easy.new
+ curl.url = "http://events.pagerduty.com/generic/2010-04-15/create_event.json"
+ curl.http_post JSON.generate(params)
+ JSON.parse curl.body_str
+ end
+
+end
+
+class PagerdutyIncident < Pagerduty
+
+ def initialize(service_key, incident_key)
+ super service_key
+ @incident_key = incident_key
+ end
+
+ def acknowledge(description, details = {})
+ resp = api_call("acknowledge", description, details = {})
+ throw PagerdutyException.new(self, resp) unless resp["status"] == "success"
+
+ self
+ end
+
+ def resolve(description, details = {})
+ resp = api_call("resolve", description, details = {})
+ throw PagerdutyException.new(self, resp) unless resp["status"] == "success"
+
+ self
+ end
+
+end
View
18 test/helper.rb
@@ -1,18 +0,0 @@
-require 'rubygems'
-require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
-require 'test/unit'
-require 'shoulda'
-
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'pagerduty'
-
-class Test::Unit::TestCase
-end
View
7 test/test_pagerduty.rb
@@ -1,7 +0,0 @@
-require 'helper'
-
-class TestPagerduty < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end

0 comments on commit aac419e

Please sign in to comment.
Something went wrong with that request. Please try again.