Current section
Files
Jump to
Current section
Files
lib/bamboohr_ex.ex
defmodule BamboohrEx do
@moduledoc """
A Wrapper around [BambooHR API](http://www.bamboohr.com/api/documentation/)
- To use this package, you must have an API key generated in BambooHR.
The steps to generate API key in Bamboo can be found [here](https://nexonia.zendesk.com/hc/en-us/articles/115000609072-Creating-a-BambooHR-API-Key-for-Integration)
- This package is just a wrapper, so it will only let you see resources that
correspond to permissions associated with the API key
This package can be configured with default `api_key` and `subdomain`.
This package can also be configured with a default `caller`. It should be used
mainly for testing purposes.
## Example Configuration (dev.exs)(Optional):
config :bamboohr_ex, BamboohrEx,
caller: BamboohrEx.HTTPClient,
api_key: "YOUR_BAMBOOHR_API_KEY",
subdomain: "DEFAULT_SUBDOMAIN"
## Example Configuration (test.exs)(Optional):
config :bamboohr_ex, BamboohrEx,
caller: BamboohrEx.InMemory,
api_key: "thuum",
subdomain: "skyrim"
"""
@doc """
`:caller` can be set as a runtime config
in the `config.exs` file
## Examples
when no `caller` config is set, if returns `BamboohrEx.Caller`
iex> BamboohrEx.caller
BamboohrEx.InMemory
"""
def caller do
config(:caller, BamboohrEx.HTTPClient)
end
@doc """
`:api_key` can be set as a runtime config
in the `config.exs` file
## Examples
when no `api_key` config is set, if returns nil
iex> BamboohrEx.api_key
"thuum"
"""
def api_key do
config(:api_key, nil)
end
@doc """
`:subdomain` can be set as a runtime config
in the `config.exs` file
## Examples
when no `subdomain` config is set, if returns nil
iex> BamboohrEx.subdomain
"skyrim"
"""
def subdomain do
config(:subdomain, nil)
end
@doc """
Gets configuration assocaited with the `bamboohr_ex` app.
## Examples
when no config is set, if returns []
iex> BamboohrEx.config
[caller: BamboohrEx.InMemory, api_key: "thuum", subdomain: "skyrim"]
"""
def config do
Application.get_env(:bamboohr_ex, BamboohrEx, [])
end
@doc """
Gets configuration set for a `key`, assocaited with the `bamboohr_ex` app.
## Examples
when no config is set for `key`, if returns `default`
iex> BamboohrEx.config(:random, "default")
"default"
"""
def config(key, default \\ nil) do
config()
|> Keyword.get(key, default)
|> resolve_config(default)
end
@doc """
`resolve_config` returns a `system` variable set up with `var_name` key
or returns the specified `default` value. Takes in `arg` whose first element is
an atom `:system`.
## Examples
Returns value corresponding to a system variable config or returns the `default` value:
iex> BamboohrEx.resolve_config({:system, "SOME_RANDOM_CONFIG"}, "default")
"default"
"""
@spec resolve_config(Tuple.t, term) :: {term}
def resolve_config({:system, var_name}, default) do
System.get_env(var_name) || default
end
def resolve_config(value, _default), do: value
end