k2s

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 11 Imported by: 0

README

k2s

A Keep2Share API client

Documentation

Index

Constants

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 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

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Log *log.Logger
	// 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) *Client

func (*Client) Authorized

func (c *Client) Authorized() 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) GetURL

func (c *Client) GetURL(fileID, freeDownloadKey, captchaChallenge, captchaResponse, urlReferrer 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) LoginWithChallenge added in v0.3.0

func (c *Client) LoginWithChallenge(challenge, response string)

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() *Token

func (*Client) UpdateAuthorization

func (c *Client) UpdateAuthorization(username string, password string)

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

type FileStatus

type FileStatus struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	IsAvailable bool      `json:"is_available"`
	IsFolder    bool      `json:"is_folder"`
	DateCreated time.Time `json:"date_created"`
	Size        int       `json:"size"`
	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 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 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
}

func (*Token) Error

func (t *Token) Error() string

func (*Token) String

func (t *Token) String() string

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