tchudyk / pocket-integration

(Java 1.8) API implementation of Pocket (getpocket.com)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pocket Java library

GetPocket-logo

This library allows to communicate with Pocket API.

License: BSD.

Maven

Add repository to your pom.xml:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Add dependency:

<dependency>
    <groupId>com.github.tchudyk</groupId>
    <artifactId>pocket-integration</artifactId>
    <version>1.2.1</version>
</dependency>

Usage

Authorization

PocketAuthFactory factory = PocketAuthFactory.create(consumerKey, "https://getpocket.com/");
String authorizationUrl = factory.getAuthUrl();
// Open here your WebBrowser with `authorizationUrl`... 
// ... when user add permission to your app, then create PocketAuth object. 
PocketAuth pocketAuth = factory.create();

You can also do this in separate steps:

PocketAuthFactory factory = PocketAuthFactory.create(consumerKey, "https://getpocket.com/");
String authCode = factory.getCode();
String authorizationUrl = factory.getAuthUrl();

After that open in your browser authorizationUrl... and after received permission:

PocketAuth pocketAuth = PocketAuthFactory.createForCode(consumerKey, authCode);
Pocket pocket = new Pocket(pocketAuth);

If authorization succeed, you can store somewhere in your application accessToken to use in later:

String accessToken = pocketAuth.getAccessToken();

When you have generated accessToken, you can use it to login, without asking user for his permission next time:

PocketAuth pocketAuth = PocketAuthFactory.createForAccessToken(consumerKey, accessToken);
Pocket pocket = new Pocket(pocketAuth);

Get List of Pocket items

GetItemsCmd cmd = new GetItemsCmd.Builder()
        .count(5)
        .build();
GetItemsResult getResult = pocket.getItems(cmd);
List<PocketItem> items = getResult.getList();

Add new bookmark to Pocket

pocket.addItem(
        new AddItemCmd.Builder("https://my-bookmark-url.com")
                .tags(Arrays.asList("tag1", "tag2"))
                .title("My bookmark title")
                .build()
);

Modify bookmarks in Pocket

PocketItem item = items.get(0);
pocket.modify(
        new ModifyItemCmd.Builder()
                .action(new TagsAddAction(item.getItemId(), "my-tag"))
                .action(new ArchiveAction(item.getItemId()))
                .build()
);

About

(Java 1.8) API implementation of Pocket (getpocket.com)

License:BSD 2-Clause "Simplified" License


Languages

Language:Java 100.0%