Skip to content

Commit

Permalink
enable deleting of urls
Browse files Browse the repository at this point in the history
  • Loading branch information
atmos committed Aug 15, 2010
1 parent f4e664b commit 3b9fb12
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 6 additions & 2 deletions bin/http-pulse
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ begin
response = api.create(options[:url])
puts "Successfully added #{options[:url]}"
when :delete
raise ArgumentError, "Unimplemented on the server"
if api.delete(options[:url])
puts "Successfully removed #{options[:url]}"
else
puts "Unable to locate #{options[:url]} for your user"
end
else
response = api.get
if response.any?
Expand All @@ -46,7 +50,7 @@ begin
puts "You have no monitors in place, create some!"
end
end
rescue Errno::ECONNREFUSED => e
rescue Errno::ECONNREFUSED, RestClient::RequestTimeout => e
puts "http-pulse seems to be down ATM :("
exit(1)
rescue RestClient::ResourceNotFound => e
Expand Down
17 changes: 15 additions & 2 deletions lib/http-pulse/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@ def create(url)
end

def delete(url)
response = RestClient.delete(endpoint, {:url => url}, {:content_type => :json, :accept => :json})
handle_response(response)
if object_id = id_for_url(url)
response = RestClient.delete("#{endpoint}/#{object_id}")
JSON.parse(response) == { }
else
false
end
end

private

def id_for_url(url)
monitors = get
monitors.each do |monitor|
return monitor['_id'] if monitor['url'] == url
end
nil
end

def handle_response(response)
raise RequestError, response.inspect unless (200...299).include?(response.code)
JSON.parse(response.to_s)
Expand Down

0 comments on commit 3b9fb12

Please sign in to comment.