Repository navigation
Expand file tree
/
Copy pathLeadSquaredAPIManager.java
More file actions
78 lines (63 loc) · 2.76 KB
/
Copy pathLeadSquaredAPIManager.java
File metadata and controls
78 lines (63 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import org.json.simple.*;
import org.json.simple.parser.*;
import java.io.*;
import java.net.*;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.*;
public class LeadSquaredAPIManager {
public static final String LSQ_BASE_URL = "https://api.leadsquared.com/v2/";
public static final String LSQ_CREATE_LEAD_URL = "LeadManagement.svc/Lead.Create";
private String accessKey;
private String secretKey;
public LeadSquaredAPIManager (String accessKey, String secretKey) {
this.accessKey = accessKey;
this.secretKey = secretKey;
}
public String addLead(String leadJSONString) throws Exception {
try {
String url = LSQ_BASE_URL + LSQ_CREATE_LEAD_URL + "?accessKey=" + this.accessKey + "&secretKey=" + this.secretKey;
return postData (url, leadJSONString);
} catch (Exception e){
throw e;
}
}
public String postData(String url, String leadJsonString) throws Exception {
try {
URL lsqURL = new URL (url);
HttpURLConnection connection = (HttpURLConnection) lsqURL.openConnection();
connection.setRequestMethod("POST");
connection.addRequestProperty ("Content-Type", "application/json");
connection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(leadJsonString);
wr.flush();
InputStream in = connection.getInputStream();
BufferedReader res = new BufferedReader(new InputStreamReader(in, "UTF-8"));
StringBuffer sBuffer = new StringBuffer();
String inputLine;
while ((inputLine = res.readLine()) != null)
sBuffer.append(inputLine);
res.close();
return sBuffer.toString();
}catch(Exception ex){
throw ex;
}
}
public static void main(String[] args)
{
try {
LeadSquaredJSONHelper leadJSON = new LeadSquaredJSONHelper();
leadJSON.addLeadAttribute("EmailAddress", "kaushik.kishore@marketxpander.com");
leadJSON.addLeadAttribute ("FirstName", "Kaushik");
leadJSON.addLeadAttribute ("LastName", "Kishore");
String jsonData = leadJSON.getJSONString();
// adding a lead
String accessKey = "<your access key here>";
String secretKey = "<your secret key here>";
LeadSquaredAPIManager lead = new LeadSquaredAPIManager(accessKey, secretKey);
lead.addLead(jsonData);
} catch (Exception ex) {
}
}
}