Documentation
¶
Overview ¶
Package api provides API wrappers for some of Lovense's API.
Index ¶
- Variables
- type Client
- func (c *Client) Do(method, path string, opts ...RequestOpt) (*http.Response, error)
- func (c *Client) DoGET(path string, outJSON interface{}, opts ...RequestOpt) error
- func (c *Client) DoJSON(method, path string, outJSON interface{}, opts ...RequestOpt) error
- func (c *Client) DoPOST(path string, outJSON interface{}, opts ...RequestOpt) error
- func (c *Client) WithContext(ctx context.Context) *Client
- type ClientData
- type Pattern
- type PatternClient
- func (c *PatternClient) DownloadPattern(p *Pattern) (*pattern.Pattern, error)
- func (c *PatternClient) Find(page, pageSize int, typ PatternFindType) ([]Pattern, error)
- func (c *PatternClient) SearchAuthor(keyword string) ([]Pattern, error)
- func (c *PatternClient) SearchTitle(keyword string) ([]Pattern, error)
- type PatternFindType
- type RequestOpt
- type ResponseBody
- type ServerError
Constants ¶
This section is empty.
Variables ¶
var DefaultForm = url.Values{
"appVersion": {"5.1.6"},
"version": {"2"},
"platform": {"android"},
}
DefaultForm are the default form values.
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 NewClientContext ¶
NewClientContext returns a new client with the given context applied throughout the requests.
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.
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 ¶
AuthorOrAnon returns the Author name or Anonymous if empty.
func (*Pattern) DecodedName ¶
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 ¶
RequestOpt is the type for an API option.
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.