WaifuVault (waifu_vault v1.0.0)
This API wrapper is meant to conform to the WaifuVault Swagger docs.
To include in your project:
# In your mix.exs deps/0 function
{:waifu_vault, "~> 1.0.0"}
To Use:
# In your_file.ex
require WaifuVault
Summary
Albums
The associate_file/2 function connects one or more files to an album. Swagger docs
The create_album/2 function creates an album within the specified bucket. Swagger docs
The delete_album/2 function removes the specified album. Swagger docs
The disassociate_file/2 function dis-connects one or more files from an album. Swagger docs
The download_album/2 function fetches a zip file containing either the whole album, or specified files. Swagger docs
The get_album/1 function returns album info, given the private token. Swagger docs
The revoke_album/1 function disables public sharing. Note that future calls to share_album/1 will give it a new public token and new public URL. Swagger docs
The share_album/1 function takes the album's private token and returns the public URL. Calling share_album/1 on an already-shared album will just return its token. Swagger docs
Buckets
Buckets are virtual collections that are linked to your IP and a token. When you create a bucket, you will receive a bucket token that you can use in get_bucket/1 to get all the files in that bucket. Later calls to create_bucket/0 will return the same token as long as your IP address doesn't change. Swagger docs
Deleting a bucket will delete the bucket and all the files it contains. Swagger docs
The get_bucket/1 function returns the list of files and albums contained in a bucket.
The bucket has a dateCreated
value that can be converted
with DateTime.from_unix( dateCreated, :millisecond)
Swagger docs
Files
The delete_file/1 function returns {:ok, true}
for a successful deletion.
Swagger docs
The file_info/2 function retrieves file metadata for the specified file token. Swagger docs
The get_file/2 function retrieves the contents of the specified file, which can be specified via URL or by token (which is used to look up the URL). The password, if passed, is ignored unless the file is password-protected. Swagger docs
The update_file/2 function returns {:ok, file_data}
for a successful update.
Swagger docs
The upload_file_from_buffer/3 function posts the data to the server, returning a fileResponse map. Swagger docs and parallel Swagger docs
The upload_local_file/3 function simplifies the process of uploading a local file with a simple wrapper around upload_file_from_buffer/3. It posts the data to the server, returning a fileResponse map. Swagger docs and parallel Swagger docs
Uploading a file specified via URL. Setting the :bucket option will place the file in the specified bucket (assuming it exists). Swagger docs and parallel Swagger docs
Resources
The get_file_stats/0 function returns server limits for the current IP address. Swagger docs
The get_restrictions/0 function returns restrictions for the current IP address. Swagger docs
Albums
The associate_file/2 function connects one or more files to an album. Swagger docs
iex> {:ok, album_response} = WaifuVault.associate_file("some-valid-album-token", ["valid-file1". "valid-file2"])
{:ok, Map}
The create_album/2 function creates an album within the specified bucket. Swagger docs
iex> {:ok, album} = WaifuVault.create_album("some-bucket-token", "album-name")
{:ok, Map}
The delete_album/2 function removes the specified album. Swagger docs
# First deletion attempt
iex> WaifuVault.delete_album("album-token")
{:ok, %{"description" => "album deleted", "success" => true}}
# Attempt a second deletion
iex> WaifuVault.delete_album("album-token")
{:error,
"Error 400 (BAD_REQUEST): Album with token album-token not found"}
The disassociate_file/2 function dis-connects one or more files from an album. Swagger docs
iex> {:ok, album_response} = WaifuVault.disassociate_file("some-valid-album-token", ["valid-file1". "valid-file2"])
{:ok, Map}
The download_album/2 function fetches a zip file containing either the whole album, or specified files. Swagger docs
iex> {:ok, zip_data} = WaifuVault.download_album("some-valid-album-token", ["file.jpg", "file2.jpg"])
{:ok, zip_data}
The get_album/1 function returns album info, given the private token. Swagger docs
iex> {:ok, album_response} = WaifuVault.get_album("some-valid-album-token")
{:ok, Map}
The revoke_album/1 function disables public sharing. Note that future calls to share_album/1 will give it a new public token and new public URL. Swagger docs
iex> {:ok, album_response} = WaifuVault.revoke_album("some-valid-album-token")
{:ok, "album unshared"}
Buckets
Buckets are virtual collections that are linked to your IP and a token. When you create a bucket, you will receive a bucket token that you can use in get_bucket/1 to get all the files in that bucket. Later calls to create_bucket/0 will return the same token as long as your IP address doesn't change. Swagger docs
iex> {:ok, bucket} = WaifuVault.create_bucket()
{:ok, "some-uuid-type-value"}
Deleting a bucket will delete the bucket and all the files it contains. Swagger docs
IMPORTANT: All contained files will be DELETED along with the Bucket!
iex> {:ok, boolean} = WaifuVault.delete_bucket("some-valid-uuid-token")
{:ok, true}
The get_bucket/1 function returns the list of files and albums contained in a bucket.
The bucket has a dateCreated
value that can be converted
with DateTime.from_unix( dateCreated, :millisecond)
Swagger docs
Individual files have a retentionPeriod
which is the UNIX timestamp in milliseconds for when the
file will expire. It can be converted with DateTime.from_unix( retentionPeriod, :millisecond)
iex> {:ok, boolean} = WaifuVault.get_bucket("some-valid-uuid-token")
{:ok, Map}
Files
The delete_file/1 function returns {:ok, true}
for a successful deletion.
Swagger docs
iex> {:ok, true} = WaifuVault.delete_file(file_token)
{:ok, true}
The file_info/2 function retrieves file metadata for the specified file token. Swagger docs
iex> {:ok, map} = WaifuVault.file_info("some-valid-file-token")
{:ok, %{...}}
The get_file/2 function retrieves the contents of the specified file, which can be specified via URL or by token (which is used to look up the URL). The password, if passed, is ignored unless the file is password-protected. Swagger docs
iex> {:ok, bitstring} = WaifuVault.get_file("some-valid-album-token", "some-password")
{:ok, <<many bytes>>}
The update_file/2 function returns {:ok, file_data}
for a successful update.
Swagger docs
iex> {:ok, true} = WaifuVault.update_file(file_token, %{...})
{:ok, true}
The upload_file_from_buffer/3 function posts the data to the server, returning a fileResponse map. Swagger docs and parallel Swagger docs
iex> {:ok, buffer} = File.read("some/local/file")
iex> {:ok, fileResponse} = WaifuVault.upload_file_from_buffer(buffer, "file.name", %{expires: "10m"})
{:ok, %{...}}
The upload_local_file/3 function simplifies the process of uploading a local file with a simple wrapper around upload_file_from_buffer/3. It posts the data to the server, returning a fileResponse map. Swagger docs and parallel Swagger docs
iex> options = %{}
iex> {:ok, fileResponse} = WaifuVault.upload_local_file("./mix.exs", "my_mix.exs", options)
{:ok, %{...}}
Uploading a file specified via URL. Setting the :bucket option will place the file in the specified bucket (assuming it exists). Swagger docs and parallel Swagger docs
iex> options = %{}
iex> {:ok, fileResponse} = WaifuVault.upload_via_url(image_url, options)
{:ok, %{...}}
Resources
The get_file_stats/0 function returns server limits for the current IP address. Swagger docs
iex> WaifuVault.get_file_stats
{:ok, %{"recordCount" => 1420, "recordSize" => "1.92 GiB"}}
The get_restrictions/0 function returns restrictions for the current IP address. Swagger docs
iex> {:ok, restrictions} = WaifuVault.get_restrictions()
{:ok,
[
%{type: "MAX_FILE_SIZE", value: 104857600},
%{
type: "BANNED_MIME_TYPE",
value: "application/x-dosexec,application/x-executable,application/x-hdf5,application/x-java-archive,application/vnd.rar"
}
]
}