Skip to content

Commit 6835c96

Browse files
BRIAN HOLYFIELDBRIAN HOLYFIELD
authored andcommitted
Initial commit for Java API v2
Initial commit for Java API v2
1 parent 48d24a1 commit 6835c96

File tree

107 files changed

+2684
-499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+2684
-499
lines changed
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11

22

3+
import java.text.DecimalFormat;
4+
import java.text.MessageFormat;
5+
36
import com.sendsafely.ProgressInterface;
47

58
public class ProgressCallback implements ProgressInterface {
69

710
@Override
8-
public void updateProgress(double progress) {
9-
System.out.println("Progress: " + progress);
11+
public void updateProgress(String fileId, double progress) {
12+
System.out.println(MessageFormat.format("{0,number,#.##%}", progress));
1013
}
1114

15+
@Override
16+
public void gotFileId(String fileId) {
17+
System.out.println("Got File Id: " + fileId);
18+
}
1219
}

SampleApplication/src/SendSafelyRefApp.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,17 @@
22

33
import java.io.IOException;
44

5-
import com.sendsafely.File;
6-
import com.sendsafely.Recipient;
7-
import com.sendsafely.SendSafely;
5+
import com.sendsafely.File.*;
86
import com.sendsafely.Package;
7+
import com.sendsafely.*;
98
import com.sendsafely.dto.PackageURL;
10-
import com.sendsafely.exceptions.ApproverRequiredException;
11-
import com.sendsafely.exceptions.CreatePackageFailedException;
12-
import com.sendsafely.exceptions.DownloadFileException;
13-
import com.sendsafely.exceptions.FinalizePackageFailedException;
14-
import com.sendsafely.exceptions.InvalidCredentialsException;
15-
import com.sendsafely.exceptions.LimitExceededException;
16-
import com.sendsafely.exceptions.PackageInformationFailedException;
17-
import com.sendsafely.exceptions.PasswordRequiredException;
18-
import com.sendsafely.exceptions.RecipientFailedException;
19-
import com.sendsafely.exceptions.SendFailedException;
20-
import com.sendsafely.exceptions.UploadFileException;
9+
import com.sendsafely.exceptions.*;
10+
import com.sendsafely.file.DefaultFileManager;
11+
import com.sendsafely.file.FileManager;
2112

2213
public class SendSafelyRefApp {
2314

24-
public static void main(String[] args) throws SendFailedException, IOException, InvalidCredentialsException, CreatePackageFailedException, LimitExceededException, FinalizePackageFailedException, UploadFileException, ApproverRequiredException, RecipientFailedException, PackageInformationFailedException, DownloadFileException, PasswordRequiredException
15+
public static void main(String[] args) throws SendFailedException, IOException, InvalidCredentialsException, CreatePackageFailedException, LimitExceededException, FinalizePackageFailedException, UploadFileException, ApproverRequiredException, RecipientFailedException
2516
{
2617
/*
2718
* This example will read in the following command line arguments:
@@ -35,7 +26,7 @@ public static void main(String[] args) throws SendFailedException, IOException,
3526
* UserApiSecret: The API Secret associated with the API Key used above. The API Secret is provided to
3627
* you when you generate a new API Key.
3728
*
38-
* FileToUpload: Local path to the file you want to upload. Can be any file up to 10GB in size.
29+
* FileToUpload: Local path to the file you want to upload. Can be any file up to 2GB in size.
3930
*
4031
* RecipientEmailAddress: The email address of the person you want to send the file to.
4132
*/
@@ -72,19 +63,14 @@ public static void main(String[] args) throws SendFailedException, IOException,
7263
System.out.println("Adding Recipient (Recipient ID#" + newRecipient.getRecipientId() + ")");
7364

7465
System.out.println("Uploading File");
75-
File addedFile = sendSafely.encryptAndUploadFile(packageId, pkgInfo.getKeyCode(), new java.io.File(fileToUpload), new ProgressCallback());
66+
FileManager uploadManager = new DefaultFileManager(new java.io.File(fileToUpload));
67+
File addedFile = sendSafely.encryptAndUploadFile(packageId, pkgInfo.getKeyCode(), uploadManager, new ProgressCallback());
7668
System.out.println("Upload Complete - File Id#" + addedFile.getFileId() + ". Finalizing Package.");
7769

7870
// Package is finished, call the finalize method to make the package available for pickup and print the URL for access.
7971
PackageURL packageLink = sendSafely.finalizePackage(packageId, pkgInfo.getKeyCode());
8072
System.out.println("Success: " + packageLink.getSecureLink());
8173

82-
// Download the file again.
83-
Package pkgToDownload = sendSafely.getPackageInformationFromLink(packageLink.getSecureLink());
84-
for(File file : pkgToDownload.getFiles()) {
85-
java.io.File downloadedFile = sendSafely.downloadFile(pkgToDownload.getPackageId(), file.getFileId(), pkgToDownload.getKeyCode(), new ProgressCallback());
86-
System.out.println("Downloaded File to path: " + downloadedFile.getAbsolutePath());
87-
}
8874
}
8975

9076
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.sendsafely;
2+
3+
import java.util.List;
4+
5+
import com.sendsafely.enums.PackageState;
6+
7+
/**
8+
* A Java Bean containing information about a package.
9+
* Only the Getters should be used from this object, since the server will populate the object.
10+
* Updating the setters will not change any state on the server and should be avoided.
11+
* @author Erik Larsson
12+
*
13+
*/
14+
public class BasePackage {
15+
16+
private String packageId;
17+
private String packageCode;
18+
private String serverSecret;
19+
private String keyCode;
20+
private List<File> files;
21+
private List<String> approverList;
22+
private boolean needsApproval;
23+
private PackageState state;
24+
private int life;
25+
26+
/**
27+
* @description The package ID used to identify a given package
28+
* @return The package ID
29+
*/
30+
public String getPackageId() {
31+
return packageId;
32+
}
33+
34+
/**
35+
* @description Set internally by the API.
36+
* @param packageId
37+
*/
38+
public void setPackageId(String packageId) {
39+
this.packageId = packageId;
40+
}
41+
42+
/**
43+
* @description Get the server secret. The server secret is unique to a package and is used as part of the encryption key.
44+
* @return The server secret
45+
*/
46+
public String getServerSecret() {
47+
return serverSecret;
48+
}
49+
50+
/**
51+
* @description Set internally by the API.
52+
* @param server secret
53+
*/
54+
public void setServerSecret(String serverSecret) {
55+
this.serverSecret = serverSecret;
56+
}
57+
58+
/**
59+
* @description The package code is used in the link, sent out to the recipients. It will uniquely identify a package.
60+
* @return the package code
61+
*/
62+
public String getPackageCode() {
63+
return packageCode;
64+
}
65+
66+
/**
67+
* @description Set internally by the API.
68+
* @param packageCode
69+
*/
70+
public void setPackageCode(String packageCode) {
71+
this.packageCode = packageCode;
72+
}
73+
74+
/**
75+
* @description The key code is generated by the Java API when a new package is created. It must be passed into the API when a new file is uploaded and when the package is finalized. The key code is unique for every package.
76+
* @return
77+
*/
78+
public String getKeyCode() {
79+
return this.keyCode;
80+
}
81+
82+
/**
83+
* @description Set internally by the API.
84+
* @param keyCode
85+
*/
86+
public void setKeyCode(String keyCode) {
87+
this.keyCode = keyCode;
88+
}
89+
90+
/**
91+
* @description Get all files that are currently associated with the package
92+
* @returnType File
93+
* @return
94+
*/
95+
public List<File> getFiles() {
96+
return files;
97+
}
98+
99+
/**
100+
* @description Set internally by the API.
101+
* @param files
102+
*/
103+
public void setFiles(List<File> files) {
104+
this.files = files;
105+
}
106+
107+
/**
108+
* @description Returns a list of all potential approvers for the package.
109+
* @return
110+
*/
111+
public List<String> getApproverList() {
112+
return approverList;
113+
}
114+
115+
/**
116+
* @description Set internally by the API.
117+
* @param approverList
118+
*/
119+
public void setApproverList(List<String> approverList) {
120+
this.approverList = approverList;
121+
}
122+
123+
/**
124+
* @description Returns true if the package needs approval, false otherwise.
125+
* @return
126+
*/
127+
public boolean getNeedsApproval() {
128+
return needsApproval;
129+
}
130+
131+
/**
132+
* @description Set internally by the API.
133+
* @param needsApproval
134+
*/
135+
public void setNeedsApproval(boolean needsApproval) {
136+
this.needsApproval = needsApproval;
137+
}
138+
139+
/**
140+
* @description Returns the current state of the package.
141+
* @return
142+
*/
143+
public PackageState getState() {
144+
return state;
145+
}
146+
147+
/**
148+
* @description Set internally by the API.
149+
* @param state
150+
*/
151+
public void setState(PackageState state) {
152+
this.state = state;
153+
}
154+
155+
/**
156+
* @description Get the number of days the final package will be available for before it expires.
157+
* @return
158+
*/
159+
public int getLife() {
160+
return life;
161+
}
162+
163+
/**
164+
* @description Set internally by the API.
165+
* @param life
166+
*/
167+
public void setLife(int life) {
168+
this.life = life;
169+
}
170+
171+
}

0 commit comments

Comments
 (0)