1. Using in site URL
--------------------
@RestResource(urlMapping='/ProcessBitlyAPIService/*')
Global with sharing class BitlyWebService {
@HttpPost
global static void AcuityWebService1123() {
string username = '**************'; //Bitly username
String password = '**************'; //Bitly password
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +EncodingUtil.base64encode(headerValue);
//String authorizationHeader = 'Basic'+base64encode(username + ":" + password);
//BitlyCalloutService.doGet12(authorizationHeader);
}
}
2. HTTP Call Out
----------------
public class BitlyCalloutService {
public static String getscheduleLink(String endPoint){
HttpRequest req = new HttpRequest();
req.setEndpoint(endPoint);
req.setMethod('GET');
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp=res.getBody();
string shortUrl;
JSONParser parser = JSON.createParser(resp);
Map <String, Object> root = (Map <String, Object>) JSON.deserializeUntyped(resp);
Map <String, Object> mapdata=(Map <String, Object> )root.get('data');
Object url=mapdata.get('url');
shortUrl=url.toString();
return shortUrl;
}
public static void caseinsert(string shortUrl){
case caselist = new case();
if (Schema.sObjectType.case.fields.OpenSMSPro__Schedule_link__c.isUpdateable()) {
caselist.OpenSMSPro__Schedule_link__c = shortUrl;
}
Update caselist;
}
public static String getRescheduleLink(Task taskObj){
HttpRequest req = new HttpRequest();
String longurl='https://app.acuityscheduling.com/schedule.php?action=appt&owner=18252599&id[]='+taskObj.OpenSMSPro__Reschedule_URL_Id__c+'&apptId='+taskObj.OpenSMSPro__Appointment_ID__c;
//Blob b=EncodingUtil.base64Decode(longurl);
String encodeurl=EncodingUtil.urlEncode(longurl, 'UTF-8');
String endPoint='https://api-ssl.bitly.com/v3/shorten?access_token=21c0957767b791442080cf2674fada89ddf60171&longurl=';
endPoint+=encodeurl;
endPoint+='&format=json';
req.setEndpoint(endPoint);
req.setMethod('GET');
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp=res.getBody();
string shortUrl1;
JSONParser parser = JSON.createParser(resp);
Map <String, Object> root = (Map <String, Object>) JSON.deserializeUntyped(resp);
Map <String, Object> mapdata=(Map <String, Object> )root.get('data');
Object url=mapdata.get('url');
shortUrl1=url.toString();
return shortUrl1;
}
public static void taskinsert(string shortUrl1){
task tasklist = new task();
if (Schema.sObjectType.task.fields.OpenSMSPro__Reschedule_Link__c.isUpdateable()) {
tasklist.OpenSMSPro__Reschedule_Link__c = shortUrl1;
}
Update tasklist;
}
}
No comments:
Post a Comment