Packages
smart_city
5.2.3
6.0.0
5.4.7
5.4.6
5.4.5
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.8
5.2.6
5.2.5
5.2.4
5.2.3
5.2.2
5.2.1
5.2.0
5.1.1
5.1.0
5.0.7
5.0.6
5.0.5
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.0.1
4.0.0
3.25.0
3.24.0
3.23.0
3.22.0
3.21.0
3.20.1
3.20.0
3.19.1
3.19.0
3.18.3
3.18.2
3.18.1
3.18.0
3.17.0
3.16.0
3.15.1
3.15.0
3.14.1
3.14.0
3.13.0
3.12.0
3.11.0
3.10.0
3.9.0
3.8.0
3.7.0
3.6.0
3.5.1
3.5.0
3.4.0
3.3.0
3.2.4
3.2.3
3.2.1
3.2.0
3.1.0
3.0.0
2.9.0
2.8.2
2.8.0
2.7.1
2.7.0
2.6.1
2.5.0
2.4.2
retired
2.4.1
2.4.0
2.3.0
2.2.0
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
A library for shared helper modules in the Smart Cities Data project.
Current section
Files
Jump to
Current section
Files
lib/smart_city/hosted_file.ex
defmodule SmartCity.HostedFile do
@moduledoc """
Defines the information needed to process uploaded
files by components of the system including the files'
type, parent identifier, and location info.
"""
@type id :: String.t()
@type bucket :: String.t()
@type key :: String.t()
@type t :: %SmartCity.HostedFile{
:bucket => bucket(),
:dataset_id => id(),
:key => key(),
:mime_type => SmartCity.Helpers.mime_type()
}
@derive Jason.Encoder
defstruct bucket: nil,
dataset_id: nil,
key: nil,
mime_type: nil,
version: "0.1"
alias SmartCity.BaseStruct
@doc """
Instantiates an instance of a file upload event struct.
"""
@spec new(String.t() | map()) :: {:ok, map()} | {:error, term()}
def new(msg) do
msg
|> BaseStruct.new()
|> create()
end
defp create(%{dataset_id: id, mime_type: type, bucket: bucket, key: key}) do
mime_type = SmartCity.Helpers.mime_type(type)
file =
struct(%__MODULE__{}, %{
bucket: bucket,
dataset_id: id,
key: key,
mime_type: mime_type
})
{:ok, file}
end
defp create(bad_struct) do
{:error, "Invalid file upload event: #{inspect(bad_struct)}"}
end
end