Hash :
fe17ed84
Author :
Date :
2016-05-01T14:43:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
defmodule ExOvh.Utils do
@moduledoc false
alias ExOvh.Auth.Ovh.Cache, as: OvhCache
alias ExOvh.Auth.Openstack.Swift.Cache, as: SwiftCache
alias ExOvh.Defaults
@doc """
For naming a supervisor to incorporate the name of the client.
The client name is required so that when a client makes a request, the correct supervisor
is called if there are multiple clients in use.
"""
defmacro supervisor_name(client) do
caller = __CALLER__.module
quote do
(
(
Atom.to_string(unquote(client))
<>
"."
)
<>
Atom.to_string(unquote(caller))
)
|> String.replace("Elixir.", "")
|> String.to_atom()
end
end
@doc """
For naming a genserver to incorporate the name of the client.
The client name is required so that when a client makes a request, the correct genserver
is called if there are multiple clients in use.
"""
defmacro gen_server_name(client) do
caller = __CALLER__.module
quote do
(
(
Atom.to_string(unquote(client))
<>
"."
)
<>
Atom.to_string(unquote(caller))
)
|> String.replace("Elixir.", "")
|> String.to_atom()
end
end
@doc """
For naming an ets table to incorporate the name of the client.
The client name is required so that when a client makes a request, the correct ets table
is looked up if there are multiple clients in use.
"""
defmacro ets_tablename(client) do
# caller = __CALLER__.module
quote do
"Ets."
<>
(
gen_server_name(unquote(client))
|> Atom.to_string()
)
|> String.to_atom()
end
end
@doc """
Changes the timeout option for a http_query.
"""
@spec change_http_query_timeout(Openstex.HttpQuery.t, integer) :: Openstex.HttpQuery.t
def change_http_query_timeout(%Openstex.HttpQuery{options: options} = http_query, new_timeout) do
new_options = Map.merge(options, Map.put(options, :timeout, new_timeout))
Map.put(http_query, :options, new_options)
end
@doc """
Returns a string with the formatted date
"""
@spec formatted_date() :: String.t
def formatted_date() do
{year, month, date} = :erlang.date()
Integer.to_string(date) <> "." <>
Integer.to_string(month) <> "." <>
Integer.to_string(year)
end
end