pinata

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pinata is used to send requests to the Pinata pinByHash endpoint (https://pinata.cloud/documentation#PinByHash).

Index

Constants

View Source
const (

	// DefaultEndpoint is the API endpoint to use for pinata.
	DefaultEndpoint = "https://api.pinata.cloud/pinning/addHashToPinQueue"

	// DefaultAuthEndpoint is the API endpoint to use for authentication testing.
	DefaultAuthEndpoint = "https://api.pinata.cloud/data/testAuthentication"

	// DefaultTimeout is maximum response time to wait before the client hangs up.
	DefaultTimeout = 42 * time.Second

	// MetaDataLimit is the maximum number of key value pairs permitted by Pinata in metadata.
	MetaDataLimit = 10
)

Variables

View Source
var (

	// ErrMetaLimit is issued when too many key value pairs are added to the Pinata metadata.
	ErrMetaLimit = fmt.Errorf("metadata capacity reached (only %d key values pairs allowed)", MetaDataLimit)
)

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	ID       string
	Ipfshash string
	Status   string
	Name     string
}

APIResponse is a struct to unmarshal the Pinata API response into.

type Client

type Client struct {
	http.Client
	// contains filtered or unexported fields
}

Client handles pinata requests. It wraps the standard http.Client and adds the pinata requirements.

func NewClient

func NewClient(key, secret, host string) (*Client, error)

NewClient takes an API Key, API Secret and the hostNode where the pinned CIDs are and returns a Client and any error.

Note: host can be blank ("") and it will be left out of pinByHash requests.

func (*Client) NewPinataRequest

func (client *Client) NewPinataRequest(method, url string, body io.Reader) (*http.Request, error)

NewPinataRequest returns a http.NewRequest with the required headers required by Pinata.

func (*Client) PinByHashWithMetadata

func (client *Client) PinByHashWithMetadata(cid string, metadata *Metadata) (*APIResponse, error)

PinByHashWithMetadata attaches metadata to the Pinata request.

For more details on using the metadata, see: pinata.cloud/documentation#PinByHash

func (*Client) TestAuthentication

func (client *Client) TestAuthentication() (*http.Response, error)

TestAuthentication is used to test Pinata authentication.

type Metadata

type Metadata struct {

	// Name is a custom name you can have for referencing your pinned content
	Name string `json:"name,omitempty"`

	// Keyvalues encode the metadata (as strings, numbers or ISO dates)
	Keyvalues map[string]interface{} `json:"keyvalues,omitempty"`
}

Metadata is a general purpose data structure as described in the Pinata API docs.

"Similarily to other endpoints, Pinata also allows metadata to be attached to when pinning content by hash. This metadata can later be used for easy querying on what you've pinned with our userPinList request."

func NewMetadata

func NewMetadata(name string) *Metadata

NewMetadata initialises a Meatadata struct with the provided name.

func (*Metadata) Add

func (metadata *Metadata) Add(key string, value interface{}) error

Add will set a keyvalue pair in the metadata struct. Only Strings, Numbers and ISO date are permitted and there is a limit of 10 pairs.

type PinQueueRequest

type PinQueueRequest struct {
	Cid           string                 `json:"hashToPin"`
	PinataOptions map[string]interface{} `json:"pinataOptions,omitempty"`
	Metadata      *Metadata              `json:"pinataMetadata,omitempty"`
}

PinQueueRequest is the request structure as outlined in https://pinata.cloud/documentation#PinByHash

Jump to

Keyboard shortcuts

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