gonextcloud/client.go

39 lines
888 B
Go
Raw Normal View History

package gonextcloud
import (
req "github.com/levigross/grequests"
2018-10-08 16:50:11 +00:00
"gitlab.adphi.fr/partitio/Nextcloud-Partitio/gonextcloud/types"
"net/url"
)
2018-07-30 08:03:38 +00:00
// Client is the API client that performs all operations against a Nextcloud server.
type Client struct {
baseURL *url.URL
username string
password string
session *req.Session
headers map[string]string
capabilities *types.Capabilities
version *types.Version
}
2018-07-30 08:03:38 +00:00
// NewClient create a new Client from the Nextcloud Instance URL
func NewClient(hostname string) (*Client, error) {
2018-07-13 11:41:51 +00:00
baseURL, err := url.ParseRequestURI(hostname)
if err != nil {
2018-07-13 11:41:51 +00:00
baseURL, err = url.ParseRequestURI("https://" + hostname)
if err != nil {
return nil, err
}
}
2018-07-13 11:41:51 +00:00
c := Client{
baseURL: baseURL,
headers: map[string]string{
"OCS-APIREQUEST": "true",
"Accept": "application/json",
},
}
return &c, nil
}