Git Product home page Git Product logo

dat-pinning-service-client's Introduction

dat-pinning-service-client

Client API for Dat pinning services. Conforms to the Dat Pinning Service API.

API

To create a client:

const {createClient} = require('dat-pinning-service-client')
createClient('https://my-pinning-service.com', {username: 'bob', password: 'hunter2'}, (err, client) => {
  if (err) throw err
  // ...
})

Alternatively:

const {DatPinningServiceClient} = require('dat-pinning-service-client')
var client = new DatPinningServiceClient('https://my-pinning-service.com')
client.fetchPSADoc(err => {
  if (err) throw err
  client.login('bob', 'hunter2', err => {
    if (err) throw err
    // ...
  })
})

All of the methods provide the response body and give an error if a non-2xx response is received. The errors will have the .statusCode and .responseBody set.

createClient(hostUrl[, login], cb)

Create a new client object. Will fetch the PSA document and run login if the creds are specified.

new DatPinningServiceClient(hostUrl[, psaDoc])

Create a new client object. You can optionally provide the PSA document, which is useful if you've cached it from a previous session.

client.setPSADoc(psaDoc)

Manually set the PSA document (useful if you've cached it from a previous session). You can find the PSA doc on client.psaDoc.

client.setSession(token)

Manually set the session token (useful if you've cached it from a previous session). You can find the token on client.sessionToken.

client.login(username, password, cb)

Start a session. You can check client.hasSession to see if a session token has been stored.

client.logout(cb)

End the session.

client.getAccount(cb)

Get the account info for the current session. Returns

{
  email: String, the accounts email (required)
  username: String, the accounts username (required)
  diskUsage: Number, how much disk space has the user's data taken? (optional)
  diskQuota: Number, how much disk space can the user's data take? (optional)
  updatedAt: Number, the Unix timestamp of the last time the user account was updated (optional)
  createdAt: Number, the Unix timestamp of the last time the user account was updated (optional)
}

client.listDats(cb)

Get the dats pinned by the user. Returns

{
  items: [{
    url: String, dat url
    name: String, optional shortname assigned by the user
    title: String, optional title extracted from the dat's manifest file
    description: String, optional description extracted from the dat's manifest file
    additionalUrls: Array of Strings, optional list of URLs the dat can be accessed at
  }]
}

client.addDat({url, name, domains}, cb)

Pin a dat. Params:

  • url String, required url/key of the dat
  • name String, optional shortname for the archive
  • domains Array of Strings, optional list of domain-names the dat should be made available at

client.removeDat(url, cb)

Unpin a dat. Params:

  • url String, required url/key of the dat

client.getDat(url, cb)

Get a pinned dat. Returns:

{
  url: String, dat url
  name: String, optional shortname assigned by the user
  title: String, optional title extracted from the dat's manifest file
  description: String, optional description extracted from the dat's manifest file
  additionalUrls: Array of Strings, optional list of URLs the dat can be accessed at
}

client.updateDat(url, {name, domains}, cb)

Update a pinned dat. Params:

  • url String, required url/key of the dat
  • name String, optional shortname for the archive
  • domains Array of Strings, optional list of domain-names the dat should be made available at

CLI tool

Small utility for testing endpoints:

npm i -g dat-pinning-service-client
dat-pinning-service-client https://my-pinning-service.com bob hunter2 getDat 9900f9aad4d6e79e0beb1c46333852b99829e4dfcdfa9b690eeeab3c367c1b9a

The usage is:

dat-pinning-service-client [service] [username] [password] [action] [args...]

dat-pinning-service-client's People

Contributors

pfrazee avatar rangermauve 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.