Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5 from signaturelabs/ok_json

Replacing JSON dependency with Heroku::OkJson
  • Loading branch information...
commit 83d16b7b3c588dbb9c96771a91a3c085cf8b57bb 2 parents 5d90f08 + 75138d2
@shayfrendt authored
Showing with 19 additions and 25 deletions.
  1. +19 −25 init.rb
View
44 init.rb
@@ -1,9 +1,3 @@
-begin
- require 'json'
-rescue LoadError
- raise "json gem is missing. Please install json: gem install json"
-end
-
module Heroku::Command
class Ranger < BaseWithApp
def initialize(*args)
@@ -22,7 +16,7 @@ def initialize(*args)
def index
if get_status
dependencies = @current_status
-
+
puts "\nRanger Status"
puts "------------------------------------------"
@@ -31,7 +25,7 @@ def index
code = record["dependency"]["latest_response_code"]
puts "#{url} #{up_or_down(code)}"
end
-
+
watchers_list
else
no_domains_monitored
@@ -47,7 +41,7 @@ def domains
domain_list
return
end
-
+
case args.shift
when "add"
url = args.shift
@@ -172,9 +166,9 @@ def get_status
resource = authenticated_resource("/status/#{@ranger_app_id}?api_key=#{@ranger_api_key}")
begin
- @current_status = JSON.parse(resource.get)
+ @current_status = Heroku::OkJson.decode(resource.get)
true
- rescue RestClient::ResourceNotFound => e
+ rescue Heroku::OkJson::Error => e
false
end
end
@@ -189,7 +183,7 @@ def create_dependency(url)
params = { :dependency => { :name => "Website", :url => url, :check_every => "1" }, :api_key => @ranger_api_key}
resource.post(params)
end
-
+
def remove_url(url)
if delete_dependency_from_url(url)
puts "Removed #{url} from the monitoring list"
@@ -199,8 +193,8 @@ def remove_url(url)
end
def delete_dependency_from_url(url)
- dependencies = JSON.parse(get_dependencies)
-
+ dependencies = Heroku::OkJson.decode(get_dependencies)
+
dependency_id = nil
dependencies.each do |record|
if record["dependency"]["url"] == url
@@ -223,16 +217,16 @@ def delete_dependency(id)
end
def clear_all_dependencies
- dependencies = JSON.parse(get_dependencies)
-
+ dependencies = Heroku::OkJson.decode(get_dependencies)
+
dependencies.each do |record|
delete_dependency(record["dependency"]["id"])
end
end
-
+
def clear_all_watchers
watchers = get_watchers
-
+
watchers.each do |record|
delete_watcher(record["watcher"]["id"])
end
@@ -249,7 +243,7 @@ def no_domains_monitored
def domain_list
if get_status
dependencies = @current_status
-
+
puts "\nDomains Being Monitored"
puts "------------------------------------------"
@@ -266,12 +260,12 @@ def domain_list
def get_watchers
resource = authenticated_resource("/apps/#{@ranger_app_id}/watchers.json?api_key=#{@ranger_api_key}")
- @current_watchers = JSON.parse(resource.get)
+ @current_watchers = Heroku::OkJson.decode(resource.get)
end
def watchers_list
get_watchers
-
+
puts "\nApp Watchers"
puts "------------------------------------------"
@@ -281,13 +275,13 @@ def watchers_list
end
puts ""
end
-
+
def create_watcher(email)
resource = authenticated_resource("/apps/#{@ranger_app_id}/watchers.json")
params = { :watcher => { :email => email }, :api_key => @ranger_api_key}
resource.post(params)
end
-
+
def remove_watcher(email)
if delete_watcher_from_email(email)
puts "Removed #{email} as a watcher"
@@ -295,10 +289,10 @@ def remove_watcher(email)
puts "No watchers with that email found in the watcher list"
end
end
-
+
def delete_watcher_from_email(email)
watchers = get_watchers
-
+
watcher_id = nil
watchers.each do |record|
if record["watcher"]["email"] == email
Please sign in to comment.
Something went wrong with that request. Please try again.