Using Pipl with Codenvy

Create a Pipl API application using our Factory button:


People Search API is the easiest way to get all the people data you need in your application from one single source.

The API allows you to query with the information you have about a person (such as name, address, age, email, phone or username) and get complete, structured profile based on everything we found on the web. Pipl index covers billions and billion of web pages from millions of websites both in the deep and the surface web, now all that information is available to you with a simple query to Pipl Search API.

Pipl uses powerful Identity Resolution engine, a combination of statistical analysis and other proprietry algorithms that allow them to determine whether each piece of data found is related to an individual or not then combine all those diseparate records into a single, structured and easy to use person profile that one can easily integrate into any application.

Register at Pipl

Upon registering , FREE DEMO KEY is provided for API calls, for a normal usage, this will be sufficient.

If one intends to just test Pipl API services , and doesn’t have API key yet, they can experiment with the Pipl API using the key: samplekey.

NOTE: samplekey has limits, so grab your own API key!

The Pipl API has different methods to integrate with Pipl ,each accepting different input parameters for information from the Pipl website. You can get more information about the API methods at http://dev.pipl.com/docs

To assist the integration with the different methods, the Pipl website has a IO Docs section at http://dev.pipl.com/io-docs which will give you the HTTP Request URL that will be required to invoke the method from your Codenvy application and the response that you would get. For example, if you want to invoke the Pipl API, you would do the following steps in your Pipl account under your registered application –

a) Navigating to this section will list all methods for the Pipl API:

Capture_15

b) Let us take the Search Information related method for integration. Now expand the Search Information related method. This will have the option to enter the email_field for which we will retrieve information ,response will be in the JSON format containing all the information about the email_address entered in it.

Capture_16

c) On clicking Try it, you will get the Request URL generated that will be used from your application in Codenvy and the request and response headers and response body in JSON format that you will capture in your Codenvy application:
Capture_17

Create a Project in Codenvy

Now, login to your Codenvy workspace and create a WAR project named as ‘piplAPI’. This will have the following structure :

Capture_9

 pom.xml File

To make use of the Pipl API through HttpClient as a servlet, please update the pom.xml to include the HttpClient and Java EE Web API jars and the servletapi jar into your project as Maven dependencies.

Capture_10

Create PiplSearchCallServlet Class

Now create a Java servlet class named ‘PiplSearchCallServlet.java’ that will talk to the Pipl website with the Http request URL that was generated above in the Pipl IO Docs section and then get a Http response back with the response header and the response body in the JSON format which will be then displayed on the browser through a JSP. All this is done inside the method doPost() in the sample source Java class.

package com.codenvy;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.IOException;

public class PiplSearchCallServlet extends HttpServlet{
private static final long serialVersionUID = 1L;

private HttpClient client = new DefaultHttpClient();
private final String USER_AGENT = "Mozilla/5.0";
private final String PIPL_API_URL = "http://api.pipl.com/search/v3/json/?";
private final String PIPL_API_KEY = "samplekey";
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
StringBuffer sb = null;
try {
String getEmail = request.getParameter("inputEmail");
//http://api.pipl.com/search/v3/json/?key=samplekey&email=steve@apple.com

String getURL = PIPL_API_URL+"key="+PIPL_API_KEY+"&email="+getEmail;

HttpGet req = new HttpGet(getURL);
// add request header
req.addHeader("User-Agent", USER_AGENT);
HttpResponse res = client.execute(req);
HttpEntity entity = res.getEntity();
BufferedReader rd = new BufferedReader(
new InputStreamReader(res.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}

if (entity != null) {
EntityUtils.consume(entity);
}

sb = new StringBuffer("<br/>Simple people search with Pipl API with email : "+ getURL +"<br/>");
sb.append("*** Request headers ***").append("<br/>");
Header[] requestHeaders = req.getAllHeaders();
for (Header header : requestHeaders) {
sb.append(header.toString()).append("<br/>");
}
sb.append("***********************").append("<br/>");

sb.append("*** Response headers ***").append("<br/>");
sb.append(res.getStatusLine()).append("<br/>");
Header[] headers = res.getAllHeaders();
for (Header header : headers) {
sb.append(header.toString()).append("<br/>");
}
sb.append("***********************").append("<br/>");

sb.append("*** Response ***").append("<br/>");
sb.append(result.toString());
} catch (Exception ex) {
sb = new StringBuffer(ex.toString());
}

request.setAttribute("data", sb.toString());
RequestDispatcher rd = request.getRequestDispatcher("/success.jsp");
rd.forward(request, response);
}
}

Create index.jsp File

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pipl Search API Tutorial- using httpclient</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div class="CodenvyDiv">
    <p id="head">People search by email through Pipl Search API </p>
    <form action="PiplSearchCallServlet" method="post">
      <table width="400" border="0" cellspacing="0" cellpadding="0"
        class="table">
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="144"><strong>email Address</strong></td>
          <td width="8">&nbsp;</td>
          <td width="203"><label> <input type="text" name="inputEmail" />
          </label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>(example : a@abc.com)</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><label> <input type="submit" name="GET" value="Pipl Search" class="button" />
          </label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
    </form>
  </div>
</body>
</html>

Create success.jsp File

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>People search by email through Pipl Search API </title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
  <div class="CodenvyDivFull">
  <p>Data : <br/><%=request.getAttribute("data") %></p>
  <br/>
  <p><a href="index.jsp">Try</a> another url</p>
  </div>
</body>
</html>

Your Codenvy project will have a success.jsp which will be invoked from the PiplSearchCallServlet.class to display the response on the browser

Create style.css file

body{font-family: 'Trebuchet MS';font-size: 12px;}
.CodenvyDivFull {margin:40px;padding:20px;border:2px solid #F0C36D; background-color:#F9EDBE;width:100%;}
.CodenvyDiv {margin:40px;padding:20px;border:2px solid #F0C36D; background-color:#F9EDBE;width:500px;}
.CodenvyDivFull #head {font-family: 'Trebuchet MS'; font-weight: bold; color: #E04B39; font-size: 18px; letter-spacing: 1px;}
.CodenvyDiv #head {font-family: 'Trebuchet MS'; font-weight: bold; color: #E04B39; font-size: 18px; letter-spacing: 1px;}
.button {font-family: 'Trebuchet MS'; font-weight: bold; padding: 2px 10px;}
tr {margin:2px;}

Create web.xml File

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>piplAPI Tutorial</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <display-name>PiplSearchCallServlet</display-name>
    <servlet-name>PiplSearchCallServlet</servlet-name>
    <servlet-class>com.codenvy.PiplSearchCallServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>PiplSearchCallServlet</servlet-name>
    <url-pattern>/PiplSearchCallServlet</url-pattern>
  </servlet-mapping>
</web-app>

Run Application

Now you build and run your Codenvy project you’ll be prompted to enter email_address.

Capture_7

When clicked on the button the Http response from the Pipl website with the information about email_address will be displayed in the browser:

Capture_8

You can use this JSON format response in a way that you would like to meet your needs for your custom application.

The Pipl API provides more methods that can be used in a similar way as above to retrieve information. More details would be available on their website – http://dev.pipl.com/io-docs