Expander v0.0.1 Expander.Expand View Source
Defines an Expander.
An expander is a wrapper around an adapter that makes it easy for you to swap the cache adapter without having to change your code.
It is also responsible for doing some sanity checks before handing down the url to the adapter.
When used, the expander expects :otp_app as an option.
The :otp_app should point to an OTP application that has the expander
configuration. For example, the expander:
defmodule Sample.Expander do
use Expander.Expand, otp_app: :sample
end
Could be configured with:
config :sample, Sample.Expander,
adapter: Expander.Cache.Adapter.Local,
api_key: "x.x.x"
Most of the configuration that goes into the config is specific to the adapter, so check the adapter’s documentation for more information.
Note that the configuration is set into your expander at compile time. If you
need to reference config at runtime you can use a tuple like
{:system, "ENV_VAR"}.
config :sample, Sample.LocalCacheExpander,
adapter: Expander.Cache.Adapter.Local
Examples
Once configured you can use your expander like this:
# in an IEx console
iex> url = new() |> short_url("http://amzn.to/2w9oM5d")
%Expander.Url{long_url: nil, short_url: "http://amzn.to/2w9oM5d"}
iex> Expander.expand(url)
{:ok, {%Expander.Url{long_url: "http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create_dashboard.html?sc_channel=sm&sc_campaign=Docs&sc_publisher=TWITTER&sc_country=Global&sc_geo=GLOBAL&sc_outcome=[GLOBAL]&sc_content=Docs&linkId=40350988", short_url: "http://amzn.to/2w9oM5d"}, []}}
You can also pass an extra config argument to expand/2 that will be merged
with your Expander’s config:
# in an IEx console
iex> url = new() |> short_url("http://amzn.to/2w9oM5d")
%Expander.Url{long_url: nil, short_url: "http://amzn.to/2w9oM5d"}
iex> Expander.expand(url, tls: 100)
{%Expander.Url{long_url: "http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create_dashboard.html?sc_channel=sm&sc_campaign=Docs&sc_publisher=TWITTER&sc_country=Global&sc_geo=GLOBAL&sc_outcome=[GLOBAL]&sc_content=Docs&linkId=40350988", short_url: "http://amzn.to/2w9oM5d"}, []}}
Link to this section Summary
Functions
Parses the OTP configuration at compile time
Parses the OTP configuration at run time. This function will transform all the {:system, “ENV_VAR”} tuples into their respective values grabbed from the process environment
Link to this section Functions
Parses the OTP configuration at compile time.
Parses the OTP configuration at run time. This function will transform all the {:system, “ENV_VAR”} tuples into their respective values grabbed from the process environment.