Expand description
§Initializing the API
use pinata_sdk::PinataApi;
let api = PinataApi::new("api_key", "secret_api_key").unwrap();
// test that you can connect to the API:
let result = api.test_authentication().await;
if let Ok(_) = result {
// credentials are correct and other api calls can be made
}
§Usage
§1. Pinning a file
Send a file to pinata for direct pinning to IPFS.
use pinata_sdk::{ApiError, PinataApi, PinByFile};
let api = PinataApi::new("api_key", "secret_api_key").unwrap();
let result = api.pin_file(PinByFile::new("file_or_dir_path")).await;
if let Ok(pinned_object) = result {
let hash = pinned_object.ipfs_hash;
}
If a directory path is used to construct PinByFile
, then pin_file()
will upload all the contents
of the file to be pinned on pinata.
§2. Pinning a JSON object
You can send a JSON serializable to pinata for direct pinning to IPFS.
use pinata_sdk::{ApiError, PinataApi, PinByJson};
use std::collections::HashMap;
let api = PinataApi::new("api_key", "secret_api_key").unwrap();
// HashMap derives serde::Serialize
let mut json_data = HashMap::new();
json_data.insert("name", "user");
let result = api.pin_json(PinByJson::new(json_data)).await;
if let Ok(pinned_object) = result {
let hash = pinned_object.ipfs_hash;
}
§3. Unpinning
You can unpin using the PinataApi::unpin()
function by passing in the CID hash of the already
pinned content.
Structs§
- Change
PinMetadata - Pin metadata struct to update metadata of pinned items.
- Hash
PinPolicy - Represents a PinPolicy linked to a particular ipfs pinned hash
- PinBy
File - Request object to pin a file
- PinBy
Hash - Request object to pin hash of an already existing IPFS hash to pinata.
- PinBy
Hash Result - Represents response of a pinByHash request.
- PinBy
Json - Request object to pin json
- PinJob
- Pin Job Record
- PinJobs
- Represents a list of pin job records for a set of filters.
- PinJobs
Filter - Filter parameters for fetching PinJobs
- PinJobs
Filter Builder - Builder for
PinJobsFilter
. - PinList
- Result of request to get pinList
- PinList
Filter - Options to filter your pin list based on a number of different options
- PinList
Filter Builder - Builder for
PinListFilter
. - PinList
Item - A pinned item gotten from get PinList request
- PinList
Item Region Policy - RegionPolicy active on the PinListItem
- PinList
Metadata - Pin metadata returns from PinList query
- PinMetadata
- Pin metadata stored along with files pinned.
- PinOptions
- Used to add additional options when pinning by hash
- PinPolicy
- Pinata Pin Policy Regions
- Pinata
Api - API struct. Exposes functions to interact with the Pinata API
- Pinned
Object - Represents a PinnedObject
- Region
Policy - Region and desired replication for that region
- Total
Pinned Data - Results of a call to get total users pinned data
Enums§
- ApiError
- All possible error returned from this SDK defined as variants of this enum.
- JobStatus
- Status of Jobs
- Metadata
Value - Possible MetadaValues
- PinJobs
Filter Builder Error - Error type for PinJobsFilterBuilder
- PinList
Filter Builder Error - Error type for PinListFilterBuilder
- PinList
Filter Status - Status used with PinListFilterBuilder to filter on pin list results.
- Region
- All the currently supported regions on Pinata
- Sort
Direction - Sort Direction
Type Aliases§
- Metadata
KeyValues - alias type for HashMap<String, MetadataValue>