pcloud

package module
v0.0.0-...-59a5eb6 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2023 License: MIT Imports: 7 Imported by: 0

README

pCloud

A wrapper for the pcloud API

API-Server

Before you start using the pCloud-API you need to find out where your servers are. Europe and US are having different Subdomains (https://docs.pcloud.com).

As Go supports HTTPS just the SSL-Protocol is used. The base of the API-calls are:

Documentation

Overview

Package pcloud provides a client for accessing the pCloud API.

The pCloud API is located in the US and EU. If you are using the API it is important that you set the correct location for your account. Otherwise the authentication will fail. The default HostURL is the EU API. To change the host use the constants HostURLEU or HostURLUS. If there will be another location in the future it is also possible to set that variable with the URL. For security reasons it is not recomended to change the protocol from HTTPS to HTTP.

For the authentication there are two different methods to get the auth-token. With AuthMethodPassword the password is send to the server as a get-parameter. This way is not recomended, because it not a good idea to send a password directly to pCloud. Even when HTTPS is used. The Default method is AuthMethodDigest. In this case first a digest is requested from the api-server. This digest is used to hash the password with the username to receive an auth-token. Cause of the extra request that way is a little bit slower. But that is just once, when the auth-token is requested.

To get the data this package does just use the JSON API from pCloud. The binary API is not supported. The JSON API is documented here: https://docs.pcloud.com/methods/

Index

Constants

View Source
const (
	HostURLEU = "https://eapi.pcloud.com"
	HostURLUS = "https://api.pcloud.com"
)

The different host URLs of the pCloud API. The URL can be setz with the HostURL variable. If there will be a new host URL, it can be set with the HostURL variable. The HostURL variable is set to the HostURLEU variable by default.

View Source
const (
	AuthMethodPassword = iota // Send password as get parameter
	AuthMethodDigest          // Send a hashed password as get parameter
)

The different authentication methods, which can be used to authenticate with the pCloud API. The AuthMethodPassword method sends the password as parameters. So it is not recomendet to use this method, because the password is sent in plain text. The AuthMethodDigest method sends the password as a hashed string. To do this a digest value is requested from the pCloud API.

Variables

View Source
var (
	HostURL    = HostURLEU        // HostURL is the base URL for the pCloud API.
	AuthMethod = AuthMethodDigest // AuthMethod is the method used to authenticate with the pCloud API.
	Timeout    = 5 * time.Second  // Timeout for the API requests
)

The global configuration variables of the pCloud API.

View Source
var HTTPClient = &http.Client{
	Timeout: Timeout,
}

HTTPClient is the HTTP client used to make requests to the pCloud API. If you want to define your own HTTP client, you can do so by setting this variable to your client. The default client uses the Timout variable of this package.

Functions

func ApiRequest

func ApiRequest(respStruct any, method string, params ...Param) error

ApiRequest is a generic function to request data from the pCloud API It takes a pointer to a struct as response and a method name and a list of parameters. Into the respStuct the JSON response is decoded.

This function uses the authToken variable to authenticate the request. If the authToken is not set, the user needs to be logged in.

func AuthToken

func AuthToken() string

AuthToken returns the authentication token used to authenticate with the pCloud API.

func LogIn

func LogIn(user, pass string) error

LogIn authenticates the user with the pCloud API. With the given AuthMethod the auth-token is requested.

func LogOut

func LogOut() error

LogOut logs the user out of the pCloud API. When the logout request is successful the authToken is set to "".

Types

type Param

type Param struct {
	Name string
	Val  string
}

Param is a struct to hold a parameter for an API request

Directories

Path Synopsis
Package api is the structure of the JSON returned by the pCloud API.
Package api is the structure of the JSON returned by the pCloud API.
Package pfs implements the pCloud API as a fs.FS interface At the moment this is a prototype and should not be used by other packages! Because the API is not stable yet and the implementation is not complete.
Package pfs implements the pCloud API as a fs.FS interface At the moment this is a prototype and should not be used by other packages! Because the API is not stable yet and the implementation is not complete.

Jump to

Keyboard shortcuts

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