Created
August 14, 2017 20:24
-
-
Save adkron/4c025c8eabef2d76973b6da3cdf94d92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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