Skip to content
Browse files

Merge pull request #86 from kplawver/kplawver-generic_json_uri

Adds the Generic JSON URI plugin.
  • Loading branch information...
2 parents 0e8b897 + 1b22d23 commit 931b6d669013d66c4f84503f2d7666db11b0e18d @andre andre committed
Showing with 31 additions and 0 deletions.
  1. +31 −0 generic_json_uri/generic_json_uri.rb
View
31 generic_json_uri/generic_json_uri.rb
@@ -0,0 +1,31 @@
+class GenericJsonUri < Scout::Plugin
+ needs 'json', 'open-uri'
+ require 'json'
+ require 'open-uri'
+
+ OPTIONS=<<-EOS
+ url:
+ name: URL
+ notes: Full URL to the JSON end point you want to query. Could be a path on the server.
+ username:
+ notes: Username for basic http auth.
+ password:
+ notes: Password for the username.
+ EOS
+
+ def build_report
+ if option(:username) && option(:password)
+ response = nil
+ open option(:url), :http_basic_authentication => [option(:username), option(:password)] do |io|
+ response = io.read
+ end
+ else
+ response = open(option(:url)).read
+ end
+ obj = JSON.parse(response)
+ report(obj)
+ rescue Exception => e
+ return error("Error getting JSON", e.message)
+ end
+
+end

0 comments on commit 931b6d6

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