instapaper

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrRateLimitExceeded    = 1040 // Rate-limit exceeded
	ErrNotPremiumAccount    = 1041 // Premium account required
	ErrApplicationSuspended = 1042 // Application is suspended

	ErrFullContentRequired      = 1220 // Domain requires full content to be supplied
	ErrDomainNotSupported       = 1221 // Domain has opted out of Instapaper compatibility
	ErrInvalidURL               = 1240 // Invalid URL specified
	ErrInvalidBookmarkID        = 1241 // Invalid or missing bookmark_id
	ErrInvalidFolderID          = 1242 // Invalid or missing folder_id
	ErrInvalidProgress          = 1243 // Invalid or missing progress
	ErrInvalidProgressTimestamp = 1244 // Invalid or missing progress_timestamp
	ErrSuppliedContentRequired  = 1245 // Private bookmarks require supplied content
	ErrUnexpected               = 1250 // Unexpected error when saving bookmark

	ErrInvalidTitle              = 1250 // Invalid or missing title
	ErrDuplicateFolder           = 1251 // User already has a folder with this title
	ErrCannotAddBookmarkToFolder = 1252 // Cannot add bookmarks to this folder

	ErrGeneric = 1500 // Unexpected service error
	ErrTextGen = 1550 // Error generating text version of this URL

	ErrEmptyText          = 1600 // Cannot create highlight with empty text
	ErrDuplicateHighlight = 1601 // Duplicate highlight

	ErrNotAuthenticated = 666 // The client did not authenticate
	ErrUnmarshalError   = 667 // Cannot unmarshal the response from Instapaper's API
	ErrHTTPError        = 668 // A generic HTTP error
)
View Source
const FolderIDArchive = "archive"

FolderIDArchive is a built-in folder for archived bookmarks

View Source
const FolderIDStarred = "starred"

FolderIDStarred is a built-in folder for starred bookmarks

View Source
const FolderIDUnread = "unread"

FolderIDUnread is the default folder - unread bookmarks

Variables

View Source
var DefaultBookmarkListRequestParams = BookmarkListRequestParams{
	Limit:           500,
	Skip:            nil,
	CustomHaveParam: "",
	Folder:          FolderIDUnread,
}

DefaultBookmarkListRequestParams provides sane defaults - no filtering and the maximum limit of 500 bookmarks

Functions

This section is empty.

Types

type APIError

type APIError struct {
	ErrorCode    int `json:"error_code"`
	StatusCode   int
	Message      string
	WrappedError error
}

APIError represents an error returned by the Instapaper API - a numeric code and a message

func (*APIError) Error

func (r *APIError) Error() string

type Bookmark

type Bookmark struct {
	Hash              string
	Description       string
	ID                int    `json:"bookmark_id"`
	PrivateSource     string `json:"private_source"`
	Title             string
	URL               string
	ProgressTimestamp int64 `json:"progress_timestamp"`
	Time              int64
	Progress          float32
	Starred           string
}

Bookmark represents a single bookmark entry

type BookmarkAddRequestParams

type BookmarkAddRequestParams struct {
	URL               string
	Title             string
	Description       string
	Folder            string
	ResolveFinalURL   bool
	Content           string
	PrivateSourceName string
}

BookmarkAddRequestParams represents all the parameters you can pass when adding a new bookmark Either URL or Content or a (Content, PrivateSourceName) pair is mandatory.

type BookmarkListRequestParams

type BookmarkListRequestParams struct {
	Limit           int
	Skip            []Bookmark
	SkipHighlights  []Highlight
	CustomHaveParam string
	Folder          string
}

BookmarkListRequestParams defines filtering and limiting options for the List endpoint. see DefaultBookmarkListRequestParams for a set of sane defaults

type BookmarkListResponse

type BookmarkListResponse struct {
	Bookmarks   []Bookmark
	Highlights  []Highlight
	RawResponse string
}

BookmarkListResponse represents the useful part of the API response for the bookmark list endpoint

type BookmarkService

type BookmarkService struct {
	Client Client
}

BookmarkService is the implementation of the bookmark related parts of the API client, conforming to the BookmarkService interface

func (*BookmarkService) Add

Add adds a new bookmark from the specified URL

func (*BookmarkService) Archive

func (svc *BookmarkService) Archive(bookmarkID int) error

Archive archives the specified bookmark

func (*BookmarkService) DeletePermanently

func (svc *BookmarkService) DeletePermanently(bookmarkID int) error

