Created
December 1, 2015 10:46
-
-
Save Miguel000/dc0b934ff2f62f74d492 to your computer and use it in GitHub Desktop.
FullContactPerson
This file contains hidden or 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
| /* | |
| The MIT License (MIT) | |
| Copyright (c) 2014 sinfonier-project | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in | |
| all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| THE SOFTWARE. | |
| */ | |
| package com.sinfonier.bolts; | |
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.TreeMap; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.net.URL; | |
| import java.net.URLEncoder; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| import org.codehaus.jackson.map.ObjectMapper; | |
| import org.codehaus.jackson.type.TypeReference; | |
| import org.jsoup.select.Elements; | |
| import org.jsoup.nodes.Document; | |
| import org.jsoup.Jsoup; | |
| import org.jsoup.nodes.Element; | |
| public class FullContactPerson extends BaseSinfonierBolt { | |
| private String ApiKey; | |
| private String email; | |
| public FullContactPerson (String xmlFile) { | |
| super(xmlFile); | |
| } | |
| @Override | |
| public void userprepare() { | |
| this.ApiKey = this.getParam("ApiKey"); | |
| this.email = this.getParam("email"); | |
| } | |
| @Override | |
| public void userexecute() { | |
| try{ | |
| String Mail = (String) this.getField(this.email); | |
| URL url = new URL("https://api.fullcontact.com/v2/person.json?email="+Mail+"&apiKey="+this.ApiKey); | |
| InputStream is = url.openStream(); | |
| int ptr = 0; | |
| StringBuilder builder = new StringBuilder(); | |
| while ((ptr = is.read()) != -1) { | |
| builder.append((char) ptr); | |
| } | |
| String jsonString = builder.toString(); | |
| ObjectMapper mapper = new ObjectMapper(); | |
| Map<String, Object> json = new HashMap<String, Object>(); | |
| json = mapper.readValue(jsonString,new TypeReference<Map<String, Object>>() {}); | |
| this.addField("FullContactPerson", json); | |
| } catch (Exception e) { | |
| this.addField("FullContactPerson-error",e.toString()); | |
| } | |
| // Por si acaso, que emita (puede que no haya links) | |
| this.emit(); | |
| } | |
| public void usercleanup() { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment