k2s

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 10 Imported by: 0

README

k2s

A Keep2Share API client

Documentation

Index

Constants

View Source
const AccountInfoPath = "/accountInfo"

AccountInfoPath is the subpath for the accountInfo endpoint

View Source
const ContentTypeJSON = "application/json"

ContentTypeJSON represents the application/json MIME type.

View Source
const DefaultBaseURL = "https://keep2share.cc/api/v2"

DefaultBaseURL is the Keep2Share API base URL as of early 2022.

View Source
const GetFileStatusPath = "/getFileStatus"

GetFileStatusPath is the subpath for the getFileStatus endpoint

View Source
const GetFilesInfoPath = "/getFilesInfo"

GetFilesInfoPath is the subpath for the getFilesInfo endpoint

View Source
const GetURLPath = "/getUrl"

GetURLPath is the subpath for the getUrl endpoint

View Source
const LoginPath = "/login"

LoginPath is the subpath for the login endpoint

View Source
const RequestRecaptchaPath = "/requestReCaptcha"

RequestRecaptchaPath is the subpath for the requestRecaptcha endpoint

Variables

View Source
var (
	ErrInvalidParams           = Error{Code: http.StatusBadRequest, ErrorCode: 2}
	ErrDownloadTrafficExceeded = Error{Code: http.StatusNotAcceptable, ErrorCode: 2}
	ErrFileNotAvailable        = Error{Code: http.StatusNotAcceptable, ErrorCode: 21}
	ErrNotAuthorized           = Error{Code: http.StatusForbidden, ErrorCode: 10}
	ErrVerifyWithRecaptcha     = Error{Code: http.StatusNotAcceptable, ErrorCode: 33}
)

Error constants

Functions

This section is empty.

Types

type Account added in v0.8.0

type Account struct {
	AvailableTraffic int `json:"available_traffic"`
	AccountExpires   int `json:"account_expires"`
}

Account represents the non-http portion of the accountInfo response

type AccountInfoRequest added in v0.8.0

type AccountInfoRequest struct {
	AuthToken string `json:"auth_token"`
}

AccountInfoRequest represents the request body for the accountInfo endpoint

type AccountInfoResponse added in v0.8.0

type AccountInfoResponse struct {
	Response
	Account
}

AccountInfoResponse represents the response body for the accountInfo endpoint

type Client

type Client struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

Client encapsulates a Keep2Share API client. The client is thread-safe and automatically logs in and refreshes its authorization token, blocking requests when an invalid token exists.

func NewClient

func NewClient(baseURL, username, password string, logger Logger) (*Client, error)

func (*Client) AccountInfo added in v0.8.0

func (c *Client) AccountInfo() (*Account, error)

AccountInfo calls the accountInfo endpoint and returns the account info

func (*Client) Authenticate added in v0.9.0

func (c *Client) Authenticate() error

func (*Client) AuthenticateWithChallenge added in v0.9.0

func (c *Client) AuthenticateWithChallenge(challenge, response string) error

func (*Client) Authenticated added in v0.9.0

func (c *Client) Authenticated() bool

func (*Client) GetFileStatus

func (c *Client) GetFileStatus(id string) (*FileStatus, error)

GetFileStatus calls the getFileStatus endpoint and returns the status information for the requested file.

func (*Client) GetFilesInfo added in v0.7.0

func (c *Client) GetFilesInfo(ids []string, extended bool) ([]FileInfo, error)

GetFilesInfo calls the getFilesInfo endpoint and returns the info for the requested files

func (*Client) GetURL

func (c *Client) GetURL(fileID string) (string, error)

func (*Client) Login

func (c *Client) Login(username, password, challenge, response string) (string, error)

Login calls the login endpoint and returns the auth token.

func (*Client) RequestRecaptcha

func (c *Client) RequestRecaptcha() (*RequestRecaptchaResponse, error)

RequestRecaptcha calls the requestRecaptcha endpoint and returns the reCaptcha challenge and link

func (*Client) Token added in v0.3.1

func (c *Client) Token() (string, error)

type Error

type Error struct {
	Status    string `json:"status"`
	Code      int    `json:"code"`
	ErrorCode int    `json:"errorCode"`
	Message   string `json:"message"`
}

Error represents an error response from the Keep2Share API

func (Error) Error

func (e Error) Error() string

func (Error) Is added in v0.6.1

func (e Error) Is(target error) bool

type ExtendedInfo added in v0.7.0

