Packages
smart_city
3.18.0
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/dataset/technical.ex
defmodule SmartCity.Dataset.Technical do
@moduledoc """
A struct defining technical metadata on a dataset.
"""
alias SmartCity.Helpers
@type not_required(type) :: type | nil
@type t() :: %SmartCity.Dataset.Technical{
allow_duplicates: not_required(boolean()),
authHeaders: not_required(map()),
authBody: not_required(map()),
authUrl: String.t(),
authBodyEncodeMethod: not_required(String.t()),
cadence: not_required(String.t()),
credentials: boolean(),
dataName: String.t(),
orgId: not_required(String.t()),
orgName: String.t(),
private: not_required(boolean()),
protocol: not_required(list(String.t())),
schema: not_required(list(map())),
sourceFormat: String.t(),
sourceHeaders: not_required(map()),
sourceQueryParams: not_required(map()),
sourceType: not_required(String.t()),
sourceUrl: String.t(),
systemName: String.t(),
topLevelSelector: not_required(String.t())
}
@derive Jason.Encoder
defstruct allow_duplicates: true,
authHeaders: %{},
authBody: %{},
authUrl: nil,
authBodyEncodeMethod: nil,
cadence: "never",
credentials: false,
dataName: nil,
orgId: nil,
orgName: nil,
private: true,
protocol: nil,
schema: [],
sourceFormat: nil,
sourceHeaders: %{},
sourceQueryParams: %{},
sourceType: "remote",
sourceUrl: nil,
systemName: nil,
topLevelSelector: nil
use Accessible
@doc """
Returns a new `SmartCity.Dataset.Technical`.
Can be created from `Map` with string or atom keys.
Raises an `ArgumentError` when passed invalid input
## Parameters
- msg: Map with string or atom keys that defines the dataset's technical metadata
_Required Keys_
- dataName
- orgName
- systemName
- sourceUrl
- sourceFormat
- sourceType will default to "remote"
- cadence will default to "never"
"""
@spec new(map()) :: SmartCity.Dataset.Technical.t()
def new(%{"dataName" => _} = msg) do
msg
|> Helpers.to_atom_keys()
|> new()
end
def new(%{dataName: _, orgName: _, systemName: _, sourceUrl: _, sourceFormat: type, schema: schema} = msg) do
msg
|> Map.put(:schema, Helpers.to_atom_keys(schema))
|> Map.replace!(:sourceFormat, Helpers.mime_type(type))
|> create()
end
def new(%{dataName: _, orgName: _, systemName: _, sourceUrl: _, sourceFormat: type} = msg) do
mime_type = Helpers.mime_type(type)
create(Map.replace!(msg, :sourceFormat, mime_type))
end
def new(msg) do
raise ArgumentError, "Invalid technical metadata: #{inspect(msg)}"
end
defp create(%__MODULE__{} = struct) do
struct |> Map.from_struct() |> create()
end
defp create(map), do: struct(%__MODULE__{}, map)
end