-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for notifying package recipients
- Loading branch information
1 parent
7e098b0
commit 336375c
Showing
6 changed files
with
183 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
SendSafelyAPI/src/com/sendsafely/dto/request/NotifyPackageRecipientsRequest.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,27 @@ | ||
package com.sendsafely.dto.request; | ||
|
||
import com.sendsafely.enums.GetParam; | ||
import com.sendsafely.enums.HTTPMethod; | ||
import com.sendsafely.json.JsonManager; | ||
|
||
public class NotifyPackageRecipientsRequest extends BaseRequest | ||
{ | ||
|
||
private HTTPMethod method = HTTPMethod.POST; | ||
private String path = "/package/" + GetParam.PACKAGE_ID + "/notify/"; | ||
|
||
public NotifyPackageRecipientsRequest(JsonManager jsonManager, String keyCode) { | ||
initialize(jsonManager, method, path); | ||
|
||
super.setPostParam("keycode", keyCode); | ||
} | ||
|
||
public NotifyPackageRecipientsRequest() { | ||
} | ||
|
||
public void setPackageId(String packageId) | ||
{ | ||
super.setGetParam(GetParam.PACKAGE_ID, packageId); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
SendSafelyAPI/src/com/sendsafely/exceptions/NotifyPackageRecipientsException.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,44 @@ | ||
package com.sendsafely.exceptions; | ||
|
||
import java.util.List; | ||
|
||
public class NotifyPackageRecipientsException extends Exception | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
private List<String> errors; | ||
|
||
String error; | ||
|
||
public NotifyPackageRecipientsException() | ||
{ | ||
super(); | ||
error = "unknown"; | ||
} | ||
|
||
public NotifyPackageRecipientsException(String err){ | ||
super(err); | ||
error = err; | ||
} | ||
|
||
public NotifyPackageRecipientsException(String err, List<String> errors){ | ||
super(err); | ||
error = err; | ||
this.errors = errors; | ||
} | ||
|
||
public NotifyPackageRecipientsException(Exception e){ | ||
super(e); | ||
error = e.getMessage(); | ||
} | ||
|
||
public String getError() | ||
{ | ||
return error; | ||
} | ||
|
||
public List<String> getErrors() | ||
{ | ||
return errors; | ||
} | ||
|
||
} |
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
45 changes: 45 additions & 0 deletions
45
SendSafelyAPI/src/com/sendsafely/handlers/NotifyPackageRecipientsHandler.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,45 @@ | ||
package com.sendsafely.handlers; | ||
|
||
import java.io.IOException; | ||
|
||
import com.sendsafely.dto.request.NotifyPackageRecipientsRequest; | ||
import com.sendsafely.dto.response.BaseResponse; | ||
import com.sendsafely.enums.APIResponse; | ||
import com.sendsafely.exceptions.NotifyPackageRecipientsException; | ||
import com.sendsafely.exceptions.SendFailedException; | ||
import com.sendsafely.upload.UploadManager; | ||
|
||
public class NotifyPackageRecipientsHandler extends BaseHandler | ||
{ | ||
|
||
private NotifyPackageRecipientsRequest request; | ||
|
||
public NotifyPackageRecipientsHandler(UploadManager uploadManager, String keycode) { | ||
super(uploadManager); | ||
this.request = new NotifyPackageRecipientsRequest(uploadManager.getJsonManager(),keycode); | ||
} | ||
|
||
public BaseResponse makeRequest(String packageId) throws NotifyPackageRecipientsException { | ||
request.setPackageId(packageId); | ||
|
||
BaseResponse response = send(); | ||
|
||
if(response.getResponse() != APIResponse.SUCCESS) | ||
{ | ||
throw new NotifyPackageRecipientsException(response.getMessage()); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
protected BaseResponse send() throws NotifyPackageRecipientsException | ||
{ | ||
try { | ||
return send(request, new BaseResponse()); | ||
} catch (SendFailedException e) { | ||
throw new NotifyPackageRecipientsException(e); | ||
} catch (IOException e) { | ||
throw new NotifyPackageRecipientsException(e); | ||
} | ||
} | ||
} |