Pocket API for Swift.
Before you can use the API, you need to obtain a consumer key.
You can start using the package by creating a new Pocket
instance and passing your consumer key:
let pocket = Pocket(consumerKey: "...")
The instance needs to be authenticated with the user's account. This is done via the user's consent in the browser.
- Obtain a request token that you can later use to obtain your access token.
- Listen on the redirect url you provided to notice when the authorization has been granted by the user.
- Direct the user to the authorization url.
- You can obtain your access token.
// (1)
let requestToken = try await pocket.obtainRequestToken(forRedirectingTo: redirectUrl)
// (2)
// Listen on your redirectUrl, e.g. "http://localhost:44444/callback" using a local webserver
// (3)
let authorizationUrl = pocket.buildAuthorizationUrl(for: requestToken, redirectingTo: redirectUrl)
// (4)
let accessToken = try await pocket.obtainAccessToken(for: requestToken)
Using that instance, you can invoke actions against the api.
You can retrieve the access token from the accessToken
property.
Use this to save and restore the token for future uses.
let parameters = Pocket.AddParameters(url: url)
// add parameters by configuring the AddParameters object
try await pocket.add(item: parameters)
let parameters = Pocket.RetrieveParameters()
// change filter options by configuring the RetrieveParameters object
let items = try await pocket.retrieve(with: parameters)
let itemId = 123
try await pocket.archive(itemIds: [itemId])
Using the Swift Package Manager, add this line to your Package.swift
as a dependency:
.package(url: "https://github.com/sgade/swift-pocket", from: "1.0.0"),
See LICENSE
file.