Giter VIP home page Giter VIP logo

pinata-java-sdk's Introduction

Pinata SDK

Unofficial Java SDK for Pinata.

Overview

This Pinata Java SDK enables interaction with the Pinata API. Pinata is a pinning service that allows you to upload and manage files on IPFS.

Install

Maven

For Maven, add the following sections to your pom.xml (replacing $LATEST_VERSION):

  <dependencies>
    <dependency>
      <groupId>io.github.zinebfadili</groupId>
      <artifactId>pinata-java-sdk</artifactId>
      <version>$LATEST_VERSION</version>
    </dependency>
  </dependencies>

Setup

Create a Pinata instance without API keys:

  Pinata pinata = new Pinata();

Or, with Pinata API keys:

  Pinata pinata = new Pinata("yourPinataApiKey", "yourPinataSecretApiKey");

Test that you can connect to the API with:

  // If you created a Pinata instance with keys
  try {
    PinataResponse authResponse = pinata.testAuthentication();
    // If a PinataException hasn't been been thrown, it means that the status is 200  
    System.out.println(authResponse.getStatus()); // 200
  } catch (PinataException e) {
    // The status returned is not 200
  } catch (IOException e) {
    // Unable to send request
  }
  
  // If you created a Pinata instance without keys
  try {
    PinataResponse authResponse = pinata.testAuthentication("yourPinataApiKey", "yourPinataSecretApiKey");
    // If a PinataException hasn't been been thrown, it means that the status is 200  
    System.out.println(authResponse.getStatus()); // 200
  } catch (PinataException e) {
    // The status returned is not 200
  } catch (IOException e) {
    // Unable to send request
  }

Usage

The available operations are:

  • Pinning

    • hashMetadata
    • hashPinPolicy
    • pinByHash
    • pinFileToIPFS
    • pinFromFs
    • pinJobs
    • pinJSONToIPFS
    • unpin
    • userPinPolicy
  • Data

    • testAuthentication
    • pinList
    • userPinnedDataTotal

Please refer to the Pinata-SDK documentation for the explanation of the purpose of these methods. The method names are the same but in camel case.

If you have created a Pinata instance using your keys, you don't need to specify them again when calling the methods.

As an example, here is a call to pin by hash:

  // If you created a Pinata instance with keys
  try {
    PinataResponse pinResponse = pinata.pinByHash("yourHash");
    // If a PinataException hasn't been been thrown, it means that the status is 200  
    System.out.println(pinResponse.getStatus()); // 200
  } catch (PinataException e) {
    // The status returned is not 200
  } catch (IOException e) {
    // Unable to send request
  }
  
  // If you created a Pinata instance without keys
  try {
    PinataResponse pinResponse = pinata.pinByHash("yourPinataApiKey", "yourPinataSecretApiKey", "yourHash");
    // If a PinataException hasn't been been thrown, it means that the status is 200  
    System.out.println(pinResponse.getStatus()); // 200
  } catch (PinataException e) {
    // The status returned is not 200
  } catch (IOException e) {
    // Unable to send request
  }

The return value contains two attributes:

  • status : an Integer containing the response status
  • body : a String containing the response body

Methods with optional parameters (for example pinByHash and its options parameter) are overloaded so that they can be invoked without.

Remarks

Please note that this version only supports IPFS peer addresses protocols and formats that are handled in the Multiformats Java Implementation. This means, for example, that addresses containing p2p-webrtc-start or in Base1 are not supported.

License

MIT

pinata-java-sdk's People

Contributors

mcerina avatar zinebfadili avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.