https://github.com/allyedge/exbitly
An Elixir library to interact with the Bitly API.
https://github.com/allyedge/exbitly
bitly bitly-api elixir elixir-library
Last synced: about 1 year ago
JSON representation
An Elixir library to interact with the Bitly API.
- Host: GitHub
- URL: https://github.com/allyedge/exbitly
- Owner: Allyedge
- License: mit
- Created: 2022-06-19T17:52:20.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-19T21:36:02.000Z (about 4 years ago)
- Last Synced: 2023-12-08T16:15:44.891Z (over 2 years ago)
- Topics: bitly, bitly-api, elixir, elixir-library
- Language: Elixir
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exbitly
[](https://hex.pm/packages/exbitly)
[](https://hex.pm/packages/exbitly)
An Elixir library to interact with the Bitly API.
## Installation
To use Exbitly, you first have to add it to your `mix.exs` dependencies.
```elixir
defp deps do
[
{:exbitly, "~> 0.1.0"}
]
end
```
After that, you have to create a `config` folder and a `config.exs` file inside that folder.
Then, pass the code below inside the `config.exs` file and add your token in it.
```elixir
import Config
config :exbitly,
token: ""
```
Without the `config.exs` file, you won't be able to shorten URLs.
## Usage
You can use `shorten/2` to shorten a URL.
```elixir
Exbitly.shorten("bit.ly", "https://www.example.com")
# {:ok, "http://bit.ly/short_url"}
Exbitly.shorten("random", "https://www.example.com")
# {:error, %{
# "description" => "The value provided is invalid.",
# "errors" => [%{"error_code" => "invalid", "field" => "domain"}],
# "message" => "INVALID_ARG_DOMAIN",
# "resource" => "bitlinks"
# }}
```
If you prefer exceptions, you can always use `shorten!/2` instead of `shorten/2`.
```elixir
Exbitly.shorten!("bit.ly", "https://www.example.com")
# {:ok, "http://bit.ly/short_url"}
Exbitly.shorten!("random", "https://www.example.com")
# ** (Exbitly.Error) An error occured while shortening the URL. Message: INVALID_ARG_DOMAIN - Description: The value provided is invalid.
```
## License
Copyright (c) 2022-present Alim Arslan Kaya.
Exbitly is licensed under the MIT license.