Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix package name and add static String for Content-Type #148

Closed
wants to merge 11 commits into from
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
language: java
sudo: false
sudo: required
jdk:
- oraclejdk8
- oraclejdk7
- openjdk7
- oraclejdk8
- oraclejdk7
- openjdk7
before_script:
- mkdir prism/bin
- export PATH=$PATH:$PWD/prism/bin/
- ./prism/prism.sh
- nohup prism run -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json &
after_script:
- "./gradlew build"
- "./scripts/upload.sh"
- "./gradlew build"
- "./scripts/upload.sh"
env:
global:
- S3_POLICY: ewogICJleHBpcmF0aW9uIjogIjIxMDAtMDEtMDFUMTI6MDA6MDAuMDAwWiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImFjbCI6ICJwdWJsaWMtcmVhZCIgfSwKICAgIHsiYnVja2V0IjogInNlbmRncmlkLW9wZW4tc291cmNlIiB9LAogICAgWyJzdGFydHMtd2l0aCIsICIka2V5IiwgInNlbmRncmlkLWphdmEvIl0sCiAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMjA0OCwgMjY4NDM1NDU2XSwKICAgIFsiZXEiLCAiJENvbnRlbnQtVHlwZSIsICJhcHBsaWNhdGlvbi96aXAiXQogIF0KfQo=
Expand Down
42 changes: 42 additions & 0 deletions prism/prism.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

install () {

set -eu

UNAME=$(uname)
ARCH=$(uname -m)
if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] && [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "i686" ]; then
echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/prism/releases"
exit 1
fi

if [ "$UNAME" = "Darwin" ] ; then
OSX_ARCH=$(uname -m)
if [ "${OSX_ARCH}" = "x86_64" ] ; then
PLATFORM="darwin_amd64"
fi
elif [ "$UNAME" = "Linux" ] ; then
LINUX_ARCH=$(uname -m)
if [ "${LINUX_ARCH}" = "i686" ] ; then
PLATFORM="linux_386"
elif [ "${LINUX_ARCH}" = "x86_64" ] ; then
PLATFORM="linux_amd64"
fi
fi

#LATEST=$(curl -s https://api.github.com/repos/stoplightio/prism/tags | grep -Eo '"name":.*?[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2)
LATEST="v0.1.5"
URL="https://github.com/stoplightio/prism/releases/download/$LATEST/prism_$PLATFORM"
DEST=./prism/bin/prism

if [ -z $LATEST ] ; then
echo "Error requesting. Download binary from ${URL}"
exit 1
else
curl -L $URL -o $DEST
chmod +x $DEST
fi
}

