paper

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2017 License: MIT Imports: 6 Imported by: 0

README

paper

A dependency-free client for the Dropbox Paper API.

Installation

Use the paper package via dep.

dep ensure -add github.com/kyleconroy/paper

Status

This client is ready to use, but only a subset of the API methods have been implemented.

Usage

package main

import (
	"log"

	"github.com/kyleconroy/paper"
)

func PaperSync(names string) error {
	client := paper.NewClient(os.Getenv("DROPBOX_API_KEY"))
	ctx := context.Background()

	list, err := client.ListDocs(ctx, &paper.ListPaperDocsArgs{Limit: 100})
	if err != nil {
		panic(err)
	}

	for _, doc := range list.DocIDs {
		folder, err := client.GetDocFolderInfo(ctx, &paper.RefPaperDoc{DocID: doc})
		if err != nil {
			panic(err)
		}
		if len(folder.Folders) > 0 {
			log.Printf("Document %s is inside folder %s", doc, folder.Folders[0].Name)
		}
		download, content, err := client.DownloadDoc(ctx, &paper.PaperDocExport{
			DocID: doc,
			Format: paper.ExportFormatMarkdown,
		})
		if err != nil {
			panic(err)
		}
		log.Println(download.Title)
		log.Println(string(content))
	}
}

Documentation

Index

Constants

View Source
const (
	ListPaperDocsFilterByAccessed ListPaperDocsFilterBy = "accessed"
	ListPaperDocsFilterByModified                       = "modified"
	ListPaperDocsFilterByCreated                        = "created"
)
View Source
const (
	ListPaperDocsSortByAccessed ListPaperDocsSortBy = "accessed"
	ListPaperDocsSortByModified                     = "modified"
	ListPaperDocsSortByCreated                      = "created"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	Token string
	HTTP  http.Client
}

func NewClient

func NewClient(token string) *APIClient

func (*APIClient) DownloadDoc

func (c *APIClient) DownloadDoc(ctx context.Context, in *PaperDocExport) (*PaperDocExportResult, []byte, error)

func (*APIClient) GetDocFolderInfo

func (c *APIClient) GetDocFolderInfo(ctx context.Context, in *RefPaperDoc) (*FoldersContainingPaperDoc, error)

func (*APIClient) ListDocs

type APIError

type APIError struct {
	Summary  string            `json:"error_summary"`
	Metadata map[string]string `json:"error"`
}

func (APIError) Error

func (e APIError) Error() string

type Cursor

type Cursor struct {
	Value      string `json:"value"`
	Expiration string `json:"expiration"` // TODO: Make a time.Time
}

type ExportFormat

type ExportFormat string
const (
	ExportFormatMarkdown ExportFormat = "markdown"
	ExportFormatHTML     ExportFormat = "html"
)

type Folder

type Folder struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type FolderSharingPolicyType

type FolderSharingPolicyType string
const (
	FolderSharingPolicyTeam       FolderSharingPolicyType = "team"
	FolderSharingPolicyInviteOnly                         = "invite_only"
)

type FoldersContainingPaperDoc

type FoldersContainingPaperDoc struct {
	FolderSharingPolicyType FolderSharingPolicyType
	Folders                 []Folder
}

type ListPaperDocsArgs

type ListPaperDocsArgs struct {
	FilterBy  ListPaperDocsFilterBy  `json:"filter_by,omitempty"`
	SortBy    ListPaperDocsSortBy    `json:"sort_by,omitempty"`
	SortOrder ListPaperDocsSortOrder `json:"sort_order,omitempty"`
	Limit     int32                  `json:"limit,omitempty"`
}

type ListPaperDocsFilterBy

type ListPaperDocsFilterBy string

type ListPaperDocsResponse

type ListPaperDocsResponse struct {
	DocIDs  []string `json:"doc_ids"`
	Cursor  Cursor   `json:"cursor"`
	HasMore bool     `json"has_more"`
}

type ListPaperDocsSortBy

type ListPaperDocsSortBy string

type ListPaperDocsSortOrder

type ListPaperDocsSortOrder string
const (
	ListPaperDocsSortOrderAsc  ListPaperDocsSortOrder = "ascending"
	ListPaperDocsSortOrderDesc                        = "descending"
)

type PaperDocExport

type PaperDocExport struct {
	DocID  string       `json:"doc_id,omitempty"`
	Format ExportFormat `json:"export_format,omitempty"`
}

type PaperDocExportResult

type PaperDocExportResult struct {
	Owner    string `json:"owner"`
	Title    string `json:"title"`
	Revision int64  `json:"revision"`
	MIME     string `json:"mime_type"`
}

type RefPaperDoc

type RefPaperDoc struct {
	DocID string `json:"doc_id"`
}

Jump to

Keyboard shortcuts

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