Packages

An Elixir SDK for Porter's delivery API, providing a simple and reliable way to integrate Porter's logistics services into your Elixir applications. Features include getting delivery quotes, creating and managing delivery orders, and real-time order tracking.

Current section

Files

Jump to
ex_porter_sdk lib protocols protocol_generator.ex
Raw

lib/protocols/protocol_generator.ex

defmodule ExPorterSDK.Protocols.ProtocolGenerator do
@moduledoc """
Generates a default protocol implementations for non-nested structures.
"""
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
alias ExPorterSDK.Protocols.Mappable
@structs Keyword.get(opts, :structs, [])
for struct <- @structs do
# Generate Mappable implementation
defimpl Mappable, for: struct do
def to_map(struct) do
Map.from_struct(struct)
end
end
end
end
end
end