install
6 changes: 2 additions & 4 deletions src/main/java/com/sendgrid/SendGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class SendGrid {
private static final String VERSION = "3.0.0";
private static final String USER_AGENT = "sendgrid/" + VERSION + ";java";

private String apiKey;
private String host;
private String version;
private Client client;
Expand Down Expand Up @@ -44,17 +43,16 @@ public SendGrid(String apiKey, Client client) {
}

public void initializeSendGrid(String apiKey) {
this.apiKey = apiKey;
this.host = "api.sendgrid.com";
this.version = "v3";
this.requestHeaders = new HashMap<String, String>();
this.requestHeaders = new HashMap<>();
this.requestHeaders.put("Authorization", "Bearer " + apiKey);
this.requestHeaders.put("User-agent", USER_AGENT);
this.requestHeaders.put("Accept", "application/json");
}

public String getLibraryVersion() {
return this.VERSION;
return VERSION;
}

public String getVersion() {
Expand Down
61 changes: 27 additions & 34 deletions src/main/java/com/sendgrid/helpers/mail/Mail.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.sendgrid;
package com.sendgrid.helpers.mail;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.sendgrid.helpers.mail.objects.*;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -23,32 +18,30 @@
*/
@JsonInclude(Include.NON_DEFAULT)
public class Mail {
@JsonProperty("from") public Email from;
@JsonProperty("subject") public String subject;
@JsonProperty("personalizations") public List<Personalization> personalization;
@JsonProperty("content") public List<Content> content;
@JsonProperty("attachments") public List<Attachments> attachments;
@JsonProperty("template_id") public String templateId;
@JsonProperty("sections") public Map<String,String> sections;
@JsonProperty("headers") public Map<String,String> headers;
@JsonProperty("categories") public List<String> categories;
@JsonProperty("custom_args") public Map<String,String> customArgs;
@JsonProperty("send_at") public long sendAt;
@JsonProperty("batch_id") public String batchId;
@JsonProperty("asm") public ASM asm;
@JsonProperty("ip_pool_name") public String ipPoolId;
@JsonProperty("mail_settings") public MailSettings mailSettings;
@JsonProperty("tracking_settings") public TrackingSettings trackingSettings;
@JsonProperty("reply_to") public Email replyTo;
@JsonProperty("from") private Email from;
@JsonProperty("subject") private String subject;
@JsonProperty("personalizations") private List<Personalization> personalization;
@JsonProperty("content") private List<Content> content;
@JsonProperty("attachments") private List<Attachments> attachments;
@JsonProperty("template_id") private String templateId;
@JsonProperty("sections") private Map<String,String> sections;
@JsonProperty("headers") private Map<String,String> headers;
@JsonProperty("categories") private List<String> categories;
@JsonProperty("custom_args") private Map<String,String> customArgs;
@JsonProperty("send_at") private long sendAt;
@JsonProperty("batch_id") private String batchId;
@JsonProperty("asm") private ASM asm;
@JsonProperty("ip_pool_name") private String ipPoolId;
@JsonProperty("mail_settings") private MailSettings mailSettings;
@JsonProperty("tracking_settings") private TrackingSettings trackingSettings;
@JsonProperty("reply_to") private Email replyTo;

private static final ObjectMapper SORTED_MAPPER = new ObjectMapper();
static {
SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
}

public Mail() {
return;
}
public Mail() {}

public Mail(Email from, String subject, Email to, Content content)
{
Expand Down Expand Up @@ -94,7 +87,7 @@ public List<Personalization> getPersonalization() {

public void addPersonalization(Personalization personalization) {
if (this.personalization == null) {
this.personalization = new ArrayList<Personalization>();
this.personalization = new ArrayList<>();
this.personalization.add(personalization);
} else {
this.personalization.add(personalization);
Expand All @@ -111,7 +104,7 @@ public void addContent(Content content) {
newContent.setType(content.getType());
newContent.setValue(content.getValue());
if (this.content == null) {
this.content = new ArrayList<Content>();
this.content = new ArrayList<>();
this.content.add(newContent);
} else {
this.content.add(newContent);
Expand All @@ -131,7 +124,7 @@ public void addAttachments(Attachments attachments) {
newAttachment.setDisposition(attachments.getDisposition());
newAttachment.setContentId(attachments.getContentId());
if (this.attachments == null) {
this.attachments = new ArrayList<Attachments>();
this.attachments = new ArrayList<>();
this.attachments.add(newAttachment);
} else {
this.attachments.add(newAttachment);
Expand All @@ -154,7 +147,7 @@ public Map<String,String> getSections() {

public void addSection(String key, String value) {
if (sections == null) {
sections = new HashMap<String,String>();
sections = new HashMap<>();
sections.put(key, value);
} else {
sections.put(key, value);
Expand All @@ -169,7 +162,7 @@ public Map<String,String> getHeaders() {

public void addHeader(String key, String value) {
if (headers == null) {
headers = new HashMap<String,String>();
headers = new HashMap<>();
headers.put(key, value);
} else {
headers.put(key, value);
Expand All @@ -183,7 +176,7 @@ public List<String> getCategories() {

public void addCategory(String category) {
if (categories == null) {
categories = new ArrayList<String>();
categories = new ArrayList<>();
categories.add(category);
} else {
categories.add(category);
Expand All @@ -197,7 +190,7 @@ public Map<String,String> getCustomArgs() {

public void addCustomArg(String key, String value) {
if (customArgs == null) {
customArgs = new HashMap<String,String>();
customArgs = new HashMap<>();
customArgs.put(key, value);
} else {
customArgs.put(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sendgrid/helpers/mail/objects/ASM.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/sendgrid/helpers/mail/objects/Content.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -9,9 +9,7 @@ public class Content {
@JsonProperty("type") private String type;
@JsonProperty("value") private String value;

public Content() {
return;
}
public Content() {}

public Content(String type, String value) {
this.setType(type);
Expand Down
92 changes: 92 additions & 0 deletions src/main/java/com/sendgrid/helpers/mail/objects/ContentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.sendgrid.helpers.mail.objects;

/**
* @author Marcos Barbero
*/
public class ContentType {

/**
* Public constant media type that includes all media ranges (i.e. "&#42;/&#42;").
*/
public static final String ALL = "*/*";

/**
* Public constant media type for {@code application/atom+xml}.
*/
public final static String APPLICATION_ATOM_XML = "application/atom+xml";

/**
* Public constant media type for {@code application/x-www-form-urlencoded}.
*/
public final static String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";

/**
* Public constant media type for {@code application/json}.
*/
public final static String APPLICATION_JSON = "application/json";

/**
* Public constant media type for {@code application/json;charset=UTF-8}.
*/
public final static String APPLICATION_JSON_UTF8 = APPLICATION_JSON + ";charset=UTF-8";

/**
* Public constant media type for {@code application/octet-stream}.
*/
public final static String APPLICATION_OCTET_STREAM = "application/octet-stream";

/**
* Public constant media type for {@code application/pdf}.
*/
public final static String APPLICATION_PDF = "application/pdf";

/**
* Public constant media type for {@code application/xhtml+xml}.
*/
public final static String APPLICATION_XHTML_XML = "application/xhtml+xml";

/**
* Public constant media type for {@code application/xml}.
*/
public final static String APPLICATION_XML = "application/xml";

/**
* Public constant media type for {@code image/gif}.
*/
public final static String IMAGE_GIF = "image/gif";

/**
* Public constant media type for {@code image/jpeg}.
*/
public final static String IMAGE_JPEG = "image/jpeg";

/**
* Public constant media type for {@code image/png}.
*/
public final static String IMAGE_PNG = "image/png";

/**
* Public constant media type for {@code multipart/form-data}.
*/
public final static String MULTIPART_FORM_DATA = "multipart/form-data";

/**
* Public constant media type for {@code text/html}.
*/
public final static String TEXT_HTML = "text/html";

/**
* Public constant media type for {@code text/markdown}.
*/
public final static String TEXT_MARKDOWN = "text/markdown";

/**
* Public constant media type for {@code text/plain}.
*/
public final static String TEXT_PLAIN = "text/plain";

/**
* Public constant media type for {@code text/xml}.
*/
public final static String TEXT_XML = "text/xml";
}
6 changes: 2 additions & 4 deletions src/main/java/com/sendgrid/helpers/mail/objects/Email.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -9,9 +9,7 @@ public class Email {
@JsonProperty("name") private String name;
@JsonProperty("email") private String email;

public Email() {
return;
}
public Email() {}

public Email(String email) {
this.setEmail(email);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sendgrid;
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand Down
Loading