Skip to content

Commit

Permalink
data cleanup refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Balbeko committed Sep 21, 2012
1 parent 509b793 commit ba08739
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/hipchat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ class HipChatClient
password: params.password
timezone: params.timezone ? 'UTC'

for k,v of data
delete data[k] unless params[k]?

options = @_prepareOptions
method: 'post'
path: '/v1/users/create'
data: data
data: @_cleanupData data, params


@_sendRequest options, callback
Expand All @@ -126,12 +124,10 @@ class HipChatClient
password: params.password
timezone: params.timezone ? 'UTC'



options = @_prepareOptions
method: 'post'
path: '/v1/users/update'
data: data
data: @_cleanupData data, params

@_sendRequest options, callback

Expand Down Expand Up @@ -176,6 +172,7 @@ class HipChatClient
if options.data? then req.write('' + options.data)
req.end()

# Removes all unused keys from array before making request
_cleanupData: (data, params) ->
for k,v of data
delete data[k] unless params[k]?
Expand Down

0 comments on commit ba08739

Please sign in to comment.