pocket2rm

package module
v0.0.0-...-a8a18e0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: MIT Imports: 12 Imported by: 0

README

* Pocket2RM

** Authorisation process

   + Load the access token (app - loadToken)
   + If that fails then we need to re-auth (app - authWithPocket)
     1. Load the consumer code (p2rm)
     2. Get a request token (p2rm)
     3. Redirect user to oauth url (app)
        1. Get the URL
        2. Start a local listener
        3. Give the user the URL
        4. Listen for a response
     4. Get callback from pocket (app)
     5. Convert request token into access token (p2rm)

** Authorising via Pocket website

#+BEGIN_SRC sh
curl "https://getpocket.com/auth/authorize?redirect_uri=localhost&request_token=REQUEST_TOKEN"
#+END_SRC
code:81fd2224-564a-7989-f0af-bcd6f5

** reMarkable API

Started working from here:
https://github.com/splitbrain/ReMarkableAPI/wiki/Authentication


* Dependencies

#+BEGIN_SRC sh
go get github.com/jacobstr/confer
go get github.com/mattn/go-sqlite3
go get github.com/jung-kurt/gofpdf
#+END_SRC

* Links

https://github.com/reHackable/awesome-reMarkable#apis

Documentation

Index

Constants

View Source
const APIOriginMercury = "mercury"

APIOriginMercury is the origin host for the Mercury API

View Source
const APIOriginPocket = "pocket"

APIOriginPocket contains the destination

View Source
const APIOriginRemarkable = "remarkable"

APIOriginRemarkable is the origin host for the reMarkable API

Variables

View Source
var APIOrigin = map[string]string{
	APIOriginPocket:     "https://getpocket.com",
	APIOriginMercury:    "https://mercury.postlight.com",
	APIOriginRemarkable: "",
}

APIOrigin maps each origin host name

View Source
var ConfigFile = os.ExpandEnv("$HOME/.config/pocket2rm.yaml")

ConfigFile contains the default configuration file

View Source
var DatastoreFile = os.ExpandEnv("$HOME/.config/pocket2rm.db")

DatastoreFile contains the path to the SQLite3 database

View Source
var NullTime = time.Unix(0, 0)

NullTime is used to indicate an unset time.

View Source
var PocketAccessFile = os.ExpandEnv("$HOME/.config/pocket2rm.access.json")

AccessFile contains the access token file

View Source
var RMAccessFile = os.ExpandEnv("$HOME/.config/pocket2rm.access.rm.json")

AccessFile contains the access token file

Functions

func Authorise

func Authorise(consumerKey string) (string, error)

Authorise carries out an auth call to Pocket to get a token

func CleanCRLF

func CleanCRLF(inp string) string

CleanCRLF removes any CR/LF characters and replaces them with spaces

func CreatePDF

func CreatePDF(outputPath string, ad *ArticleDetails) (string, error)

CreatePDF generates a simple PDF from the ArticleDetails

func FixForFileName

func FixForFileName(inp string) string

FixForFileName replaces any illegal characters in the supplied string to allow it to be used as a filename.

func GenerateAuthURL

func GenerateAuthURL(code string, redirect string) string

GenerateAuthURL will return the URL to redirect the user to in order to authorise the app with Pocket

func GenerateOutputFilename

func GenerateOutputFilename(outputPath string, source string) (string, error)

GenerateOutputFilename returns a full output path

func GetJSON

func GetJSON(url string, origin string, headers map[string]string, res interface{}) error

GetJSON sends a GET request to the specified URL and receives JSON in response

func LoadJSONFromFile

func LoadJSONFromFile(path string, v interface{}) error

LoadJSONFromFile loads the JSON file into the supplied interface{}

func PostJSON

func PostJSON(url string, origin string, data, res interface{}) error

PostJSON creates a POST request with the supplied data, and sends it using sendJSON.

func SaveJSONToFile

func SaveJSONToFile(path string, v interface{}) error

SaveJSONToFile dumps the supplied struct to the file in JSON format

Types

type AccessToken

type AccessToken struct {
	Token    string `json:"access_token"`
	Username string `json:"username"`
}

AccessToken stores the returned access token and user name from an access call

func GetAccessToken

func GetAccessToken(consumerKey string, requestToken *RequestToken) (*AccessToken, error)

GetAccessToken will retrieve an access token from Pocket

type ArticleDetails

