Packages
closex
0.7.0
2.1.0
2.0.1
2.0.0
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.0
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.5
1.0.4
1.0.3
1.0.2
1.0.0
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.0
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0
Close.io HTTP client for Elixir
Current section
Files
Jump to
Current section
Files
README.md
# Closex ✨
[](https://circleci.com/gh/nested-tech/closex/tree/master)
[](https://coveralls.io/github/nested-tech/closex.svg)
[](https://hex.pm/packages/closex)
[](https://hexdocs.pm/closex/)
Elixir wrapper for the Close.io API with optional caching support.
📔 Learn more about the Close.io API: [http://developer.close.io](http://developer.close.io)
📖 Documentation for this package is available on [HexDocs](https://hexdocs.pm/closex).
## Installation
Add `closex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:closex, ">= 0.0.0"} # or the current stable version
]
end
```
## Configuration
In your config.exs:
```elixir
config :closex,
api_key: "YOUR_API_KEY"
```
You can also read from an environment variable:
```elixir
config :closex,
api_key: {:system, "MY_ENV_VAR"}
```
## Usage
The client is essentially a wrapper around the Close.IO [REST API](https://developer.close.io/).
It follows the Close.IO API naming conventions as closely as possible. It supports almost everything that the REST API supports including querying leads, opportunities, users, organizations, statuses and more.
Example usage:
```elixir
# Get a lead
Closex.HTTPClient.get_lead("my_lead_id")
{:ok, %{"id" => "my_lead_id", "status_id" => "my_status_id", ...}}
# Update a lead
Closex.HTTPClient.update_lead("my_lead_id", %{status_id: "new_status_id"})
{:ok, %{"id" => "my_lead_id", "status_id" => "new_status_id", ...}}
# With caching
:timer.tc fn -> Closex.CachingClient.get_opportunity_statuses end
{907682, {:loaded, {:ok, %{"data" => [% ...lots of data... ]}}}}
# 900ms response time
:timer.tc fn -> Closex.CachingClient.get_opportunity_statuses end
{17, {:loaded, {:ok, %{"data" => [% ...lots of data... ]}}}}
# 17us response time with caching
# many more ...
```
See [the docs](https://hexdocs.pm/closex) for more examples.
You may also want to set the default client you want to use in your applicaton, either HTTPClient
or CachingClient, via your config:
```
# your_app/config/config.exs
config :yourapp,
closeio_client: Closex.HTTPClient,
...other configuration...
```
Next, use it in your code:
```
# your_app/lib/module_which_uses_closeio.ex
defmodule YourApp.ModuleWhichUsesCloseIO do
@closeio_client Application.fetch_env!(:your_app, :closeio_client)
def do_things_with_a_close_io_lead(id) do
@closeio_client.get_lead(id)
# do things
end
end
```
## Mock Client
We have provided a mock client for testing purposes in your application.
Using the above configuration will allow you to override and use the `Closex.MockClient` in test mode.
```
# your_app/config/test.exs
config :yourapp,
closeio_client: Closex.MockClient,
...other configuration...
```
For more details on the mock client please see [the docs](https://hexdocs.pm/closex).
## Options
Options will be passed through to [HTTPoison](https://github.com/edgurgel/httpoison#options). For example, to set a shorter timeout:
```elixir
Closex.HTTPClient.get_lead("my_lead_id", timeout: 500, recv_timeout: 1_000)
```
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
- Please use the git hooks provided in the hooks directory. Use the following command to set these hooks up.
```
ln -s ../../hooks/pre-commit.sh .git/hooks/pre-commit
```
## License
MIT
## Copyright
Copyright NextDayProperty Ltd (see LICENSE for details)