Unwalled.Garden

Status: DRAFT. Part of the upcoming Beaker Browser 0.9 release.

Votes API

Votes are up/down judgments on resources around the Web. They can be set to 1 (upvote) or -1 (downvote).


import {votes} from 'dat://unwalled.garden/index.js'

// read
await votes.list({
  filters: {authors, topics, visiblity},
  sortBy,
  offset,
  limit,
  reverse
})
await votes.tabulate(topic, {
  filters: {authors, visiblity}
})
await votes.get(author, topic)

// write
await votes.set(topic, vote, {visiblity})

Vote

The values returned by vote functions will fit the following object shape:

Attribute Type Usage
url string The URL of the vote record
topic string The URL that the vote is attached to
vote number The value of the vote
createdAt string The timestamp of when the vote claims it was created
updatedAt string The timestamp of when the vote claims it was last updated
author Object The site that authored the vote
 url string
 title string
 description string
 type string[]
visibility string The visibility of the vote

TabulatedVotes

The values returned by tabulate() will fit the following object shape:

Attribute Type Usage
topic string The URL that the votes are attached to
upvotes number The number of upvotes
upvoters Object[] The sites that upvoted the site
 url string
 title string
 description string
 type string[]
downvotes number The number of downvotes
downvoters Object[] The sites that downvoted the site
 url string
 title string
 description string
 type string[]

list(opts)

List the votes on the network.

Param Type Default Usage
opts Object
 filters Object
  authors string|string[] Site URLs
  topics string|string[] URLs
  visibility string 'all' See visibility
 sortBy string 'createdAt' One of: 'createdAt'
 offset number 0
 limit number
 reverse boolean false
Returns
Promise<Vote[]>

tabulate(topic, opts)

Tabulate the votes on a topic.

Param Type Default Usage
topic string Topic URL (required)
opts Object
 filters Object
  authors string|string[] Site URLs
  visibility string 'all' See visibility
Returns
Promise<TabulatedVotes>

get(author, topic)

Get a vote by author and topic.

Param Type Default Usage
author string Site URL (required)
topic string Site URL (required)
Returns
Promise<Vote>

set(topic, vote, opts)

Set the user’s vote on the topic.

Param Type Default Usage
topic string Topic URL (required)
vote number The vote value, must be -1, 0, or 1
opts Object
visibility string 'public' One of: 'public', 'private'
Returns
Promise<Vote>