TL;DR
This post is a story about how I created an Open Source Elixir ExKeyCDN Library for KeyCDN API.
Setting
As part of my Elixir learning path, I decided that I am ready to extend my Elixir portfolio with a paid gig on Upwork. In my RSS reader Newsblur, I am using RSS feed to monitor for Elixir jobs. There was a job to create an open-source Elixir Library for KeyCDN API. I did not get the job, but I found it an excellent opportunity to create my first open-source Elixir contribution.
Hex Package
In Elixir, when you are contributing to open-source, you create a Hex Package. Here is Github repository from Alexandru; he got that job.
Tesla Hex Package
I learned from Alexandru about a trendy HTTP Elixir client, Tesla.
ExKeyCDN Hex Package
It took me 15 hours to do this library. I decided to create a Struct for each Data Type used in KeyCDN API. With struct abstractions, we move from HTTP to the KeyCDN business domain. Here are examples of how you can use the ExKeyCDN library.
How To Create Hex Library
First, create a new mix project with:
mix new exkeycdn
you need to add to mix.exs project()
function, package()
function:
The next step is to create hex
account:
mix hex.user register
Develop Library
Now do your standard Elixir development and create modules and tests for your library. KeyCDN API does not have a sandbox environment for testing, so you can only use your production key API. Not so good for your Integration tests because you could easily deplete your hourly API limit.
Mox
You will need to use some kind of mocking. By implementing ExKeyCDN using Elixir behaviors, you can use Mox mocking library. Why Mox? Because you do not give up concurrency execution in your tests.
And in test_helpers.exs
you need to add these two lines:
Documentation
Do not forget to document your library using @moduledoc
and @doc
attributes that are read by exdoc
library.
mix docs
Creates awesome Elixir library.
Publish To Hex
With the following two commands starts your Elixir glory:
mix hex.build
mix hex.publish
Your library is publically available on Hex.pm!