Created
March 3, 2016 09:19
-
-
Save shrutis22/7d2b6af41a631d8c47b7 to your computer and use it in GitHub Desktop.
Class which makes API Calls to HipChat Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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