type ArticleDetails struct {
	Title         string `json:"title"`
	Content       string `json:"content"`
	Author        string `json:"author"`
	DatePublished string `json:"date_published"`
	LeadImageURL  string `json:"lead_image_url"`
	Dek           string `json:"dek"`
	URL           string `json:"url"`
	Domain        string `json:"domain"`
	Excerpt       string `json:"excerpt"`
	WordCount     int    `json:"word_count"`
	Direction     string `json:"direction"`
	TotalPages    int    `json:"total_pages"`
	RenderedPages int    `json:"rendered_pages"`
}

ArticleDetails contains details about a URL, usually from the Mercury API

type Item

type Item struct {
	ItemID        int        `json:"item_id,string"`
	ResolvedID    int        `json:"resolved_id,string"`
	GivenURL      string     `json:"given_url"`
	ResolvedURL   string     `json:"resolved_url"`
	GivenTitle    string     `json:"given_title"`
	ResolvedTitle string     `json:"resolved_title"`
	Favorite      int        `json:",string"`
	Status        ItemStatus `json:",string"`
	Excerpt       string
	IsArticle     int `json:"is_article,string"`
	// HasImage      ItemMediaAttachment `json:"has_image,string"`
	// HasVideo      ItemMediaAttachment `json:"has_video,string"`
	WordCount int `json:"word_count,string"`

	// Fields for detailed response
	Tags    map[string]map[string]interface{}
	Authors map[string]map[string]interface{}
	Images  map[string]map[string]interface{}
	Videos  map[string]map[string]interface{}
}

Item contains all the data returned

type ItemStatus

type ItemStatus int

ItemStatus is a typedef wrapping the status of an item

type Pocket2RM

type Pocket2RM struct {
	Config       *confer.Config
	ConsumerKey  string
	RequestToken *RequestToken
	AccessToken  *AccessToken
	RMToken      *RMToken
	// contains filtered or unexported fields
}

Pocket2RM contains the interface to the Pocket2RM API

func (*Pocket2RM) AddArticle

func (p *Pocket2RM) AddArticle(itemID string, pocketArticles map[string]Item)

AddArticle will retrieve the HTML, generate a PDF, and upload it to RM

func (*Pocket2RM) GeneratePDF

func (p *Pocket2RM) GeneratePDF(ad *ArticleDetails) (string, error)

GeneratePDF creates a PDF from the supplied ArticleDetails

func (*Pocket2RM) GetAccessToken

func (p *Pocket2RM) GetAccessToken()

GetAccessToken carries out an OAUTH call to Pocket to get a token

func (*Pocket2RM) GetArticleDetails

func (p *Pocket2RM) GetArticleDetails(articleURL string, details *ArticleDetails) error

GetArticleDetails will use the Mercury API to retrieve details of the article, using the provided URL

func (*Pocket2RM) GetRequestToken

func (p *Pocket2RM) GetRequestToken()

GetRequestToken calls into the API to get an initial request token

func (*Pocket2RM) Init

func (p *Pocket2RM) Init()

Init performs any initialisation (such as loading API keys etc).

func (*Pocket2RM) ListFromRemarkable

func (p *Pocket2RM) ListFromRemarkable() (string, error)

ListFromRemarkable will pull a list from the RM cloud

func (*Pocket2RM) PullFromPocket

func (p *Pocket2RM) PullFromPocket(count int)

PullFromPocket retrieves a list of the articles from pocket and compares against local state.

type PocketCode

type PocketCode struct {
	Code string `json:"code"`
}

PocketCode contains the code returned from the first Pocket auth call.

type RMToken

type RMToken struct {
	Token string `json:"token"`
}

RMToken is a reMarkable access token

func GetRMToken

func GetRMToken(code string, deviceDesc string, deviceID string) (*RMToken, error)

GetRMToken will retrieve an access token from Pocket

type RequestToken

type RequestToken struct {
	Code string `json:"code"`
}

RequestToken stores the initial request token

func GetRequestToken

func GetRequestToken(consumerKey string) (*RequestToken, error)

GetRequestToken will retrieve a RequestToken from Pocket

type RetrieveResult

type RetrieveResult struct {
	List     map[string]Item
	Status   int
	Complete int
	Since    int
}

RetrieveResult contains the response from a GET request

func PullArticles

func PullArticles(consumerKey string, accessToken *AccessToken, count int) (*RetrieveResult, error)

PullArticles retrieves a list of articles

Directories

Path Synopsis
cmd
pocket2rm command

Jump to

Keyboard shortcuts

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