This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from fullcontact/email-verification
Email verification
- Loading branch information
Showing
12 changed files
with
431 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
...ava/com/fullcontact/api/libs/fullcontact4j/http/email/EmailVerificationAsyncResponse.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.fullcontact.api.libs.fullcontact4j.http.email; | ||
|
||
import com.fasterxml.jackson.core.JsonParseException; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fullcontact.api.libs.fullcontact4j.FullContactException; | ||
import com.fullcontact.api.libs.fullcontact4j.http.FCResponse; | ||
|
||
import java.io.IOException; | ||
|
||
public class EmailVerificationAsyncResponse extends FCResponse { | ||
private static ObjectMapper mapper = new ObjectMapper(); | ||
|
||
private String batchId; | ||
private String webhookUrl; | ||
private boolean completed; | ||
private EmailVerificationResponse response; | ||
|
||
public String getBatchId() { | ||
return batchId; | ||
} | ||
|
||
public String getWebhookUrl() { | ||
return webhookUrl; | ||
} | ||
|
||
public boolean isCompleted() { | ||
return completed; | ||
} | ||
|
||
public EmailVerificationResponse getResponse() { | ||
return response; | ||
} | ||
|
||
/** | ||
* Factory method to create a webhook response from json. | ||
* @throws com.fullcontact.api.libs.fullcontact4j.FullContactException if there is a parsing/mapping error. | ||
*/ | ||
public static EmailVerificationAsyncResponse fromJson(String json) throws FullContactException { | ||
//Properties not present in the POJO are ignored instead of throwing exceptions | ||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
//An empty string ("") is interpreted as null | ||
mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); | ||
try { | ||
return mapper.readValue(json, EmailVerificationAsyncResponse.class); | ||
} catch(JsonMappingException e) { | ||
throw new FullContactException("Failed to convert person json to a response", e); | ||
} catch(JsonParseException e) { | ||
throw new FullContactException("Json is not valid format", e); | ||
} catch(IOException e) { | ||
throw new FullContactException("Unexpected exception when parsing json", e); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...java/com/fullcontact/api/libs/fullcontact4j/http/email/EmailVerificationBatchRequest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.fullcontact.api.libs.fullcontact4j.http.email; | ||
|
||
import com.fullcontact.api.libs.fullcontact4j.FullContactApi; | ||
import com.fullcontact.api.libs.fullcontact4j.http.FCRequest; | ||
import retrofit.Callback; | ||
|
||
import java.util.*; | ||
|
||
public class EmailVerificationBatchRequest extends FCRequest<EmailVerificationAsyncResponse> { | ||
|
||
private Body body; | ||
|
||
protected EmailVerificationBatchRequest(Body body) { | ||
super(new HashMap<String, String>()); | ||
this.body = body; | ||
} | ||
|
||
protected void makeRequest(FullContactApi api, Callback<EmailVerificationAsyncResponse> callback) { | ||
api.submitEmailVerificationBatch(body, callback); | ||
} | ||
|
||
public static class Body { | ||
private List<String> emails; | ||
private String webhookUrl; | ||
|
||
public Body(List<String> emails, String webhookUrl) { | ||
this.emails = emails; | ||
this.webhookUrl = webhookUrl; | ||
} | ||
|
||
public List<String> getEmails() { | ||
return emails; | ||
} | ||
|
||
public String getWebhookUrl() { | ||
return webhookUrl; | ||
} | ||
} | ||
|
||
public static class Builder extends FCRequest.BaseBuilder<Builder, EmailVerificationBatchRequest> { | ||
private List<String> emails; | ||
private String webhookUrl; | ||
|
||
protected EmailVerificationBatchRequest createInstance() { | ||
return new EmailVerificationBatchRequest(new Body(emails, webhookUrl)); | ||
} | ||
|
||
public Builder emails(List<String> emails) { | ||
this.emails = emails; | ||
return this; | ||
} | ||
|
||
public Builder webhookUrl(String webhookUrl) { | ||
this.webhookUrl = webhookUrl; | ||
return this; | ||
} | ||
|
||
protected void validate() { | ||
if(emails == null || emails.size() == 0) { | ||
throw new IllegalArgumentException("request must include emails"); | ||
} | ||
} | ||
|
||
protected Builder self() { | ||
return this; | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
src/main/java/com/fullcontact/api/libs/fullcontact4j/http/email/EmailVerificationData.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.fullcontact.api.libs.fullcontact4j.http.email; | ||
|
||
public class EmailVerificationData { | ||
private String message; | ||
private String address; | ||
private String username; | ||
private String domain; | ||
private boolean corrected; | ||
private EmailVerificationAttributes attributes; | ||
private Boolean cached; | ||
private String person; | ||
private String company; | ||
private boolean sendSafely; | ||
|
||
private EmailVerificationData() { | ||
attributes = new EmailVerificationAttributes(); | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getDomain() { | ||
return domain; | ||
} | ||
|
||
public boolean isCorrected() { | ||
return corrected; | ||
} | ||
|
||
public EmailVerificationAttributes getAttributes() { | ||
return attributes; | ||
} | ||
|
||
public Boolean getCached() { | ||
return cached; | ||
} | ||
|
||
public String getPerson() { | ||
return person; | ||
} | ||
|
||
public String getCompany() { | ||
return company; | ||
} | ||
|
||
public boolean isSendSafely() { | ||
return sendSafely; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("EmailVerificationData{"); | ||
sb.append("message='").append(message).append('\''); | ||
sb.append(", address='").append(address).append('\''); | ||
sb.append(", username='").append(username).append('\''); | ||
sb.append(", domain='").append(domain).append('\''); | ||
sb.append(", corrected=").append(corrected); | ||
sb.append(", attributes=").append(attributes); | ||
sb.append(", cached=").append(cached); | ||
sb.append(", person='").append(person).append('\''); | ||
sb.append(", company='").append(company).append('\''); | ||
sb.append(", sendSafely=").append(sendSafely); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
|
||
public static class EmailVerificationAttributes { | ||
private boolean validSyntax; | ||
private boolean deliverable; | ||
private boolean catchall; | ||
private boolean risky; | ||
private boolean disposable; | ||
|
||
private EmailVerificationAttributes() {} | ||
|
||
public boolean isValidSyntax() { | ||
return validSyntax; | ||
} | ||
|
||
public boolean isDeliverable() { | ||
return deliverable; | ||
} | ||
|
||
public boolean isCatchall() { | ||
return catchall; | ||
} | ||
|
||
public boolean isRisky() { | ||
return risky; | ||
} | ||
|
||
public boolean isDisposable() { | ||
return disposable; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("EmailVerificationAttributes{"); | ||
sb.append("validSyntax=").append(validSyntax); | ||
sb.append(", deliverable=").append(deliverable); | ||
sb.append(", catchall=").append(catchall); | ||
sb.append(", risky=").append(risky); | ||
sb.append(", disposable=").append(disposable); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...a/com/fullcontact/api/libs/fullcontact4j/http/email/EmailVerificationGetBatchRequest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.fullcontact.api.libs.fullcontact4j.http.email; | ||
|
||
import com.fullcontact.api.libs.fullcontact4j.FullContactApi; | ||
import com.fullcontact.api.libs.fullcontact4j.http.FCRequest; | ||
import retrofit.Callback; | ||
|
||
import java.util.HashMap; | ||
|
||
public class EmailVerificationGetBatchRequest extends FCRequest<EmailVerificationAsyncResponse> { | ||
private String batchId; | ||
|
||
protected EmailVerificationGetBatchRequest(String batchId) { | ||
super(new HashMap<String, String>()); | ||
this.batchId = batchId; | ||
} | ||
|
||
protected void makeRequest(FullContactApi api, Callback<EmailVerificationAsyncResponse> callback) { | ||
api.getEmailVerificationBatch(batchId, callback); | ||
} | ||
|
||
public static class Builder extends BaseBuilder<Builder, EmailVerificationGetBatchRequest> { | ||
private String batchId; | ||
|
||
public Builder batchId(String batchId) { | ||
this.batchId = batchId; | ||
return this; | ||
} | ||
|
||
protected EmailVerificationGetBatchRequest createInstance() { | ||
return new EmailVerificationGetBatchRequest(batchId); | ||
} | ||
|
||
protected void validate() { | ||
if(batchId == null) { | ||
throw new IllegalArgumentException("batchId is required"); | ||
} | ||
} | ||
|
||
protected Builder self() { | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.