Package ch.threema.apitool
Class APIConnector
java.lang.Object
ch.threema.apitool.APIConnector
Facilitates HTTPS communication with the Threema Message API.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAPIConnector(String apiIdentity, String secret, PublicKeyStore publicKeyStore) APIConnector(String apiIdentity, String secret, String apiUrl, PublicKeyStore publicKeyStore) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]downloadFile(byte[] blobId) Download a file given its blob ID.protected ApiExceptiongetApiException(String operationId, HttpResponse<InputStream> response) lookupEmail(String email) Lookup an ID by email address.byte[]Lookup a public key by ID.lookupKeyCapability(String threemaId) Lookup the capabilities of a IDlookupPhone(String phoneNumber) Lookup an ID by phone number.static HttpRequest.BodyPublisherofMimeMultipartData(Map<Object, Object> data, String boundary, byte[] fileEncryptionResultData) ApiResponse<org.json.JSONArray> sendE2EBulkMessage(String[] toArr, byte[][] nonces, byte[][] boxes) ApiResponse<org.json.JSONArray> sendE2EBulkMessage(String[] toArr, byte[][] nonces, byte[][] boxes, Map<String, ?> options) sendE2EMessage(String to, byte[] nonce, byte[] box) sendE2EMessage(String to, byte[] nonce, byte[] box, Map<String, ?> options) sendTextMessageSimple(String to, String text) Send a text message with server-side encryption.voidsetUserAgent(String userAgent) uploadFile(EncryptResult fileEncryptionResult) Upload a file.uploadFile(EncryptResult fileEncryptionResult, boolean persist) Upload a file.
-
Field Details
-
userAgent
-
-
Constructor Details
-
APIConnector
-
APIConnector
public APIConnector(String apiIdentity, String secret, String apiUrl, PublicKeyStore publicKeyStore)
-
-
Method Details
-
getUserAgent
-
setUserAgent
-
sendTextMessageSimple
Send a text message with server-side encryption.- Parameters:
to- recipient IDtext- message text (max. 3500 bytes)- Returns:
- message ID
- Throws:
ApiException- if a communication or server error occurs
-
sendE2EMessage
- Throws:
ApiException
-
sendE2EMessage
public ApiResponse<String> sendE2EMessage(String to, byte[] nonce, byte[] box, Map<String, ?> options) throws ApiException- Throws:
ApiException
-
sendE2EBulkMessage
public ApiResponse<org.json.JSONArray> sendE2EBulkMessage(String[] toArr, byte[][] nonces, byte[][] boxes) throws ApiException - Throws:
ApiException
-
sendE2EBulkMessage
public ApiResponse<org.json.JSONArray> sendE2EBulkMessage(String[] toArr, byte[][] nonces, byte[][] boxes, Map<String, ?> options) throws ApiException- Throws:
ApiException
-
lookupPhone
Lookup an ID by phone number. The phone number will be hashed before being sent to the server.- Parameters:
phoneNumber- the phone number in E.164 format- Returns:
- the ID, or null if not found
- Throws:
ApiException- if a communication or server error occurs
-
lookupEmail
Lookup an ID by email address. The email address will be hashed before being sent to the server.- Parameters:
email- the email address- Returns:
- the ID, or null if not found
- Throws:
ApiException- if a communication or server error occurs
-
lookupKey
Lookup a public key by ID.- Parameters:
id- the ID whose public key is desired- Returns:
- the corresponding public key, or null if not found
- Throws:
ApiException- if a communication or server error occurs
-
lookupKeyCapability
Lookup the capabilities of a ID- Parameters:
threemaId- The ID whose capabilities should be checked- Returns:
- The capabilities, or null if not found
- Throws:
IOExceptionApiException
-
lookupCredits
- Throws:
ApiException
-
uploadFile
Upload a file.- Parameters:
fileEncryptionResult- The result of the file encryption (i.e. encrypted file data)- Returns:
- the result of the upload
- Throws:
IOException
-
uploadFile
public UploadResult uploadFile(EncryptResult fileEncryptionResult, boolean persist) throws IOException Upload a file.- Parameters:
fileEncryptionResult- The result of the file encryption (i.e. encrypted file data)persist- Whether the uploaded file blob should be persisted- Returns:
- the result of the upload
- Throws:
IOException
-
ofMimeMultipartData
public static HttpRequest.BodyPublisher ofMimeMultipartData(Map<Object, Object> data, String boundary, byte[] fileEncryptionResultData) throws IOException- Throws:
IOException
-
downloadFile
Download a file given its blob ID.- Parameters:
blobId- The blob ID of the file- Returns:
- Encrypted file data
- Throws:
IOException
-
getApiException
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException - Throws:
IOException
-