Alex Cohen Alex Cohen - 1 year ago 84
Ruby Question

Ruby HipChat Wrapper, how to check that a username is valid?

I am using the ruby HipChat Wrapper to send HipChat messages with a script. Before attempting to send any messages I would like to be able to check that the users I am attempting to message exist and are valid.

Is there a function in the

class that allows me to do this?

Note: I know that I can test if a user exists by attempting to send a message. If the script exits with a
Access denied to user
error then it is invalid. However I would like to test that a user exists without actually sending any messages.

Answer Source

I'm not familiar with that client, however looking at the library you should be able to do something like this client.user('').view (assuming API V2).

Have a look at user.rb#L57 which uses, that will probably give you back an error as well if the user does not exist (unsure). It's probably still better than sending the entire message before realising the user does not exist (alternatively you can also retrieve all users and check it against that).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download