Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Raynes/reap
A refheap API client library in Elixir.
https://github.com/Raynes/reap
Last synced: about 1 month ago
JSON representation
A refheap API client library in Elixir.
- Host: GitHub
- URL: https://github.com/Raynes/reap
- Owner: Raynes
- Created: 2013-08-01T04:57:56.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-27T22:53:40.000Z (about 10 years ago)
- Last Synced: 2024-10-28T12:00:21.182Z (about 2 months ago)
- Language: Elixir
- Size: 175 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Reap is a simple Elixir library for working with the refheap API. (Third Party APIs)
- fucking-awesome-elixir - reap - Reap is a simple Elixir library for working with the refheap API. (Third Party APIs)
- awesome-elixir - reap - Reap is a simple Elixir library for working with the refheap API. (Third Party APIs)
README
# Reap
Reap is a simple Elixir library for working with the
[refheap](https://www.refheap.com) API. It uses the excellent
[hackney](https://github.com/benoitc/hackney) HTTP client and
[JSEX](https://github.com/talentdeficit/jsex) JSON encoder/decoder.## Usage
Reap only has one function you should care about: `request/2`, `request/3`.
Here's some examples:```elixir
iex(1)> Reap.start
:ok
iex(2)> Reap.request(:post, "/paste", [contents: "foo"])
{:ok,
[{"lines", 1}, {"date", "2013-08-01T04:42:44.155Z"}, {"paste-id", "17091"},
{"fork", nil}, {"random-id", "6249eaf9c9c8186230243bb46"},
{"language", "Plain Text"}, {"private", false}, {"views", 0},
{"url", "https://www.refheap.com/17091"}, {"user", nil}, {"contents", "foo"}]}
iex(3)> Reap.request(:get, "/paste/17091")
{:ok,
[{"lines", 1}, {"date", "2013-08-01T04:42:44.155Z"}, {"paste-id", "17091"},
{"fork", nil}, {"random-id", "6249eaf9c9c8186230243bb46"},
{"language", "Plain Text"}, {"private", false}, {"views", 0},
{"url", "https://www.refheap.com/17091"}, {"user", nil}, {"contents", "foo"}]}
```As you can see, if the request and json decode is successful we get back `{:ok,
body}`. Let's see what happens if things go wrong:```elixir
iex(11)> Reap.request(:post, "/paste")
{:error, :refheap, [{"error", "Your paste cannot be empty."}]}
```In this case, something went wrong on refheap and it gave us back an error. The
second element of the tuple is the type of the error, and it can be `:refheap`
if something bad happens on refheap, `:json` if JSON parsing of the body fails
for some reason, or `:http` if we fail to make an http request at all. In the
latter two cases, the entire hackney response gets returned as the third element
of the tuple.