DeletePermanently PERMANENTLY deletes the specified bookmark

func (*BookmarkService) GetText

func (svc *BookmarkService) GetText(bookmarkID int) (string, error)

GetText returns the specified bookmark's processed text-view HTML, which is always text/html encoded as UTF-8.

func (*BookmarkService) List

List returns the list of bookmarks. By default it returns (maximum) 500 of the unread bookmarks see BookmarkListRequestParams for filtering options

func (*BookmarkService) Move

func (svc *BookmarkService) Move(bookmarkID int, folderID string) error

Move moves the specified bookmark to the specified folder

func (*BookmarkService) Star

func (svc *BookmarkService) Star(bookmarkID int) error

Star stars the specified bookmark

func (*BookmarkService) UnArchive

func (svc *BookmarkService) UnArchive(bookmarkID int) error

UnArchive un-archives the specified bookmark

func (*BookmarkService) UnStar

func (svc *BookmarkService) UnStar(bookmarkID int) error

UnStar un-stars the specified bookmark

func (*BookmarkService) UpdateReadProgress

func (svc *BookmarkService) UpdateReadProgress(bookmarkID int, progress float32, when int64) error

UpdateReadProgress updates the read progress on the bookmark progress is between 0.0 and 1.0 - a percentage when - Unix timestamp - optionally specify when the update happened. If it's set to 0 the current timestamp is used.

type Client

type Client struct {
	OAuthClient oauth.Client
	Username    string
	Password    string
	Credentials *oauth.Credentials
	BaseURL     string
}

Client represents the API client and is used directly by the specific API endpoint client implementations

func NewClient

func NewClient(consumerID string, consumerSecret string, username string, password string) (Client, error)

NewClient configures a new Client and returns it. This is the preferred way to get a new client.

func (*Client) Authenticate

func (svc *Client) Authenticate() error

Authenticate uses the client ID and secret plus the username/password to get oAuth tokens with which it can make authenticated calls in the future

func (*Client) Call

func (svc *Client) Call(path string, params url.Values) (*http.Response, error)

Call makes a call to the Instapaper API on the specific path with the given call parameters. It handles errors converting them to an APIError instance

type ClientIf

type ClientIf interface {
	Authenticate() error
}

ClientIf represents the interface an Instapaper API client needs to implement

type Folder

type Folder struct {
	ID           json.Number `json:"folder_id"`
	Title        string
	Slug         string
	DisplayTitle string `json:"display_title"`
	SyncToMobile int    `json:"sync_to_mobile"`
	Position     json.Number
}

Folder represents a folder on Instapaper - there are 3 default ones, see FolderIDUnread, FolderIDStarred and FolderIDArchive

type FolderService

type FolderService struct {
	Client Client
}

FolderService encapsulates all folder operations

func (*FolderService) Add

func (svc *FolderService) Add(title string) (*Folder, error)

Add creates a folder and returns with it if there wasn't already one with the same title - in that case it returns an error

func (*FolderService) Delete

func (svc *FolderService) Delete(folderID string) error

Delete removes a folder and moves all of its bookmark entries to the archive

func (*FolderService) List

func (svc *FolderService) List() ([]Folder, error)

List returns the list of *custom created* folders. It does not return any of the built in ones!

func (*FolderService) SetOrder

func (svc *FolderService) SetOrder(folderOrderlist string) ([]Folder, error)

SetOrder sets the order of the user-created folders. Format: folderid1:order1,folderid2:order2,...,folderidN,orderN example: 100:1,200:2,300:3 the order of the pairs in the list does not matter. You should include all folders for consistency. !!!No errors returned for missing or invalid folders!!!

type Highlight

type Highlight struct {
	ID         int `json:"highlight_id"`
	BookmarkID int `json:"bookmark_id"`
	Text       string
	Note       string
	Time       json.Number
	Position   int
}

Highlight represents a highlight within a bookmark

type HighlightService

type HighlightService struct {
	Client Client
}

func (*HighlightService) Add

func (svc *HighlightService) Add(bookmarkID int, text string, position int) (*Highlight, error)

Add adds a highlight for the specified bookmark

func (*HighlightService) Delete

func (svc *HighlightService) Delete(highlightID int) error

Delete removes the specified highlight

func (*HighlightService) List

func (svc *HighlightService) List(bookmarkID int) ([]Highlight, error)

List fetches all highlights for the specified bookmark

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL