Skip to content

Commit

Permalink
updating src
Browse files Browse the repository at this point in the history
  • Loading branch information
ivikramsahu committed May 21, 2020
1 parent c301f8e commit 4d96442
Show file tree
Hide file tree
Showing 36 changed files with 3,483 additions and 0 deletions.
507 changes: 507 additions & 0 deletions src/main/java/com/pepipost/api/APIHelper.java

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions src/main/java/com/pepipost/api/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* PepipostLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/
package com.pepipost.api;

import java.util.HashMap;
import java.util.Map;

import com.pepipost.api.models.*;

public class Configuration {
//Your Pepipost API Key. You will find the api key in the Pepipost application in Integrations.
//TODO: Replace the apiKey with an appropriate value
public static String apiKey = "4D51B3ECA2D4ED3A67E4E043B3F1A4D1";

/**
* Current API environment
*/
public static Environments environment = Environments.PRODUCTION;

/**
* Get base URI by current environment
* @param server Server for which to get the base URI
* @return Processed base URI
*/
public static String getBaseUri(Servers server) {
StringBuilder baseUrl = new StringBuilder(environmentMapper(Configuration.environment, server));
Map<String, Object> parameters = new HashMap<String, Object>();
APIHelper.appendUrlWithTemplateParameters(baseUrl, parameters);
return baseUrl.toString();
}

/**
* Get base URI by current environment
* @return Processed base URI
*/
public static String getBaseUri() {
return Configuration.getBaseUri(Servers.SERVER1);
}

/**
* Base URLs by environments and server aliases
*/

private static String environmentMapper(Environments environments, Servers servers) {
String url = "";
if(environments.equals(Environments.PRODUCTION)) {
if(servers.equals(Servers.SERVER1))
url = "https://api.pepipost.com/v5/mail";
}
return url;
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/pepipost/api/Environments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* PepipostLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/
package com.pepipost.api;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

public enum Environments {
PRODUCTION; //TODO: Write general description for this element

private static TreeMap<String, Environments> valueMap = new TreeMap<String, Environments>();
private String value;

static {
PRODUCTION.value = "production";

valueMap.put("production", PRODUCTION);
}

/**
* Returns the enum member associated with the given string value
* @return The enum member against the given string value */
@com.fasterxml.jackson.annotation.JsonCreator
public static Environments fromString(String toConvert) {
return valueMap.get(toConvert);
}

/**
* Returns the string value associated with the enum member
* @return The string value against enum member */
@com.fasterxml.jackson.annotation.JsonValue
public String value() {
return value;
}

/**
* Get string representation of this enum
*/
@Override
public String toString() {
return value.toString();
}

/**
* Convert list of Environments values to list of string values
* @param toConvert The list of Environments values to convert
* @return List of representative string values */
public static List<String> toValue(List<Environments> toConvert) {
if(toConvert == null)
return null;
List<String> convertedValues = new ArrayList<String>();
for (Environments enumValue : toConvert) {
convertedValues.add(enumValue.value);
}
return convertedValues;
}
}
50 changes: 50 additions & 0 deletions src/main/java/com/pepipost/api/PepipostClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* PepipostLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/
package com.pepipost.api;

import com.pepipost.api.controllers.*;
import com.pepipost.api.http.client.HttpClient;

public class PepipostClient {
/**
* Singleton access to Send controller
* @return Returns the SendController instance
*/
public SendController getSend() {
return SendController.getInstance();
}

/**
* Get the shared http client currently being used for API calls
* @return The http client instance currently being used
*/
public HttpClient getSharedHttpClient() {
return BaseController.getClientInstance();
}

/**
* Set a shared http client to be used for API calls
* @param httpClient The http client to use
*/
public void setSharedHttpClient(HttpClient httpClient) {
BaseController.setClientInstance(httpClient);
}

/**
* Default constructor
*/
public PepipostClient() {
Configuration.apiKey = "4D51B3ECA2D4ED3A67E4E043B3F1A4D1";
}

/**
* Client initialization constructor
*/
public PepipostClient(String apiKey) {
this();
if(apiKey != null) Configuration.apiKey = apiKey;
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/pepipost/api/Servers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* PepipostLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/
package com.pepipost.api;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

public enum Servers {
SERVER1; //TODO: Write general description for this element

private static TreeMap<String, Servers> valueMap = new TreeMap<String, Servers>();
private String value;

static {
SERVER1.value = "server1";

valueMap.put("server1", SERVER1);
}

/**
* Returns the enum member associated with the given string value
* @return The enum member against the given string value */
@com.fasterxml.jackson.annotation.JsonCreator
public static Servers fromString(String toConvert) {
return valueMap.get(toConvert);
}

/**
* Returns the string value associated with the enum member
* @return The string value against enum member */
@com.fasterxml.jackson.annotation.JsonValue
public String value() {
return value;
}

/**
* Get string representation of this enum
*/
@Override
public String toString() {
return value.toString();
}

/**
* Convert list of Servers values to list of string values
* @param toConvert The list of Servers values to convert
* @return List of representative string values */
public static List<String> toValue(List<Servers> toConvert) {
if(toConvert == null)
return null;
List<String> convertedValues = new ArrayList<String>();
for (Servers enumValue : toConvert) {
convertedValues.add(enumValue.value);
}
return convertedValues;
}
}
92 changes: 92 additions & 0 deletions src/main/java/com/pepipost/api/controllers/BaseController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* PepipostLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/
package com.pepipost.api.controllers;


import com.pepipost.api.exceptions.*;
import com.pepipost.api.http.client.HttpClient;
import com.pepipost.api.http.client.HttpContext;
import com.pepipost.api.http.client.HttpCallBack;
import com.pepipost.api.http.client.OkClient;
import com.pepipost.api.http.response.HttpResponse;

public abstract class BaseController {
/**
* Private variable to keep shared reference of client instance
*/
private static HttpClient clientInstance = null;
private static final Object syncObject = new Object();
protected static final String userAgent = "APIMATIC 2.0";

/**
* Protected variable to keep reference of httpCallBack instance if user provides any
*/
protected HttpCallBack httpCallBack = null;

/**
* Get httpCallBack associated with this controller
* @return HttpCallBack
*/
public HttpCallBack getHttpCallBack() {
return httpCallBack;
}

/**
* Set the httpCallBack for this controller
* @param httpCallBack
*/
public void setHttpCallBack(HttpCallBack httpCallBack) {
this.httpCallBack = httpCallBack;
}

/**
* Shared instance of the Http client
* @return The shared instance of the http client
*/
public static HttpClient getClientInstance() {
if (null == clientInstance) {
synchronized (syncObject) {
if (null == clientInstance) {
clientInstance = OkClient.getSharedInstance();
}
}
}
return clientInstance;
}

/**
* Shared instance of the Http client
* @param client The shared instance of the http client
*/
public static void setClientInstance(HttpClient client) {
if (null != client) {
synchronized (syncObject) {
if (null != client) {
clientInstance = client;
}
}
}
}
/**
* Validates the response against HTTP errors defined at the API level
* @param _response The response recieved
* @param context Context of the request and the recieved response
*/
protected void validateResponse(HttpResponse _response, HttpContext context)
throws APIException {
//get response status code to validate
int responseCode = _response.getStatusCode();
if (responseCode == 400) {
throw new APIException("Bad request", context);
}

if ((responseCode < 200) || (responseCode > 208)) { //[200,208] = HTTP OK
if(!(responseCode == 401 || responseCode == 400 || responseCode == 403)) {
throw new APIException("HTTP Response Not OK", context);
}
}
}
}
Loading

0 comments on commit 4d96442

Please sign in to comment.