Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8 from lparry/master

Dump curb http library
  • Loading branch information...
commit 8ba3be06effb0b6f524c3547db814b38e4191e48 2 parents 457c6bd + 2be32d2
@lparry lparry authored
Showing with 33 additions and 30 deletions.
  1. +0 −2  Gemfile
  2. +1 −1  VERSION
  3. +31 −20 lib/pagerduty.rb
  4. +1 −7 pagerduty.gemspec
View
2  Gemfile
@@ -1,12 +1,10 @@
source "http://rubygems.org"
gem "json", "~> 1.4.6"
-gem "curb", "~> 0.7.8"
group :development do
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
gem "json", "~> 1.4.6"
- gem "curb", "~> 0.7.8"
end
View
2  VERSION
@@ -1 +1 @@
-1.2.0
+1.3.0
View
51 lib/pagerduty.rb
@@ -1,9 +1,9 @@
require 'json'
-require 'curb'
+require 'net/http'
class PagerdutyException < Exception
attr_reader :pagerduty_instance, :api_response
-
+
def initialize(instance, resp)
@pagerduty_instance = instance
@api_response = resp
@@ -11,57 +11,68 @@ def initialize(instance, resp)
end
class Pagerduty
-
+
attr_reader :service_key, :incident_key
-
+
def initialize(service_key, incident_key = nil)
@service_key = service_key
@incident_key = incident_key
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
-
+
def get_incident(incident_key)
PagerdutyIncident.new @service_key, 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
+
+ url = URI.parse("http://events.pagerduty.com/generic/2010-04-15/create_event.json")
+
+
+ http = Net::HTTP.new(url.host, url.port)
+
+ req = Net::HTTP::Post.new(url.request_uri)
+ req.body = JSON.generate(params)
+
+ res = http.request(req)
+ case res
+ when Net::HTTPSuccess, Net::HTTPRedirection
+ JSON.parse(res.body)
+ else
+ res.error!
+ end
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
8 pagerduty.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{pagerduty}
- s.version = "1.2.0"
+ s.version = "1.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["charliesome"]
@@ -38,26 +38,20 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<json>, ["~> 1.4.6"])
- s.add_runtime_dependency(%q<curb>, ["~> 0.7.8"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
s.add_development_dependency(%q<json>, ["~> 1.4.6"])
- s.add_development_dependency(%q<curb>, ["~> 0.7.8"])
else
s.add_dependency(%q<json>, ["~> 1.4.6"])
- s.add_dependency(%q<curb>, ["~> 0.7.8"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
s.add_dependency(%q<json>, ["~> 1.4.6"])
- s.add_dependency(%q<curb>, ["~> 0.7.8"])
end
else
s.add_dependency(%q<json>, ["~> 1.4.6"])
- s.add_dependency(%q<curb>, ["~> 0.7.8"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
s.add_dependency(%q<json>, ["~> 1.4.6"])
- s.add_dependency(%q<curb>, ["~> 0.7.8"])
end
end

1 comment on commit 8ba3be0

@jguice

Hey this is awesome because it should work in jruby now! Can someone publish a new version to rubygems.org please? :)

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