rubyhipchat

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 HipChat::Client 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.


Solution

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

    Have a look at user.rb#L57 which uses https://www.hipchat.com/docs/apiv2/method/view_user, 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).