179 lines
No EOL
5.6 KiB
Markdown
179 lines
No EOL
5.6 KiB
Markdown
# [Pinboard](https://pinboard.in) Poster for Kotlin/Java
|
|
|
|
[](http://opensource.org/licenses/BSD-3-Clause) [](https://github.com/ethauvin/pinboard-poster/releases/latest) [](https://bintray.com/ethauvin/maven/pinboard-poster/_latestVersion)
|
|
[](https://snyk.io/test/github/ethauvin/pinboard-poster?targetFile=pom.xml) [](https://travis-ci.org/ethauvin/pinboard-poster) [](https://circleci.com/gh/ethauvin/pinboard-poster/tree/master)
|
|
|
|
A small Kotlin/Java library for posting to [Pinboard](https://pinboard.in).
|
|
|
|
## Examples
|
|
|
|
### Kotlin
|
|
|
|
```kotlin
|
|
|
|
val poster = PinboardPoster("user:TOKEN")
|
|
|
|
poster.addPin("http://www.example.com/foo", "This is a test")
|
|
poster.deletePin("http:///www.example.com/bar")
|
|
|
|
```
|
|
[View Example](https://github.com/ethauvin/pinboard-poster/blob/master/samples/kotlin/src/main/kotlin/net/thauvin/erik/pinboard/samples/KotlinExample.kt)
|
|
|
|
### Java
|
|
```java
|
|
|
|
final PinboardPoster poster = new PinBboardPoster("user:TOKEN");
|
|
|
|
poster.addPin("http://www.example.com/foo", "This is a test");
|
|
poster.deletePin("http:///www.example.com/bar");
|
|
```
|
|
[View Example](https://github.com/ethauvin/pinboard-poster/blob/master/samples/java/src/main/java/net/thauvin/erik/pinboard/samples/JavaExample.java)
|
|
|
|
Your API authentication token is available on the [Pinboard settings page](https://pinboard.in/settings/password).
|
|
|
|
## Usage with Maven, Gradle and Kobalt
|
|
|
|
### Maven
|
|
|
|
To install and run from Maven, configure an artifact as follows:
|
|
|
|
```xml
|
|
<dependency>
|
|
<groupId>net.thauvin.erik</groupId>
|
|
<artifactId>pinboard-poster</artifactId>
|
|
<version>1.0.0</version>
|
|
</dependency>
|
|
```
|
|
|
|
### Gradle
|
|
|
|
To install and run from Gradle, add the following to the build.gradle file:
|
|
|
|
```gradle
|
|
dependencies {
|
|
compile 'net.thauvin.erik:pinboard-poster:1.0.0'
|
|
}
|
|
```
|
|
[View Example](https://github.com/ethauvin/pinboard-poster/blob/master/samples/java/build.gradle)
|
|
[View Kotlin DSL Example](https://github.com/ethauvin/pinboard-poster/blob/master/samples/kotlin/build.gradle.kts)
|
|
|
|
### Kobalt
|
|
|
|
To install and run from Kobalt, add the following to the Build.kt file:
|
|
|
|
```gradle
|
|
dependencies {
|
|
compile("net.thauvin.erik:pinboard-poster:1.0.0")
|
|
}
|
|
```
|
|
[View Example](https://github.com/ethauvin/pinboard-poster/blob/master/samples/kotlin/kobalt/src/Build.kt)
|
|
|
|
## Adding
|
|
|
|
The `addPin` function support all of the [Pinboard API parameters](https://pinboard.in/api/#posts_add):
|
|
|
|
```kotlin
|
|
poster.addPin(url = "http://www.example.com",
|
|
description = "This is the title",
|
|
extended = "This is the extended description.",
|
|
tags = "tag1 tag2 tag3",
|
|
dt = "2010-12-11T19:48:02Z",
|
|
replace = true,
|
|
shared = true,
|
|
toRead = false)
|
|
```
|
|
|
|
`url` and `description` are required.
|
|
|
|
It returns `true` if the bookmark was added successfully, `false` otherwise.
|
|
|
|
## Deleting
|
|
|
|
The `deletePin` function support all of the [Pinboard API parameters](https://pinboard.in/api/#posts_delete):
|
|
|
|
```kotlin
|
|
poster.deletePin(url = "http://www.example.com/")
|
|
```
|
|
|
|
It returns `true` if the bookmark was deleted successfully, `false` otherwise.
|
|
|
|
## Logging
|
|
|
|
The library used [`java.util.logging`](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html) to log errors. Logging can be configured as follows:
|
|
|
|
#### Kotlin
|
|
```kotlin
|
|
with(poster.logger) {
|
|
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
|
level = Level.FINE
|
|
}
|
|
```
|
|
#### Java
|
|
```java
|
|
final ConsoleHandler consoleHandler = new ConsoleHandler();
|
|
consoleHandler.setLevel(Level.FINE);
|
|
final Logger logger = poster.getLogger();
|
|
logger.addHandler(consoleHandler);
|
|
logger.setLevel(Level.FINE);
|
|
```
|
|
|
|
or using a logging properties file.
|
|
|
|
## API Authentication Token
|
|
|
|
The token can also be located in a [properties file](https://en.wikipedia.org/wiki/.properties) or environment variable.
|
|
|
|
### Local Property
|
|
|
|
For example, using the default `PINBOARD_API_TOKEN` key value from a `local.properties` file:
|
|
|
|
```ini
|
|
# local.properties
|
|
PINBOARD_API_TOKEN=user\:TOKEN
|
|
```
|
|
|
|
```kotlin
|
|
val poster = PinboardPoster(Paths.get("local.properties"))
|
|
```
|
|
|
|
or by specifying your own key:
|
|
|
|
```ini
|
|
# my.properties
|
|
my.api.key=user\:TOKEN
|
|
```
|
|
|
|
```kotlin
|
|
val poster = PinboardPoster(Paths.get("my.properties"), "my.api.key")
|
|
```
|
|
|
|
or even specifying your own property:
|
|
|
|
```kotlin
|
|
val p = Properties()
|
|
p.setProperty("api.key", "user:TOKEN")
|
|
|
|
val poster = PinboardPoster(p, "api.key")
|
|
```
|
|
|
|
_In all cases, the value of the `PINBOARD_API_TOKEN` environment variable is used by default if the specified property is invalid or not found._
|
|
|
|
### Environment Variable
|
|
|
|
If no arguments are passed to the constructor, the value of the `PINBOARD_API_TOKEN` environment variable will be used, if any.
|
|
|
|
```sh
|
|
export PINBOARD_API_TOKEN="user:TOKEN"
|
|
```
|
|
|
|
```kotlin
|
|
val poster = PinboardPoster()
|
|
```
|
|
|
|
## API End Point
|
|
|
|
The API end point is automatically configured to `https://api.pinboard.in/v1/`. Since Pinboard uses the `del.ico.us` API, the library could potentially be used with another compatible service. To configure the API end point, use:
|
|
|
|
```kotlin
|
|
poster.apiEndPoint = "https://www.example.com/v1"
|
|
``` |