Permalink
Browse files

Kick curb to the curb

Why use a shitty gem that requires installing development libraries to
compile against, when http requests are part of stdlib?
  • Loading branch information...
1 parent ba4bfd6 commit 2739c115a4866fd338729c1a0a3f471e479bd1a1 @lparry lparry committed Apr 10, 2012
Showing with 16 additions and 5 deletions.
  1. +16 −5 lib/pagerduty.rb
View
@@ -1,5 +1,5 @@
require 'json'
-require 'curb'
+require 'net/http'
class PagerdutyException < Exception
attr_reader :pagerduty_instance, :api_response
@@ -35,10 +35,21 @@ 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

0 comments on commit 2739c11

Please sign in to comment.