Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/stathat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions test/test_stathat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down