Skip to content

Instantly share code, notes, and snippets.

@skylerto
Created January 18, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skylerto/cfb8a3823e94862ff3534d46b1064791 to your computer and use it in GitHub Desktop.
Save skylerto/cfb8a3823e94862ff3534d46b1064791 to your computer and use it in GitHub Desktop.
package com.inlet.delivery;
import java.io.InputStream;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.google.gson.Gson;
import com.inlet.cloud.delivery.EvernoteService;
import com.inlet.cloud.delivery.DropboxService;
import com.inlet.cloud.delivery.FluentService;
import com.inlet.cloud.delivery.OneDriveService;
import com.inlet.cloud.models.BrandLogo;
import com.inlet.cloud.models.EnvelopeCreatedLambdaEvent;
import com.inlet.cloud.models.ResponseClass;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig;
public class App implements RequestHandler<LambdaWrapper, ResponseClass>{
protected final static Logger log = LoggerFactory.getLogger( "EnvelopeService" );
public static void main( String[] args ){
// String json = "{\"channelConsumerId\": \"CC:2267442125\", \"channelId\":\"CP:0000000118\", \"brandId\":\"BB:0000000127\", \"envelopeId\": \"WelcomeNote\"}";
String json = "{ \"data\": {\"channelConsumerId\": \"CC:2267442125\", \"channelId\":\"CP:0000000118\", \"brandId\":\"BB:0000000127\", \"envelopeId\": \"EV:10000000569\"}}";
Gson gson = new Gson();
LambdaWrapper event = gson.fromJson( json, LambdaWrapper.class );
App app = new App();
app.handleRequest( event, null );
}
@Override
public ResponseClass handleRequest( LambdaWrapper wrapper, Context context ){
EnvelopeCreatedLambdaEvent envelopeEvent = (EnvelopeCreatedLambdaEvent) wrapper.getData();
//getIP();
ResponseClass response = null;
switch( envelopeEvent.getChannelId() ){
case "CP:0000000118" : // evernote
response = handleEvernote( envelopeEvent );
break;
case "CP:0000000115" : // onedrive
response = handleOneDrive( envelopeEvent );
break;
case "CP:0000000100" : // dropbox
response = handleDropbox( envelopeEvent );
break;
}
return response;
}
public ResponseClass handleDropbox( EnvelopeCreatedLambdaEvent envelopeEvent ){
FluentService fService = new FluentService();
DropboxService dpService = new DropboxService();
// TODO: Switch to this after AWS is whitelisted
// String accessToken = fService.getAccessTokenFromCCData( envelopeEvent );
String accessToken = "j80qPi5M6M8AAAAAAAABmgdUAYK5jTLbR-3Bm_0gH3ErVjdkYSoZqG0iUz14jEeb";
List<InputStream> documents = fService.getDocument( envelopeEvent );
String documentName = fService.getDocumentName( envelopeEvent );
for( InputStream document : documents ){ // Should always be 1 document, but just in case...
dpService.uploadFile( accessToken, fService.getBrandDisplayName( envelopeEvent.getChannelId(), envelopeEvent.getBrandId() ), documentName, document );
}
return new ResponseClass( "200", "Success!" );
}
public ResponseClass handleEvernote( EnvelopeCreatedLambdaEvent envelopeEvent ){
FluentService fService = new FluentService();
EvernoteService eService = new EvernoteService();
String accessToken = "S=s1:U=93404:E=160f078409a:C=15998c71120:P=81:A=m4y10621:V=2:H=f8faf75766ffcc1f31ff0d3ed78d741c";
List<InputStream> documents = fService.getDocument( envelopeEvent );
String documentName = fService.getDocumentName( envelopeEvent );
for( InputStream document : documents ){ // Should always be 1 document, but just in case...
String brandDisplayName = fService.getBrandDisplayName( envelopeEvent.getChannelId(), envelopeEvent.getBrandId() );
String brandUrl = fService.getBrandUrl( envelopeEvent.getChannelId(), envelopeEvent.getBrandId() );
BrandLogo brandLogo = fService.getBrandLogo( envelopeEvent.getChannelId(), envelopeEvent.getBrandId() );
eService.uploadNote( accessToken, brandDisplayName, brandUrl, envelopeEvent.getBrandId(), brandLogo, documentName, document );
}
return new ResponseClass( "200", "Success!" );
}
public ResponseClass handleOneDrive( EnvelopeCreatedLambdaEvent envelopeEvent ){
String accessToken = "EwAYA61DBAAUGCCXc8wU/zFu9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
String refreshToken = "MCYUETpuv!4pMKhli2w123QNhBLCHGNVZDF*n15rjRLOhzsGGwuAsJ5fNrW0Nde4L3aH9qWXLGvX7L*sIlysC7esQLrUBQMNKHODOPdF8C6E23gnE2OMTq3aDx4kf1UGQbmXERZPvP5F*5idWRftWQBDNFElMpW4GHYvBrl880FI66owSVj5S*cqKaRbaVavQg*Nt6U76mJzzGLDaLac3*qYSDSuVQ4JuRfh0cMmhWtWQl!CjexC0PoeRADCtcgsqTyLGYQ!l0ZvnHrPN8!y8AXswsHnZDbb!5On31KQn1IH0jdNczDlQzAJLfhaEFeUpmeejMCW61yYCVRbWo20caOHFlvOeKVk5NBGjogjsGCNU";
FluentService fService = new FluentService();
OneDriveService odService = new OneDriveService();
List<InputStream> documents = fService.getDocument( envelopeEvent );
String documentName = fService.getDocumentName( envelopeEvent );
for( InputStream document : documents ){ // Should always be 1 document, but just in case...
String brandDisplayName = fService.getBrandDisplayName( envelopeEvent.getChannelId(), envelopeEvent.getBrandId() );
odService.uploadFile( accessToken, refreshToken, brandDisplayName, documentName, document );
}
return new ResponseClass( "200", "Success!" );
}
public ResponseClass handleAmazonDrive( EnvelopeCreatedLambdaEvent envelopeEvent ){
return null;
}
public void getIP(){
String url = "http://ipecho.net/plain";
Client client = Client.create( new DefaultClientConfig() );
WebResource res = client.resource( url );
ClientResponse cr = res.get( ClientResponse.class );
System.err.println( cr.getEntity( String.class ) );
}
}
class LambdaWrapper{
private Object data;
private String partitionKey;
public Object getData(){
return data;
}
public void setData( Object data ){
this.data = data;
}
public String getPartitionKey(){
return partitionKey;
}
public void setPartitionKey( String partitionKey ){
this.partitionKey = partitionKey;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment