An Erlang library for Pocket API (www.getpocket.com) v3. For more details see documentation.
Project depends on jiffy library for JSON parsing and uses default HTTP client (httpc).
$ rebar3 update compile
or
$ rebar get-deps compile
New version breaks backward compatiblity due to replacing old jiffy style proplists with maps. This should be more convenient to use with latest versions of Erlang. Another big change is that API favors binary input over string input eg. for url when calling add API.
To run all required dependencies start with:
_ = application:ensure_all_started(erlpocket).
View the Error and Response Headers Documentation for detailed information about API errors. Also check the Rate Limits of API.
The Pocket API uses custom implementation of oAuth 2.0 for authentiaction. This library provide helper functions to authorize your application.
First you have to register your application to get consumer key.
RedirectUri = <<"http://www.foo.com/">>,
ConsumerKey = <<"app-consumer-key">>,
{ok, #{code := Code}} = erlpocket:request_token(ConsumerKey, RedirectUri).
Use returned security token (code) to get URL that will authorize your application on Pocket website.
Url = erlpocket:get_authorize_url(Code, RedirectUri).
{ok, #{access_token := AccessToken, username := Username}} = erlpocket:authorize(ConsumerKey, Code).
After sucessfull authentication you are ready call add/modify and retrieve functions.
You can also get content statistics, but it is just call on top of retrieve so it can take quite some time.
{ok, Stats} = erlpocket:stats(ConsumerKey, AccessToken).
Validate API params:
true = erlpocket:is_valid_param(add, #{title => <<"Foobar">>, url => <<"http://foobar">>}).
true = erlpocket:is_valid_param(retrieve, #{tag => <<"Foobar">>}).
To get content use following call:
{ok, Response} = erlpocket:retrieve(ConsumerKey, AccessToken, #{tag => <<"erlang">>}).
To validate retrieve query there is a helper:
true = erlpocket:is_valid_query(#{contentType => video}).
Add new content simply by calling:
{ok, #{<<"item"> := _}} = erlpocket:add(ConsumerKey, AccessToken, <<"http://foobar/">>).
or function with different arrity.
Update existing content. There are multiple helpers to ease work with this API call.
Delete an existing content:
ItemId = "123",
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:delete(ConsumerKey, AccessToken, ItemId).
Archive an existing content:
ItemId = <<"123">>,
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:archive(ConsumerKey, AccessToken, ItemId).
Mark an existing content as unread:
ItemId = <<"123">>,
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:readd(ConsumerKey, AccessToken, ItemId).
Mark an existing content as favorite:
ItemId = <<"123">>,
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:favorite(ConsumerKey, AccessToken, ItemId).
Remove an existing content from favorites:
ItemId = <<"123">>,
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:unfavorite(ConsumerKey, AccessToken, ItemId).
Add multiple tags to existing item:
ItemId = <<"123">>,
Tags = [<<"foo">>, <<"bar">>],
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:tags_add(ConsumerKey, AccessToken, ItemId, Tags).
Remove multiple tags from an existing item:
ItemId = "123",
Tags = [<<"foo">>],
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:tags_remove(ConsumerKey, AccessToken, ItemId, Tags).
Replace multiple tags from an existing item:
ItemId = <<"123">>,
NewTags = [<<"foo1">>, <<"bar1">>],
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:tags_replace(ConsumerKey, AccessToken, ItemId, NewTags).
Remove multiple tags from an existing item:
ItemId = <<"123">>,
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:tags_clear(ConsumerKey, AccessToken, ItemId).
Rename tag of an existing item:
ItemId = <<"123">>,
{ok, #{<<"action_results">> := [true], <<"status">> := 1}} = erlpocket:tag_rename(ConsumerKey, AccessToken, ItemId, <<"foo">>, <<"foo1">>).
For example usage of this library please refer to tests. Note that tests are are using real API endpoints (copy template api.sample.txt
as api.txt
and fill your Pocket Appplication creadentials there).