type ExtendedInfo struct {
	StorageObject string `json:"storage_object"`
	Size          int    `json:"size"`
	Access        string `json:"access"`
	ContentType   string `json:"content_type"`
}

ExtendedInfo represents the extended file info returned by getFilesInfo

type FileInfo added in v0.7.0

type FileInfo struct {
	ID                 string  `json:"id"`
	Name               string  `json:"name"`
	Size               int     `json:"size"`
	IsAvailable        bool    `json:"is_available"`
	Access             string  `json:"access"`
	IsFolder           bool    `json:"is_folder"`
	MD5                *string `json:"md5"`
	IsAvailableForFree bool    `json:"isAvailableForFree"`
	ExtendedInfo       ExtendedInfo
}

FileInfo represents the file info returned by getFilesInfo

type FileStatus

type FileStatus struct {
	Name               string    `json:"name"`
	IsAvailable        bool      `json:"is_available"`
	IsFolder           bool      `json:"is_folder"`
	DateCreated        time.Time `json:"date_created"`
	Size               int       `json:"size"`
	Access             string    `json:"access"`
	IsAvailableForFree bool      `json:"isAvailableForFree"`
	VideoInfo          VideoInfo `json:"video_info"`
}

FileStatus represents the status information returned for a file

type GetFileStatusRequest

type GetFileStatusRequest struct {
	AuthToken string `json:"auth_token,omitempty"`
	ID        string `json:"id"`
	Limit     int    `json:"limit,omitempty"`
	Offset    int    `json:"offset,omitempty"`
}

GetFileStatusRequest represents the request body for the getFileStatus endpoint

type GetFileStatusResponse

type GetFileStatusResponse struct {
	Response
	FileStatus
}

GetFileStatusResponse represents the response body for the getFileStatus endpoint

type GetFilesInfoRequest added in v0.7.0

type GetFilesInfoRequest struct {
	AuthToken    string   `json:"auth_token,omitempty"`
	IDs          []string `json:"ids"`
	ExtendedInfo bool     `json:"extended_info,omitempty"`
}

GetFilesInfoRequest represents the request body for the getFilesInfo endpoint

type GetFilesInfoResponse added in v0.7.0

type GetFilesInfoResponse struct {
	Response
	Files []FileInfo
}

GetFilesInfoResponse represents the response body for the getFilesInfo endpoint

type GetURLRequest

type GetURLRequest struct {
	FileID           string `json:"file_id"`
	AuthToken        string `json:"auth_token,omitempty"`
	FreeDownloadKey  string `json:"free_download_key,omitempty"`
	CaptchaChallenge string `json:"captcha_challenge,omitempty"`
	CaptchaResponse  string `json:"captcha_response,omitempty"`
	URLReferrer      string `json:"url_referrer,omitempty"`
}

GetURLRequest represents the request body for the getUrl endpoint

type GetURLResponse

type GetURLResponse struct {
	Response
	URL string `json:"url"`
}

GetURLResponse represents the request response for the getUrl endpoint

type Logger added in v0.9.0

type Logger interface {
	Printf(format string, v ...interface{})
}

type LoginRequest

type LoginRequest struct {
	Username           string `json:"username"`
	Password           string `json:"password"`
	ReCaptchaChallenge string `json:"re_captcha_challenge,omitempty"`
	ReCaptchaResponse  string `json:"re_captcha_response,omitempty"`
}

LoginRequest represents the request body for the login endpoint

type LoginResponse

type LoginResponse struct {
	Response
	AuthToken string `json:"auth_token"`
}

LoginResponse represents the response body for the login endpoint

type RequestRecaptchaResponse

type RequestRecaptchaResponse struct {
	Response
	Challenge  string `json:"challenge"`
	CaptchaURL string `json:"captcha_url"`
}

RequestRecaptchaResponse represents the response from the requestRecaptcha endpoint

type Response

type Response struct {
	Status string `json:"status"`
	Code   int    `json:"code"`
}

Response represents the fields common to all responses from the Keep2Share API

type Token

type Token struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

Token represents the token string with additional convenience methods

func (Token) String

func (t Token) String() string

func (Token) Valid added in v0.9.0

func (t Token) Valid() bool

type VideoInfo

type VideoInfo struct {
	Duration float64 `json:"duration"`
	Width    int     `json:"width"`
	Height   int     `json:"height"`
	Format   string  `json:"format"`
}

VideoInfo represents the video_info dictionary of a file status

Jump to

Keyboard shortcuts

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