api

package
v0.0.0-...-18a76ad Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AuthURL                   = "https://my.remarkable.com"
	StorageDiscoveryURL       = "" /* 175-byte string literal not displayed */
	NotificationsDiscoveryURL = "" /* 172-byte string literal not displayed */
)

Default URLs

Variables

This section is empty.

Functions

func NewRepository

func NewRepository(c *Client, dataDir string) rmtool.Repository

NewRepository creates a Repository with the reMarkable cloud service as backend.

The supplied dataDir is used to cache downloaded content.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the ReST API for the reMarkable cloud service.

func DefaultClient

func DefaultClient(deviceToken string) *Client

DefaultClient sets up an API client with default URLs. See NewClient for details.

func NewClient

func NewClient(discoveryStorage, discoverNotif, authBase, deviceToken string) *Client

NewClient sets up an API client with the given base URLs.

The *three* URLs are the base URLs for the various services.

Device token is the authentication token obtained from the API. This is intended for setting up a client when the registration has already been completed and a token can be loaded from storage. If set to the empty string, Register can be used to obtain a token.

Refer to DefaultClient for a more simple constructor.

func (*Client) Bookmark

func (c *Client) Bookmark(id string, mark bool) error

Bookmark adds or removes a bookmark for the given item.

func (*Client) CreateFolder

func (c *Client) CreateFolder(parentID, name string) error

CreateFolder creates a new folder under the given parent folder. The parentID can be empty (root folder) or refer to another folder.

func (*Client) Delete

func (c *Client) Delete(id string) error

Delete a document or folder referred to by the given ID.

func (*Client) Fetch

func (c *Client) Fetch(id string, w io.Writer) (Item, error)

Fetch retrieves a single item from the service and writes the item's blob data to the given writer.

The caller is responsible for closing the writer.

func (*Client) IsRegistered

func (c *Client) IsRegistered() bool

IsRegistered tells if this client thinks it is registered. This merely looks if a device token is present; that token might still be invalid.

func (*Client) List

func (c *Client) List() ([]Item, error)

List retrieves the full list of items (notebooks and folders) from the service.

func (*Client) Move

func (c *Client) Move(id, parentID string) error

Move transfers the documents with the given id to a destination folder. The parentID can be empty (root folder) or refer to another folder.

func (*Client) NewNotifications

func (c *Client) NewNotifications() (*Notifications, error)

NewNotifications sets up a client for the notifications service.

This method will retrieve the hostname for the notification service from the discovery URL. If necessary, this method will also fetch a fresh authentication token for the notification service.

func (*Client) Register

func (c *Client) Register(code string) (string, error)

Register registers a new device with the remarkable service. It sends a one-time code from my.remarkable.com/connect/desktop and retrieves a "device token" which can later be used to authenticate.

Returns the device token.

func (*Client) Rename

func (c *Client) Rename(id, name string) error

Rename changes the name for an item.

func (*Client) Upload

func (c *Client) Upload(name, id, parentID string, src io.Reader) error

Upload adds a document to the given parent folder. The parentID can be empty (root folder) or refer to another folder.

type DateTime

type DateTime struct {
	time.Time
}

DateTime is the type used to serialize a Time instance to a date string and vice versa. Used when converting an Item to and from JSON.

func (DateTime) MarshalJSON

func (d DateTime) MarshalJSON() ([]byte, error)

MarshalJSON marsahls a DateTime to JSON.

func (*DateTime) UnmarshalJSON

func (d *DateTime) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshales a DateTime from JSON. The JSON date is expected to be a string in format "yyyy-mm-ddThh:mm:ss.sss".

type Event

type Event int

Event is the type for event types used in notification messages.

const (
	DocAdded Event = iota
	DocDeleted
)

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON marshals an Event to a JSON string value.

func (Event) String

func (e Event) String() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals an Event from a JSON string value.

type Item

type Item struct {
	// ID is the UUID for this item.
	ID string

	// Version is incremented with each update.
	Version int

	// Type describes the type of item (Notebook or Folder).
	Type rmtool.NotebookType

	// VisibleName is the display name for an item.
	VisibleName string `json:"VissibleName"`

	// CurrentPage is the last opened page from a notebook,
	CurrentPage int

	// Bookmarked tells if this item is "pinned".
	Bookmarked bool

	// Parent is the id of the parent item.
	// It can be the empty string if the item is contained in the root folder.
	// The special value "trash" is used for deleted items.
	Parent string

	// Success is set to false if this item is sent by the server as a response
	// to a request.
	Success bool

	// Message should contain the error message if Success is false.
	Message string

	// BlobURLGet is the download URL for the zipped content.
	BlobURLGet string

	// BlobURLGetExpires describes how long the download URL remains valid.
	BlobURLGetExpires DateTime

	// BlobURLPut is the upload URL for zipped content.
	BlobURLPut string

	// BlobURLGetExpires describes how long the upload URL remains valid.
	BlobURLPutExpires DateTime

	// ModifiedClient is the last modification date for this item.
	// It is set automatically when the Client is used to change items-
	ModifiedClient DateTime
}

Item holds the data for a single metadata entry from the API. The Item struct is also used by the service to send the response.

func (Item) Err

func (i Item) Err() error

Err returns the error from an API response, if this item was received as a response to an API request and contains Success = false. Returns nil if there is no error.

func (Item) Validate

func (i Item) Validate() error

type Message

type Message struct {
	MessageID   string
	PublishTime time.Time
	SourceDesc  string
	SourceID    string
	Event       Event
	ItemID      string
	Parent      string
	Type        rmtool.NotebookType
	Bookmarked  bool
	Version     int
	VisibleName string
}

Message contains the data from a notification message, slightly simplified.

type MessageHandler

type MessageHandler func(Message)

A MessageHandler can be registered with the notifications client to receive incoming messages.

type Notifications

type Notifications struct {
	// contains filtered or unexported fields
}

Notifications is the client for the notification service.

It connects to the websocket service, parses messages from JSON and forwards them to a registered message handler.

func (*Notifications) Connect

func (n *Notifications) Connect() error

Connect creates a new websocket connection to the notification service.

After a connection is made, the notifications client starts to receive messages and dispatches them to the MessageHandler registered via OnMessage.

Calling Connect while the client is already connected leads to a reconnect.

func (*Notifications) Disconnect

func (n *Notifications) Disconnect()

Disconnect closes the connection with the notification server. Calling Disconnect while the client is already disconnected has no effect.

func (*Notifications) OnMessage

func (n *Notifications) OnMessage(f MessageHandler)

OnMessage registers a handler function for received messages.

Setting a handler removes the current one; setting the handler to `nil` is allowed to remove the current handler.

The handler function will be called in a separate goroutine for each message.

Jump to

Keyboard shortcuts

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