Skip to content

Commit

Permalink
Add filesEndpoint to Uploader interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Oct 31, 2023
1 parent fb5b873 commit cd1cf0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/main/kotlin/de/cyface/uploader/DefaultUploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import javax.net.ssl.SSLException
* To use this interface just call [DefaultUploader.upload] with an authentication token.
*
* @author Armin Schnabel
* @version 1.0.0
* @version 1.1.0
* @since 1.0.0
* @property apiEndpoint An API endpoint running a Cyface data collector service, like `https://some.url/api/v3`
*/
Expand All @@ -78,6 +78,7 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
jwtToken: String,
metaData: RequestMetaData,
file: File,
endpoint: URL,
progressListener: UploadProgressListener
): Result {
return try {
Expand Down Expand Up @@ -114,7 +115,7 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
uploader.progressListener = ProgressHandler(progressListener)

// Upload
val requestUrl = GenericUrl(endpoint())
val requestUrl = GenericUrl(endpoint)
val response = uploader.upload(requestUrl)
try {
readResponse(response, jsonFactory)
Expand Down Expand Up @@ -201,6 +202,10 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
return URL(returnUrlWithTrailingSlash(apiEndpoint) + "measurements")
}

override fun filesEndpoint(measurementId: Long): URL {
return URL(returnUrlWithTrailingSlash(apiEndpoint) + "measurements/$measurementId/files")
}

@Throws(
BadRequestException::class,
UnauthorizedException::class,
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/de/cyface/uploader/Uploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.net.URL
* Interface for uploading files to a Cyface Data Collector.
*
* @author Armin Schnabel
* @version 1.0.0
* @version 1.1.0
* @since 1.0.0
*/
interface Uploader {
Expand All @@ -39,6 +39,7 @@ interface Uploader {
* @param jwtToken A String in the format "eyXyz123***".
* @param metaData The [RequestMetaData] required for the Multipart request.
* @param file The data file to upload via this post request.
* @param endpoint The endpoint to upload the data to.
* @param progressListener The [UploadProgressListener] to be informed about the upload progress.
* @throws UploadFailed when an error occurred.
* @return [Result.UPLOAD_SUCCESSFUL] when successful and [Result.UPLOAD_SKIPPED] when the server is
Expand All @@ -50,13 +51,22 @@ interface Uploader {
jwtToken: String,
metaData: RequestMetaData,
file: File,
endpoint: URL,
progressListener: UploadProgressListener
): Result

/**
* @return the endpoint which will be used for the upload.
* @return the endpoint which will be used to upload the core measurement file.
* @throws MalformedURLException if the endpoint address provided is malformed.
*/
@Throws(MalformedURLException::class)
fun endpoint(): URL

/**
* @param measurementId The id of the measurement the files are captured for.
* @return the endpoint which will be used to upload the attached files of a measurement.
* @throws MalformedURLException if the endpoint address provided is malformed.
*/
@Throws(MalformedURLException::class)
fun filesEndpoint(measurementId: Long): URL
}

0 comments on commit cd1cf0f

Please sign in to comment.