         .send options
         .set 'Accept', 'application/json'
         .end (res) ->
-            if res.ok
-                callback null, res.body
-            else
-                console.log "Error in activityCreate", options, res.body?.error
-                callback res.body, null
+            handleResponse res, callback, "activityCreate", options
 

        request.put "messages/batchFetch"
        .send target
        .end (res) ->
            if res.ok
                callback null, res.body
            else
                if res.body?.name?
                    res.error = res.body
                callback res.error

    batchAddFlag: (target, flag, callback) ->
        body = _.extend {flag}, target
        request.put "messages/batchAddFlag"
        .send body
        .end (res) ->
            if res.ok
                callback null, res.body
            else
                if res.body?.name?
                    res.error = res.body
                callback res.error

    batchRemoveFlag: (target, flag, callback) ->
        body = _.extend {flag}, target
        request.put "messages/batchRemoveFlag"
        .send body
        .end (res) ->
            if res.ok
                callback null, res.body
            else
                if res.body?.name?
                    res.error = res.body
                callback res.error

    batchDelete: (target, callback) ->
        body = _.extend {}, target
        request.put "messages/batchTrash"
        .send target
        .end (res) ->
            if res.ok
                callback null, res.body
            else
                if res.body?.name?
                    res.error = res.body
                callback res.error

    batchMove: (target, from, to, callback) ->
        body = _.extend {from, to}, target
        request.put "messages/batchMove"
        .send body
        .end (res) ->
            if res.ok
                callback null, res.body
            else
                if res.body?.name?
                    res.error = res.body
                callback res.error

    createAccount: (account, callback) ->

        # TODO: validation & sanitization

        request.post 'account'
        .send account
        .set 'Accept', 'application/json'
        .end (res) ->
            if res.ok
                callback null, res.body
            else
                console.log "Error in createAccount", account, res.body?.error
                callback res.body, null

    editAccount: (account, callback) ->


        .send account
        .set 'Accept', 'application/json'
        .end (res) ->
            handleResponse res, callback, "checkAccount"

    removeAccount: (accountID, callback) ->

        request.del "account/#{accountID}"
        .set 'Accept', 'application/json'
        .end (res) ->
            handleResponse res, callback, "removeAccount"

    accountDiscover: (domain, callback) ->

        request.get "provider/#{domain}"
        .set 'Accept', 'application/json'
        .end (res) ->
            handleResponse res, callback, "accountDiscover"

    search: (url, callback) ->
        request.get url
        .set 'Accept', 'application/json'
        .end (res) ->
            handleResponse res, callback, "search"

    refresh: (hard, callback) ->
        url = if hard then "refresh?all=true"
