api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package api handles interaction between the C3PM Command Line Interface (CLI), and C3PM's API. The package's role is to abstract all needed low level interaction, such as HTTP or filesystem calls exposing an interface simple, clear and easy to understand from the rest of the CLI.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Client *http.Client
	Token  string
}

API represents a connection to c3pm's backend, used for authentication and publishing purposes

func New added in v0.1.0

func New(c *http.Client, t string) API

New builds a new API object

func (*API) CountDownload added in v0.3.0

func (c *API) CountDownload(packageName string) error

func (*API) Login

func (c *API) Login(login, password string) (string, error)

Login handles the login logic with the API. It takes the user's email and password as strings, sends them to the API, and returns the ApiKey object to be used in further calls to the API.

Example
package main

import (
	"fmt"
	"github.com/c3pm-labs/c3pm/api"
	"net/http"
)

func main() {
	c := api.New(&http.Client{}, "xxxx")
	key, err := c.Login("login", "password")
	fmt.Println(key, err)
}
Output:

func (API) Upload

func (c API) Upload(files []string) error

Upload is a wrapper function around C3PM's publish endpoint. It takes an array of file paths, creates a tar file containing them, then uploads it to the API.

Example
package main

import (
	"fmt"
	"github.com/c3pm-labs/c3pm/api"
	"net/http"
)

func main() {
	c := api.New(&http.Client{}, "xxxx")
	err := c.Upload([]string{"../../testhelpers/tars/single.tar"})
	fmt.Println(err)
}
Output:

Directories

Path Synopsis
Package test provides simple mock servers to be used when testing interaction with C3PM's API.
Package test provides simple mock servers to be used when testing interaction with C3PM's API.

Jump to

Keyboard shortcuts

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