Documentation ¶
Overview ¶
Package rmapi implements reMarkable api, as described in https://github.com/splitbrain/ReMarkableAPI/wiki.
Index ¶
- Constants
- Variables
- func GenerateIndex(entries []IndexEntry) *bytes.Buffer
- type APIRequest
- type APIResponse
- type Client
- func (c *Client) AutoRefresh(ctx context.Context) error
- func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (c *Client) Download15(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) DownloadIndex(ctx context.Context, path string) ([]IndexEntry, error)
- func (c *Client) DownloadRoot(ctx context.Context) (entries []IndexEntry, generation string, err error)
- func (c *Client) ListDirs(ctx context.Context) (map[string]string, error)
- func (c *Client) Refresh(ctx context.Context) error
- func (c *Client) UpdateRoot(ctx context.Context, generation string, path string) error
- func (c *Client) Upload(ctx context.Context, args UploadArgs) error
- func (c *Client) Upload15(ctx context.Context, content io.Reader) (path string, size int64, err error)
- type ContentArgs
- type FileType
- type IndexEntry
- type Metadata
- type RegisterArgs
- type TimestampMillisecond
- type UploadArgs
Constants ¶
const ( // api urls APIBase = "https://rm-blob-storage-prod.appspot.com/api/v1" APIDownload = APIBase + "/signed-urls/downloads" APIUpload = APIBase + "/signed-urls/uploads" APISyncComplete = APIBase + "/sync-complete" // magic strings used in index files. IndexFileFirstMagic = "3" RootEntryUnused1Magic = "80000000" IndexEntryUnused1Magic = "0" // http headers HeaderRootGeneration = "x-goog-generation" // magic numbers NumEntrySplit = 5 GCSPathBytes = 32 )
Constants used in reMarkable 1.5 API.
const ( APIResponseKeyPath = "relative_path" APIResponseKeyURL = "url" APIResponseKeyMethod = "method" APIResponseKeyExpires = "expires" )
APIResponse special keys
const MetadataSuffix = ".metadata"
MetadataSuffix is the suffix (file extension) used by metadata files.
Variables ¶
var RootDisplayName = "<ROOT>"
RootDisplayName is the display name to be used by the root directory.
Functions ¶
func GenerateIndex ¶ added in v0.2.0
func GenerateIndex(entries []IndexEntry) *bytes.Buffer
GenerateIndex generates the index file expected by reMarkable API 1.5.
It also sorts entries by its path as a side-effect.
Types ¶
type APIRequest ¶ added in v0.2.0
type APIRequest struct { Method string `json:"http_method"` Path string `json:"relative_path"` // Should only be set for the request to update root. Generation string `json:"generatio,omitempty"` }
APIRequest defines the request json format for reMarkable 1.5 API.
type APIResponse ¶ added in v0.2.0
type APIResponse struct { Path string URL string Method string Expires time.Time // It's possible the expires json value returned by reMarkable cloud cannot be // parsed as a timestamp. In such case Expires will be zero time. RawExpires string Headers map[string]string }
APIResponse defines the response json format for reMarkable 1.5 API.
func (*APIResponse) Err ¶ added in v0.3.1
func (resp *APIResponse) Err() error
Err checks for error returned by reMarkable cloud API.
func (APIResponse) ToRequest ¶ added in v0.3.0
ToRequest creates http request from the API response.
func (*APIResponse) UnmarshalJSON ¶ added in v0.3.0
func (resp *APIResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Client ¶
type Client struct { RefreshToken string Logger logger.Logger // contains filtered or unexported fields }
Client defines a reMarkable API client.
You can get it either by using Register with a new token, or construct directly from refresh token stored previously.
func Register ¶
func Register(ctx context.Context, args RegisterArgs) (*Client, error)
Register registers a new token with reMarkable API server.
Upon success, it returns a *Client with RefreshToken set.
func (*Client) AutoRefresh ¶
AutoRefresh refreshes the token when needed.
func (*Client) Download15 ¶ added in v0.2.0
Download15 is the "low-level" api that downloads a file in reMarkable Cloud API 1.5 via its GCS path.
func (*Client) DownloadIndex ¶ added in v0.2.0
DownloadIndex downloads and parses an index file by the GCS path in reMarkable 1.5 API.
func (*Client) DownloadRoot ¶ added in v0.2.0
func (c *Client) DownloadRoot(ctx context.Context) (entries []IndexEntry, generation string, err error)
DownloadRoot downloads and parses the root file in reMarkable 1.5 API.
func (*Client) ListDirs ¶
ListDirs lists all the directories user created on their reMarkable account.
The returned map is in format of <id> -> <display name>. When error is nil, the map is guaranteed to have at least an entry of "" -> RootDisplayName.
func (*Client) UpdateRoot ¶ added in v0.2.0
UpdateRoot updates the root file with the given path to the previously uploaded new root index.
type ContentArgs ¶
type ContentArgs struct {
Font string
}
ContentArgs defines the args to population InitialContent.
type FileType ¶
type FileType int
FileType is an enum type defining the file type on reMarkable.
It's either epub or pdf.
const ( FileTypeEpub FileType FileTypePdf )
FileType values.
func (FileType) InitialContent ¶
func (ft FileType) InitialContent(args ContentArgs) (string, error)
InitialContent returns the initial .content file for the given FileType.
type IndexEntry ¶ added in v0.2.0
type IndexEntry struct { // The GCS path Path string // For root this is the content uuid, // for index this is the filename (usually "uuid.ext") Filename string // For index NumFiles is always 0, for root Size is always 0 NumFiles int64 Size int64 // Should be either RootEntryUnused1Magic or IndexEntryUnused1Magic. Unused1 string }
IndexEntry defines an entry in the index file in reMarkable 1.5 API.
func ParseIndexEntry ¶ added in v0.2.0
func ParseIndexEntry(line string) (IndexEntry, error)
ParseIndexEntry parses a line into IndexEntry.
type Metadata ¶ added in v0.2.0
type Metadata struct { Type string `json:"type"` Name string `json:"visibleName"` Parent string `json:"parent"` Version int `json:"version"` LastModified TimestampMillisecond `json:"lastModified"` }
Metadata defines the json format for the .metadata files.
type RegisterArgs ¶
type RegisterArgs struct { // A token got from either https://my.remarkable.com/device/desktop/connect or // https://my.remarkable.com/device/mobile/connect, usually with length of 8. Token string // A description of this device, usually something like "desktop-linux", // "mobile-android". Description string }
RegisterArgs defines args to be used with Register.
type TimestampMillisecond ¶ added in v0.1.1
TimestampMillisecond is used to marshal timestamp into milliseconds since unix epoch in json.
func (TimestampMillisecond) MarshalJSON ¶ added in v0.1.1
func (ts TimestampMillisecond) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
It converts time into milliseconds since unix epoch.
func (*TimestampMillisecond) UnmarshalJSON ¶ added in v0.2.0
func (ts *TimestampMillisecond) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
It converts milliseconds since unix epoch into time.
type UploadArgs ¶
type UploadArgs struct { ID string Title string Data io.Reader Type FileType // Optional ParentID string ContentArgs ContentArgs }
UploadArgs defines the args used by Upload function.