Skip to content

Instantly share code, notes, and snippets.

@amencarini
Last active September 5, 2015 09:09
Show Gist options
  • Save amencarini/ed2c148eab0edc9f21d5 to your computer and use it in GitHub Desktop.
Save amencarini/ed2c148eab0edc9f21d5 to your computer and use it in GitHub Desktop.
defmodule Client do
defmacro __using__(resources: resources) do
for {singlular, plural} <- resources do
quote bind_quoted: [singlular: singlular, plural: plural] do
def one(singlular, id) do
get("/api/#{plural}/#{id}")
end
end
end
end
def get(url) do
IO.puts inspect(url)
end
end
defmodule AppCode do
use Client, resources: [{:product, :products}, {:category, :categories}]
def test, do: Client.one(:product, 12)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment