Skip to content

Instantly share code, notes, and snippets.

@adkron
Created August 14, 2017 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adkron/4c025c8eabef2d76973b6da3cdf94d92 to your computer and use it in GitHub Desktop.
Save adkron/4c025c8eabef2d76973b6da3cdf94d92 to your computer and use it in GitHub Desktop.
defmodule Zipato.Box do
@moduledoc """
Build Zipato box commands
"""
alias Zipato.Sessions.{Master}
defstruct [session: Master, serial: nil, command: nil]
def list, do: %__MODULE__{command: :list}
def register(serial), do: %__MODULE__{command: :register, serial: serial}
def unregister(serial), do: %__MODULE__{command: :unregister, serial: serial}
defimpl Zipato.Request.Build do
alias Zipato.{Request}
def build(%{command: :list}) do
"/box/list"
|> Request.init(:get)
end
def build(%{command: command, serial: serial}) do
"/box/#{command}"
|> Request.init(:post)
|> Request.add_params(
%{
serial: serial,
}
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment