Skip to content

Instantly share code, notes, and snippets.

@shrutis22
Created March 3, 2016 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrutis22/7d2b6af41a631d8c47b7 to your computer and use it in GitHub Desktop.
Save shrutis22/7d2b6af41a631d8c47b7 to your computer and use it in GitHub Desktop.
Class which makes API Calls to HipChat Servers
/**
* This class exposes a method
* to send a message to Hip Chat in a
* specific Room named Hip Chat
* API Exploration.
*
* @author Shruti Sridharan
* @since 23/02/2016
* @version 1.0
*/
public class HipChatNotifier {
/**
* This method calls the
* HipChat Notification
* Endpoint and gets a
* response from the Servers.
*
* @param myMessage Accepts a custom message.
* @since 23/02/2016
* @version 1.0
*/
@future( callout = true )
public static void notify( String myMessage ) {
/**
* Getting endpoint from the Custom Settings.
*/
String endpoint = HipChat_API_Setting__c.getInstance( 'HipChat Notification Endpoint' ).Value__c;
/**
* Setting the body.
*/
String body = '{"color":"red","message":"' + myMessage + '","notify":true,"message_format":"text"}';
Http http = new Http();
HttpRequest httpReq = new HttpRequest();
HttpResponse httpRes = new HttpResponse();
/**
* Sending http request to display
* message in HipChat API
* Exploration Group
*/
httpReq.setBody( body );
httpReq.setMethod( 'POST' );
httpReq.setHeader( 'Content-Type', 'application/json' );
httpReq.setEndpoint( endpoint );
httpRes = http.send( httpReq );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment