Skip to content

Commit

Permalink
adds javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
louismrose committed Mar 18, 2024
1 parent 0abd089 commit a89b7ef
Show file tree
Hide file tree
Showing 18 changed files with 559 additions and 29 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/zamzar/api/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
import com.zamzar.api.invoker.ApiException;
import com.zamzar.api.model.Account;

/**
* Retrieves account information.
*/
public class AccountService {

protected final ZamzarClient zamzar;
protected final AccountApi api;

public AccountService(ZamzarClient zamzar) {
protected AccountService(ZamzarClient zamzar) {
this.zamzar = zamzar;
this.api = new AccountApi(zamzar.client);
}

/**
* Retrieves the current status of your Zamzar API account, including your available conversion credits and current
* plan.
*/
public Account get() throws ApiException {
return api.getAccount();
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/zamzar/api/DefaultService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import com.zamzar.api.core.DefaultApi;
import com.zamzar.api.invoker.ApiException;

/**
* Checks connectivity to the Zamzar API.
*/
public class DefaultService {

protected final ZamzarClient zamzar;
protected final DefaultApi api;

public DefaultService(ZamzarClient zamzar) {
protected DefaultService(ZamzarClient zamzar) {
this.zamzar = zamzar;
this.api = new DefaultApi(zamzar.client);
}

/**
* Returns a welcome message if the Zamzar API is reachable, available and you are authenticated.
*/
public String welcome() throws ApiException {
return api.welcome().getMessage();
}
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/zamzar/api/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,43 @@
import java.io.File;
import java.util.Objects;

/**
* Provides operations that can be performed on a file resident on the Zamzar API servers.
*/
public class FileManager {

protected final ZamzarClient zamzar;
protected final ModelFile model;

public FileManager(ZamzarClient zamzar, ModelFile model) {
protected FileManager(ZamzarClient zamzar, ModelFile model) {
this.zamzar = zamzar;
this.model = model;
}

/**
* Returns the file's metadata.
*/
public ModelFile getModel() {
return model;
}

/**
* Returns the file's ID.
*/
public Integer getId() {
return getModel().getId();
}

/**
* Immediately deletes the file from the Zamzar API servers.
*/
public FileManager delete() throws ApiException {
return zamzar.files().delete(getId());
}

/**
* Downloads the file to the specified destination, blocking until the download is complete.
*/
public FileManager download(File destination) throws ApiException {
zamzar.files().download(getModel(), destination);
return this;
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/com/zamzar/api/FilesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@
import java.util.List;
import java.util.stream.Collectors;

/**
* Uploads to, downloads from, and retrieves files on the Zamzar API servers.
*/
public class FilesService implements Listable<FileManager, Integer> {

protected final ZamzarClient zamzar;
protected final FilesApi api;

public FilesService(ZamzarClient zamzar) {
protected FilesService(ZamzarClient zamzar) {
this.zamzar = zamzar;
this.api = new FilesApi(zamzar.client);
}

/**
* Retrieves a file by its ID.
*
* @see FileManager
*/
public FileManager find(Integer id) throws ApiException {
return toFile(api.getFileById(id));
}

/**
* Retrieves a list of files.
*
* @param anchor indicates the position in the list from which to start retrieving files
* @param limit indicates the maximum number of files to retrieve
* @see Paged
* @see FileManager
*/
@Override
public Paged<FileManager, Integer> list(Anchor<Integer> anchor, Integer limit) throws ApiException {
final Integer after = anchor == null ? null : anchor.getAfterParameterValue();
Expand All @@ -36,18 +52,31 @@ public Paged<FileManager, Integer> list(Anchor<Integer> anchor, Integer limit) t
return new Paged<>(this, toFiles(response.getData()), Paging.fromNumeric(response.getPaging()));
}

/**
* Immediately deletes a file from the Zamzar API servers.
*/
public FileManager delete(Integer id) throws ApiException {
return toFile(api.deleteFileById(id));
}

/**
* Downloads a file to the specified destination. Blocks until the download is complete.
*/
public FileManager download(Integer id, File destination) throws ApiException {
return find(id).download(destination);
}

/**
* Uploads a file to the Zamzar API servers. The file's name is used as the name of the file on the server.
* Blocks until the upload is complete.
*/
public FileManager upload(File file) throws ApiException {
return upload(file, file.getName());
}

/**
* Uploads a file to the Zamzar API servers. Blocks until the upload is complete.
*/
public FileManager upload(File file, String name) throws ApiException {
return toFile(api.uploadFile(file, name));
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/zamzar/api/FormatsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@
import com.zamzar.api.pagination.Paged;
import com.zamzar.api.pagination.Paging;

/**
* Retrieves information about the file formats supported by the Zamzar API.
*/
public class FormatsService implements Listable<Format, String> {
protected final ZamzarClient zamzar;
protected final FormatsApi api;

public FormatsService(ZamzarClient zamzar) {
protected FormatsService(ZamzarClient zamzar) {
this.zamzar = zamzar;
this.api = new FormatsApi(zamzar.client);
}

/**
* Retrieves a file format by its name.
*/
public Format find(String name) throws ApiException {
return api.getFormatById(name);
}

/**
* Retrieves a list of file formats.
*
* @param anchor indicates the position in the list from which to start retrieving file formats
* @param limit indicates the maximum number of file formats to retrieve
*/
@Override
public Paged<Format, String> list(Anchor<String> anchor, Integer limit) throws ApiException {
final String after = anchor == null ? null : anchor.getAfterParameterValue();
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/com/zamzar/api/ImportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.List;
import java.util.Objects;

/**
* Provides operations that can be performed on an import request running on the Zamzar API servers.
*/
public class ImportManager extends Awaitable<ImportManager> {

protected static List<ModelImport.StatusEnum> TERMINAL_STATUSES = Arrays.asList(
Expand All @@ -19,35 +22,58 @@ public class ImportManager extends Awaitable<ImportManager> {
protected final ZamzarClient zamzar;
protected final ModelImport model;

public ImportManager(ZamzarClient zamzar, ModelImport model) {
protected ImportManager(ZamzarClient zamzar, ModelImport model) {
this.zamzar = zamzar;
this.model = model;
}

/**
* Returns the import request's metadata.
*/
public ModelImport getModel() {
return model;
}

/**
* Returns the import request's ID.
*/
public Integer getId() {
return getModel().getId();
}

/**
* Indicates whether the import request has completed.
*/
public boolean hasCompleted() {
return TERMINAL_STATUSES.contains(getModel().getStatus());
}

/**
* Indicates whether the import request has successfully completed.
*/
public boolean hasSucceeded() {
return getModel().getStatus() == ModelImport.StatusEnum.SUCCESSFUL;
}

/**
* If the import request has failed, returns the reason for the failure.
*/
public Failure getFailure() {
return getModel().getFailure();
}

/**
* Performs an API request to determine the current state of the import request.
*/
public ImportManager refresh() throws ApiException {
return zamzar.imports().find(getId());
}

/**
* Returns a file manager for the imported file.
*
* @see FileManager
*/
public FileManager getImportedFile() {
return new FileManager(zamzar, getModel().getFile());
}
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/zamzar/api/ImportsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@
import java.util.List;
import java.util.stream.Collectors;

/**
* Starts imports -- and retrieves information about existing imports -- on the Zamzar API servers.
*/
public class ImportsService implements Listable<ImportManager, Integer> {
protected final ZamzarClient zamzar;
protected final ImportsApi api;

public ImportsService(ZamzarClient zamzar) {
protected ImportsService(ZamzarClient zamzar) {
this.zamzar = zamzar;
this.api = new ImportsApi(zamzar.client);
}

/**
* Retrieves an import request by its ID.
*/
public ImportManager find(Integer id) throws ApiException {
return toImport(api.getImportById(id));
}

/**
* Retrieves a list of import requests.
*
* @param anchor indicates the position in the list from which to start retrieving import requests
* @param limit indicates the maximum number of import requests to retrieve
*/
@Override
public Paged<ImportManager, Integer> list(Anchor<Integer> anchor, Integer limit) throws ApiException {
final Integer after = anchor == null ? null : anchor.getAfterParameterValue();
Expand All @@ -34,8 +46,18 @@ public Paged<ImportManager, Integer> list(Anchor<Integer> anchor, Integer limit)
return new Paged<>(this, toImports(response.getData()), Paging.fromNumeric(response.getPaging()));
}

/**
* Starts an import request.
*/
public ImportManager start(String url) throws ApiException {
return new ImportManager(zamzar, api.startImport(url, null)); // FIXME - add ability to set the name
return new ImportManager(zamzar, api.startImport(url, null));
}

/**
* Starts an import request, overriding the filename (rather than using the filename from the URL).
*/
public ImportManager start(String url, String filename) throws ApiException {
return new ImportManager(zamzar, api.startImport(url, filename));
}

protected List<ImportManager> toImports(List<ModelImport> models) {
Expand Down
Loading

0 comments on commit a89b7ef

Please sign in to comment.