GithubHelp home page GithubHelp logo

gmile / pocketeer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from justahero/pocketeer

0.0 3.0 0.0 115 KB

A client library for the Pocket API written in Elixir

License: MIT License

Elixir 100.00%

pocketeer's Introduction

Pocketeer

Build Status

A client library for the getpocket.com service written in Elixir. The library supports all endpoints of the Pocket API. It also supports modifying mulitple items in a bulk operation.

If you want to picture how Pocketeer might look, Pixar's character with the same name from the short movie Toy Story Of Terror! is a really good fit.

Installation

If available in Hex, the package can be installed as:

  1. Add pocketeer to your list of dependencies in mix.exs:
def deps do
  [{:pocketeer, "~> 0.1.5"}]
end
  1. Ensure pocketeer is started before your application:
def application do
  [applications: [:pocketeer]]
end

Authentication

To use the Pocket API, first the authentication process needs to be done, by using the consumer key to retrieve an access token. Both are required to use the API.

For this your application needs to be registered on the Pocket Developers page. Once the application is registered the consumer key is displayed on the My Applications page. For more details check the Authorization process on Pocket.

Your application should offer a page where users are redirected to after confirming or declining the authorization request by Pocket.

The following steps show how to use the consumer key to get an access token.

  1. Fetch request_token from Pocket.
{:ok, body} = Pocketeer.Auth.get_request_token(consumer_key, "http://yoursite.com")
#=> {:ok, %{"code" => "abcd", "state" => nil}}
request_token = body["code"]
#=> "abcd"
  1. With this token, redirect the user to the authorization page of your application.
# a helper function can be used to construct the url.
Pocketeer.Auth.authorize_url("abcd", "http://yoursite.com")
#=> "https://getpocket.com/v3/oauth/authorize?request_token=abcd&redirect_uri=http%3A%2F%2Fyoursite.com"
  1. Get an access_token after the user accepts the authorization.
{:ok, body} = Pocketeer.Auth.get_access_token(consumer_key, request_token)
#=> {:ok, %{"access_token" => "efgh", "username" => "pocketuser"}}
access_token = body["access_token"]
#=> "egfh"

For more detailed handling of the request above:

response = Pocketeer.Auth.get_request_token(consumer_key, "http://yoursite.com")
case response do
  {:ok, body}     -> body["code"]
  {:error, error} -> IO.puts "Error: #{error.message}"
end

Usage

Once the consumer_key and access_token are available, the API offers different functions, categorized into Add, Modify and Retrieve.

To save a new item in Pocket:

# with url
Pocketeer.add(client, %{url: "http://example.com", title: "Test", tags: ["news", "test"]})
%{:ok, %{"item" => { ... }}}
# with existing item id
Pocketeer.add(client, %{item_id: "1234", title: "Saved before", tweet_id: "tweet_id"})
%{:ok, %{"item" => { ... }}}

To fetch the list of the last 10 oldest favorited videos.

options = Pocketeer.Get.new(%{sort: :oldest, count: 10, contentType: :video, favorite: true})
{:ok, response} = Pocketeer.get(client, options)

To delete an item and also add tags to another item, executed in a bulk operation

Item.new
|> Item.delete("1234")
|> Item.tags_add("4444", ["great", "stuff"])
|> Pocketeer.post(client)
{:ok, %{"action_results" => [true, true], "status" => 1}}

Other libraries

There are other libraries out there worth checking out:

Licene

This software is licensed under MIT License.

pocketeer's People

Contributors

justahero avatar tsubery avatar yasuhiroki avatar

Watchers

Ievgen Pyrogov avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.