raindrop

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package raindrop implements Raindrop.io API client.

API Reference: https://developer.raindrop.io/

Index

Constants

View Source
const (
	ALL_COLLECTION_ID    = 0   //描述返回所有的集合,除了trash
	UNSORT_COLLECTION_ID = -1  // unsort collectionid, 中文含义为:没有归类的collection
	TRASH_COLLECTION_ID  = -99 // trash collection
)

Variables

This section is empty.

Functions

func GetHtmlTitle

func GetHtmlTitle(r io.Reader) (string, bool)

Types

type AccessTokenResponse

type AccessTokenResponse struct {
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Expires      int    `json:"expires,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	Error        string `json:"error,omitempty"`
}

AccessTokenResponse represents the token exchange api response item

type AttachFileInfo

type AttachFileInfo struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Size uint32 `json:"size"`
}

type CacheStatus

type CacheStatus string
const (
	READY        CacheStatus = "ready"
	RETRY        CacheStatus = "retry"
	FAILED       CacheStatus = "failed"
	INVALID_O    CacheStatus = "invalid-origin"
	INVALID_TO   CacheStatus = "invalid-timeout"
	INVALID_SIZE CacheStatus = "invalid-size"
)

type Client

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

Client is a raindrop client

func NewClient

func NewClient(clientId string, clientSecret string, redirectUri string) (*Client, error)

NewClient creates Raindrop.io client

func (*Client) CreateCollection

func (c *Client) CreateCollection(accessToken string, isRoot bool, view string, title string, sort int,
	public bool, parentId uint32, cover []string, ctx context.Context) (*CreateCollectionResponse, error)

CreateCollection creates new Collection Reference: https://developer.raindrop.io/v1/collections/methods#create-collection

func (*Client) CreateRaindrop

func (c *Client) CreateRaindrop(accessToken string, obj *RaindropUserInfo, ctx context.Context) (*SingleRaindropResponse, error)

func (*Client) CreateSimpleRaindrop

func (c *Client) CreateSimpleRaindrop(accessToken string, link string, ctx context.Context) (*SingleRaindropResponse, error)

CreateSimpleRaindrop creates new simple unsorted Raindrop Reference: https://developer.raindrop.io/v1/raindrops/single#create-raindrop

func (*Client) GetAccessToken

func (c *Client) GetAccessToken(userCode string, ctx context.Context) (*AccessTokenResponse, error)

GetAccessToken exchanges UserRef's authorization code to access token Reference: https://developer.raindrop.io/v1/authentication/token#step-3-the-token-exchange

func (*Client) GetAuthorizationCode

func (c *Client) GetAuthorizationCode(r *http.Request) (string, error)

GetAuthorizationCode returns authorization code or an error from raindrop's redirect request Reference: https://developer.raindrop.io/v1/authentication/token#step-2-the-redirection-to-your-application-site

func (*Client) GetAuthorizationCodeHandler

func (c *Client) GetAuthorizationCodeHandler(w http.ResponseWriter, r *http.Request)

GetAuthorizationCodeHandler handles redirect request from raindrop's authorization page

func (*Client) GetAuthorizationURL

func (c *Client) GetAuthorizationURL() (url.URL, error)

GetAuthorizationURL returns URL for UserRef to authorize app

func (*Client) GetChildCollections

func (c *Client) GetChildCollections(accessToken string, ctx context.Context) (*GetCollectionsResponse, error)

GetChildCollections call Get child collections API. Reference: https://developer.raindrop.io/v1/collections/methods#get-child-collections

func (Client) GetCollection

func (c Client) GetCollection(accessToken string, id uint32, ctx context.Context) (*GetCollectionResponse, error)

GetCollection call Get collection API. Reference: https://developer.raindrop.io/v1/collections/methods#get-collection

func (*Client) GetRaindrop

func (c *Client) GetRaindrop(accessToken string, rId uint32, ctx context.Context) (*SingleRaindropResponse, error)

func (*Client) GetRaindrops

func (c *Client) GetRaindrops(accessToken string, searchParam *SearchRdParams, ctx context.Context) (*MultiRaindropsResponse, error)

GetRaindrops call get raindrops API. Reference: https://developer.raindrop.io/v1/raindrops/multiple#get-raindrops

func (*Client) GetRootCollections

func (c *Client) GetRootCollections(accessToken string, ctx context.Context) (*GetCollectionsResponse, error)

GetRootCollections call Get root collections API. Reference: https://developer.raindrop.io/v1/collections/methods#get-root-collections

func (*Client) GetTaggedRaindrops

func (c *Client) GetTaggedRaindrops(accessToken string, tag string, ctx context.Context) (*MultiRaindropsResponse, error)

GetTaggedRaindrops finds raindrops with exact tags. This function calls Get raindrops API with collectionID=0 and specify given tag as a search parameter.

Reference: https://developer.raindrop.io/v1/raindrops/multiple#search-parameter

func (*Client) GetTags

func (c *Client) GetTags(accessToken string, ctx context.Context) (*Tags, error)

GetTags calls Get tags API. Reference: https://developer.raindrop.io/v1/tags#get-tags

func (*Client) RefreshAccessToken

func (c *Client) RefreshAccessToken(refreshToken string, ctx context.Context) (*AccessTokenResponse, error)

RefreshAccessToken refreshes expired token Reference: https://developer.raindrop.io/v1/authentication/token#the-access-token-refresh

type Collection

type Collection struct {
	ID         uint32   `json:"_id"`
	Access     access   `json:"access"`
	Color      string   `json:"color"`
	Count      uint32   `json:"count"`
	Cover      []string `json:"cover"`
	Created    string   `json:"created"`
	LastUpdate string   `json:"lastUpdate"`
	ParentId   int      `json:"parent_id,omitempty"`
	Expanded   bool     `json:"expanded"`
	Public     bool     `json:"public"`
	Title      string   `json:"title"`
	User       UserRef  `json:"user"`
	View       string   `json:"view"`
}

Collection represents Raindrop.io collection type

type CollectionRef

type CollectionRef struct {
	Ref             string `json:"$ref"`
	CollectionId    uint32 `json:"$id"`
	OldCollectionId uint32 `json:"oid"`
}

type CreateCollectionResponse

type CreateCollectionResponse struct {
	Result       bool                    `json:"result"`
	Item         createCollectionRequest `json:"item,omitempty"`
	Error        string                  `json:"error,omitempty"`
	ErrorMessage string                  `json:"errorMessage,omitempty"`
}

CreateCollectionResponse represents create collection api response item

type CreatorRef

type CreatorRef struct {
	Id     uint32 `json:"_id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Avatar string `json:"avatar"`
}

