diff --git a/lib/stathat.rb b/lib/stathat.rb index 711fb32..68041d6 100644 --- a/lib/stathat.rb +++ b/lib/stathat.rb @@ -22,8 +22,8 @@ def send_to_stathat(url, args) uri.query = args.map { |arg, val| arg.to_s + "=" + CGI::escape(val.to_s) }.join('&') end - resp = Net::HTTP.get(uri) - return Response.new(resp) + resp = Net::HTTP.get_response(uri) + return Response.new(resp.body, resp.code.to_i) end end end @@ -173,18 +173,23 @@ def enqueue(url, args, cb=nil) end class Response - def initialize(body) + def initialize(body, http_status) @body = body + @http_status = http_status @parsed = nil end def valid? - return status == 200 + return (200..299).cover? status end def status - parse - return @parsed['status'] + if @body + parse + return @parsed['status'] + else + return @http_status + end end def msg diff --git a/test/test_stathat.rb b/test/test_stathat.rb index 76140d9..932e90d 100644 --- a/test/test_stathat.rb +++ b/test/test_stathat.rb @@ -42,15 +42,13 @@ def test_classic_value_bad_keys def test_ez_value_sync resp = StatHat::SyncAPI.ez_post_value("test ez value stat", "test@stathat.com", 0.92) assert(resp.valid?, "response was invalid") - assert_equal(resp.msg, "ok", "message should be 'ok'") - assert_equal(resp.status, 200, "status should be 200") + assert_equal(resp.status, 204, "status should be 200") end def test_ez_count_sync resp = StatHat::SyncAPI.ez_post_value("test ez count stat", "test@stathat.com", 12) assert(resp.valid?, "response was invalid") - assert_equal(resp.msg, "ok", "message should be 'ok'") - assert_equal(resp.status, 200, "status should be 200") + assert_equal(resp.status, 204, "status should be 200") end def test_classic_count_bad_keys_sync