pocketbook_cloud_client

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 9 Imported by: 0

README

pocketbook-cloud-client

PocketBook Cloud API Client

Example

package main

import (
	"context"
	"encoding/json"
	"log"

	pbc "github.com/micronull/pocketbook-cloud-client"
)

func main() {
	cli := pbc.New(
		pbc.WithClientID("qNAx1RDb"),
		pbc.WithClientSecret("K3YYSjCgDJNoWKdGVOyO1mrROp3MMZqqRNXNXTmh"),
	)
	ctx := context.Background()

	prvs, err := cli.Providers(ctx, "you.mail.box@some.com")
	if err != nil {
		log.Fatal(err)
	}

	for _, prv := range prvs {
		req := pbc.LoginRequest{
			ShopID:   prv.ShopID,
			UserName: "you.mail.box@some.com",
			Password: "you.password",
			Provider: prv.Alias,
		}

		tkn, err := cli.Login(ctx, req)
		if err != nil {
			log.Fatal(err)
		}

		books, err := cli.Books(ctx, tkn.AccessToken, 0, 0)
		if err != nil {
			log.Fatal(err)
		}

		if books.Total == 0 {
			continue
		}

		books, err = cli.Books(ctx, tkn.AccessToken, books.Total, 0)
		if err != nil {
			log.Fatal(err)
		}

		js, _ := json.MarshalIndent(books, "", "  ")

		log.Println(string(js))
	}
}

Documentation

Index

Constants

View Source
const (
	DefaultScheme = "https"
	DefaultHost   = "cloud.pocketbook.digital"
	DefaultPath   = "/api/v1.0/"
)
View Source
const TokenTypeBearer tokenType = "Bearer"

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	ID           string
	Path         string
	Title        string
	MimeType     string
	CreatedAt    time.Time
	Purchased    bool
	Bytes        int
	ClientMtime  time.Time
	FastHash     string
	Favorite     bool
	ReadStatus   string
	Link         string
	HasLinks     bool
	Format       string
	Md5Hash      string
	Mtime        time.Time
	Name         string
	ReadPercent  int
	Percent      string
	IsDrm        bool
	IsLcp        bool
	IsAudioBook  bool
	MetaData     BookMetaData
	Position     BookPosition
	ReadPosition BookReadPosition
	Action       string
	ActionDate   time.Time
}

type BookCover

type BookCover struct {
	Width  int
	Height int
	Path   string
}

type BookMetaData

type BookMetaData struct {
	Title       string
	Authors     string
	Cover       []BookCover
	Lang        string
	Publisher   string
	Updated     time.Time
	Year        int
	Isbn        string
	BookId      []string
	FixedLayout bool
}

type BookPosition

type BookPosition struct {
	Pointer    string
	PointerPb  string
	Percent    int
	Page       string
	PagesTotal int
	Updated    time.Time
	Offs       int
}

type BookReadPosition

type BookReadPosition struct {
	Pointer    string
	PointerPb  string
	Percent    int
	Page       string
	PagesTotal int
	Updated    time.Time
	Offs       int
}

type Books

type Books struct {
	Total int
	Books []Book
}

type Client

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

func New

func New(opts ...Option) *Client

func (Client) Books

func (c Client) Books(ctx context.Context, token string, limit, offset int) (Books, error)

func (Client) Login

func (c Client) Login(ctx context.Context, lreq LoginRequest) (Token, error)

func (Client) Providers

func (c Client) Providers(ctx context.Context, userName string) ([]Provider, error)

Providers getting allowed providers list.

type LoginRequest

type LoginRequest struct {
	ShopID   string
	UserName string
	Password string
	Provider string
}

type Option

type Option func(*Client)

func WithClientID

func WithClientID(id string) Option

func WithClientSecret

func WithClientSecret(sec string) Option

func WithHTTPClient

func WithHTTPClient(client doer) Option

type Provider

type Provider struct {
	Alias    string
	Name     string
	ShopID   string
	Icon     string
	IconEink string
	LoggedBy string
}

type Token

type Token struct {
	AccessToken  string
	TokenType    tokenType
	ExpiresIn    time.Time
	RefreshToken string
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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