lib/raygun/client.rb in raygun4ruby-0.0.5 vs lib/raygun/client.rb in raygun4ruby-0.0.6

- old
+ new

@@ -5,15 +5,21 @@ include HTTParty base_uri "https://api.raygun.io/" def initialize + @api_key = require_api_key! + @headers = { - "X-ApiKey" => Raygun.configuration.api_key + "X-ApiKey" => @api_key } end + def require_api_key! + Raygun.configuration.api_key || raise(ApiKeyRequired.new("Please specify your Raygun API key using Raygun#setup (find yours at https://app.raygun.io)")) + end + def track_exception(exception_instance, env = {}) create_entry(build_payload_hash(exception_instance, env)) end private @@ -51,11 +57,11 @@ def version Raygun.configuration.version end def request_information(env) - return {} if env.blank? + return {} if env.nil? || env.empty? { hostName: env["SERVER_NAME"], url: env["PATH_INFO"], httpMethod: env["REQUEST_METHOD"], @@ -67,11 +73,11 @@ } end def headers(rack_env) rack_env.select do |k, v| - k.to_s.starts_with?("HTTP_") + k.to_s.start_with?("HTTP_") end end def form_data(rack_env) request = Rack::Request.new(rack_env) @@ -101,6 +107,6 @@ def create_entry(payload_hash) self.class.post("/entries", headers: @headers, body: JSON.generate(payload_hash)) end end -end \ No newline at end of file +end