Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
Add CardReader example to hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
Skiggz committed Apr 26, 2016
1 parent 086977c commit 6ea0176
Showing 1 changed file with 42 additions and 0 deletions.
Expand Up @@ -2,7 +2,9 @@

import com.fullcontact.api.libs.fullcontact4j.FullContact;
import com.fullcontact.api.libs.fullcontact4j.FullContactException;
import com.fullcontact.api.libs.fullcontact4j.enums.CardReaderQuality;
import com.fullcontact.api.libs.fullcontact4j.enums.Casing;
import com.fullcontact.api.libs.fullcontact4j.http.FCResponse;
import com.fullcontact.api.libs.fullcontact4j.http.location.LocationEnrichmentRequest;
import com.fullcontact.api.libs.fullcontact4j.http.location.LocationEnrichmentResponse;
import com.fullcontact.api.libs.fullcontact4j.http.name.NameDeduceRequest;
Expand All @@ -11,6 +13,10 @@
import com.fullcontact.api.libs.fullcontact4j.http.person.PersonResponse;
import com.fullcontact.api.libs.fullcontact4j.http.person.model.SocialProfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
* An example of how to use the FullContact client.
* Here, lets take a business email (like, john.smith@business.com)
Expand All @@ -36,10 +42,46 @@ public static void main(String[] args) {
String potentialLocation = lookupTwitterAndLocation(email);
lookupPopulation(potentialLocation);

// Make a CardReader request (example)
sendImageForTranscription(client);

// ALWAYS shutdown your client after you use it, or you could have a small memory leak.
client.shutdown();
}

/*
* Makes a call to CardReader API to transcribe an image from an image file
*
* See CardReader API Docs for more information
* https://www.fullcontact.com/developer/docs/card-reader/
* */
private static void sendImageForTranscription(FullContact client) {
try {
FCResponse response = client.sendRequest(
// All requests require a front image input stream. This example uses a file for simplicity
client.buildUploadCardRequest(new FileInputStream(new File("/path/to/images/front-side.jpg")))
// Back image is optional, if none is set simply remove this line
.cardBack(new FileInputStream(new File("/path/to/images/optional-back-side.jpg")))
// This helps prevent duplicate uploads, but is completely optional (see docs for more info)
.urid("unique-request-id-from-client")
// Required Endpoint on YOUR webserver accepting POST json entities (see docs for more info)
.webhookUrl("https://my-application.com/cardReaderWebhook")
// The expected quality of the transcritpions. Medium is the most popular and provides good accuracy
.verified(CardReaderQuality.MEDIUM)
.build()
);
// Print out the response to stdout
System.out.println(response);
} catch (FullContactException e) {
// Uh oh, something went wrong with FullContact HTTP
e.printStackTrace();
} catch (FileNotFoundException e) {
// The file you wanted to update was not found
// Keep in mind, you can use _any_ input stream for the file as long as you are transferring the photo bytes
e.printStackTrace();
}
}

/**
* Given an email, let's use FullContact to get a full name
* (This only works with emails with the name inside, like john.smith@business.com)
Expand Down

2 comments on commit 6ea0176

@Skiggz
Copy link
Contributor Author

@Skiggz Skiggz commented on 6ea0176 Apr 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ParisMi @McManCSU I added this example as some users wanted a bootstrap for using card reader with fullcontact4j. Purely here for example purposes and will fail because of the file paths used for examples but will not prevent the application from running.

Feel free to add anything / update anything.

@mattdelliott
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.