type GetCollectionResponse

type GetCollectionResponse struct {
	Result bool       `json:"result"`
	Item   Collection `json:"item"`
}

GetCollectionResponse represents get collection by id api response

type GetCollectionsResponse

type GetCollectionsResponse struct {
	Result bool         `json:"result"`
	Items  []Collection `json:"items"`
}

GetCollectionsResponse represents get root and child collections api response

type Highlight

type Highlight struct {
	Id      string `json:"_id"`
	Text    string `json:"text"`
	Color   string `json:"color"`
	Note    string `json:"note"`
	Created string `json:"created"`
}

type MultiRaindropsResponse

type MultiRaindropsResponse struct {
	Result bool       `json:"result"`
	Items  []Raindrop `json:"items"`
}

MultiRaindropsResponse represents get multiple raindrops api response

type Raindrop

type Raindrop struct {
	RaindropUserInfo
	RaindropAttach
}

Raindrop represents get raindrops api response item

type RaindropAttach

type RaindropAttach struct {
	Broken bool          `json:"broken"`
	Cache  RaindropCache `json:"cache"`
	CRef   CreatorRef    `json:"creatorRef,omitempty"`
}

type RaindropCache

type RaindropCache struct {
	Status  CacheStatus `json:"status"`
	Size    uint32      `json:"size"`
	Created string      `json:"created"`
}

type RaindropUserInfo

type RaindropUserInfo struct {
	ID         uint32   `json:"_id"` // id
	Created    string   `json:"created,omitempty"`
	LastUpdate string   `json:"lastUpdate,omitempty"`
	Sort       int      `json:"sort,omitempty"`
	Tags       []string `json:"tags,omitempty"`
	Media      []media  `json:"media,omitempty"`
	Cover      string   `json:"cover,omitempty"`
	Type       string   `json:"type,omitempty"`
	HTML       string   `json:"html,omitempty"`
	Excerpt    string   `json:"excerpt,omitempty"`
	Title      string   `json:"title,omitempty"`
	Link       string   `json:"link"`
	Domain     string   `json:"domain"`
	Note       string   `json:"note,omitempty"` // note limit 0 - 10000
	User       UserRef  `json:"user"`
	Removed    bool     `json:"removed"`

	Collection   CollectionRef  `json:"collection,omitempty"` // 貌似无效的字段;
	CollectionId uint32         `json:"collectionId"`         // 和collection类似,估计是新老字段吧;
	FileInfo     AttachFileInfo `json:"file,omitempty"`
	Important    bool           `json:"important"` //表示是否重要,红心
	Highlights   []Highlight    `json:"highlights,omitempty"`
	Reminder     Reminder       `json:"reminder,omitempty"`
}

type Reminder

type Reminder struct {
	Date string `json:"date"`
}

type SearchRdParams added in v0.0.2

type SearchRdParams struct {
	CollectionId int
	Search       string //这种有用户来控制
	Sort         string //按照某一个字段进行排序
	Page         int    //第几页
	PageSize     int    //每页多少条
}

func (*SearchRdParams) AddToQuery added in v0.0.2

func (s *SearchRdParams) AddToQuery(query *url.Values)

type SingleRaindropResponse

type SingleRaindropResponse struct {
	Result bool     `json:"result"`
	Items  Raindrop `json:"item"`
}

SingleRaindropResponse represent single raindrop api response

type Tag

type Tag struct {
	ID    string `json:"_id"`
	Count int    `json:"count"`
}

Tag represents get tags api response item

type Tags

type Tags struct {
	Result bool  `json:"result"`
	Items  []Tag `json:"items"`
}

Tags represents get tags api response

type UserRef

type UserRef struct {
	Id  int    `json:"$id"`
	Ref string `json:"$ref"`
}

UserRef represents collection's owner

Jump to

Keyboard shortcuts

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