Packages

FastPostmanCollection generate by your Phoenix Router collection for Postman, ...

Current section

Files

Jump to
fast_postman_collection lib fast_postman_collection generate_collection structs auth.ex
Raw

lib/fast_postman_collection/generate_collection/structs/auth.ex

defmodule FastPostmanCollection.GenerateCollection.Structs.Auth do
defstruct type: "bearer", bearer: []
alias FastPostmanCollection.GenerateCollection.Structs.Variable
alias FastPostmanCollection.CollectDataItem
def generate(item = %CollectDataItem{}) do
%__MODULE__{
type: "bearer",
bearer: get_config_auth_pipe(item)
}
end
def get_config_auth_pipe(item = %CollectDataItem{}) do
tokens = FastPostmanCollection.Config.get_pipe_tokens()
item.pipe_through
|> Enum.filter(fn x -> x in tokens end)
|> Enum.map(fn x ->
name_token = Atom.to_string(x) <> "_token"
%{key: "token", value: "{{#{name_token}}}"}
end)
end
def get_variables_tokens() do
tokens = FastPostmanCollection.Config.get_pipe_tokens()
Enum.map(tokens, fn x ->
name_token = Atom.to_string(x) <> "_token"
%Variable{key: name_token, value: "write_token"}
end)
end
end