api

package
v0.0.0-...-0e88d40 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

Package api provides API wrappers for some of Lovense's API.

Index

Constants

This section is empty.

Variables

View Source
var DefaultForm = url.Values{
	"appVersion": {"5.1.6"},
	"version":    {"2"},
	"platform":   {"android"},
}

DefaultForm are the default form values.

View Source
var DefaultHeader = http.Header{
	"User-Agent": {"okhttp/3.12.3"},
}

DefaultHeader are the default request headers.

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
	*ClientData
	// contains filtered or unexported fields
}

Client is a general API client.

func NewClient

func NewClient() *Client

NewClient returns a new client.

func NewClientContext

func NewClientContext(ctx context.Context) *Client

NewClientContext returns a new client with the given context applied throughout the requests.

func (*Client) Do

func (c *Client) Do(method, path string, opts ...RequestOpt) (*http.Response, error)

Do sends a HTTP request and returns a typical HTTP response.

func (*Client) DoGET

func (c *Client) DoGET(path string, outJSON interface{}, opts ...RequestOpt) error

DoGET sends a GET to the given URL.

func (*Client) DoJSON

func (c *Client) DoJSON(method, path string, outJSON interface{}, opts ...RequestOpt) error

DoJSON sends a HTTP request and unmarshals into the given outJSON.

func (*Client) DoPOST

func (c *Client) DoPOST(path string, outJSON interface{}, opts ...RequestOpt) error

DoPOST sends a POST to the given URL. If outJSON is not nil, then a JSON body is read.

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

WithContext returns a copy of Client with the given context.

type ClientData

type ClientData struct {
	Host          string // apps.lovense.com
	DefaultForm   url.Values
	DefaultHeader http.Header
}

ClientData contains the shared client data.

type Pattern

type Pattern struct {
	Author         string      `json:"author"`
	CDNPath        string      `json:"cdnPath"`
	Created        string      `json:"created"`     // YYYY/MM/DD HH:MM
	CreatedTime    int64       `json:"createdTime"` // UnixMilli
	Duration       int64       `json:"duration"`
	Email          string      `json:"email"`
	Favorite       interface{} `json:"favorite"` // null(?)
	FavoritesCount int64       `json:"favoritesCount"`
	ID             string      `json:"id"`
	IsAnony        string      `json:"isAnony"` // bool, "1"
	IsShowReview   string      `json:"isShowReview"`
	LikeCount      int64       `json:"likeCount"`
	Name           string      `json:"name"`
	Path           string      `json:"path"`
	PlayCount      int64       `json:"playCount"`
	RandomCode     string      `json:"randomCode"`
	Self           bool        `json:"self"`
	Status         string      `json:"status"`
	Text           string      `json:"text"`
	Timer          string      `json:"timer"`
	ToyTag         string      `json:"toyTag"`
	Updated        string      `json:"updated"` // YYYY/MM/DD HH:MM
	Version        string      `json:"version"`
	Version2       int64       `json:"version2"`
}

Pattern describes a pattern.

func (*Pattern) AuthorOrAnon

func (b *Pattern) AuthorOrAnon() string

AuthorOrAnon returns the Author name or Anonymous if empty.

func (*Pattern) DecodedName

func (p *Pattern) DecodedName() string

DecodedName returns the Pattern's name decoded from base64 if possible.

type PatternClient

type PatternClient struct {
	*Client
}

PatternClient handles pattern-fetching routes.

func NewPatternClient

func NewPatternClient(c *Client) *PatternClient

NewPatternClient returns a new PatternClient from the given Client.

func (*PatternClient) DownloadPattern

func (c *PatternClient) DownloadPattern(p *Pattern) (*pattern.Pattern, error)

DownloadPattern downloads the given pattern from the CDN and parses it into the pattern data.

func (*PatternClient) Find

func (c *PatternClient) Find(page, pageSize int, typ PatternFindType) ([]Pattern, error)

Find calls the /find endpoint, which lists patterns according to the given parameters.

typ should typically be "Recommended". If pageSize is 0, then 15 is used by default. If page is 0, then 1 is used for the first page. There is currently no known page/pageSize.

func (*PatternClient) SearchAuthor

func (c *PatternClient) SearchAuthor(keyword string) ([]Pattern, error)

SearchAuthor searches for patterns with the given keyword in its author field.

func (*PatternClient) SearchTitle

func (c *PatternClient) SearchTitle(keyword string) ([]Pattern, error)

SearchTitle searches for patterns with the given keyword in its title.

type PatternFindType

type PatternFindType string

PatternFindType

const (
	FindRecommendedPatterns PatternFindType = "Recommended"
	FindPopularPatterns     PatternFindType = "Popular"
	FindRecentPatterns      PatternFindType = "recent"
	FindPickPatterns        PatternFindType = "pick"
)

type RequestOpt

type RequestOpt func(*Client, *http.Request)

RequestOpt is the type for an API option.

func WithHeader

func WithHeader(h http.Header) RequestOpt

WithHeader injects the given header.

func WithPOSTForm

func WithPOSTForm(form url.Values) RequestOpt

WithPOSTForm injects the given form as an x-www-form-urlencoded body.

type ResponseBody

type ResponseBody struct {
	Code    int64       `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
	Result  bool        `json:"result"`
}

ResponseBody is the general response body that the backend responds with.

func (ResponseBody) RawData

func (body ResponseBody) RawData() json.RawMessage

RawData returns Data as a raw JSON message.

type ServerError

type ServerError struct {
	ResponseBody
	Status int
}

ServerError is the server error. It implements error.

func (*ServerError) Error

func (e *ServerError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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