# relike-utils

> Javascript library for interacting with the ReLike universal liking service.

Latest version **0.2.6** (published 2017-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install relike-utils
pnpm add relike-utils
yarn add relike-utils
bun add relike-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2017-07-27 |
| First published | 2017-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Noman |
| Maintainers | noman-land |
| Keywords | ethereum |

## Links

- npm: https://www.npmjs.com/package/relike-utils
- Repository: https://github.com/noman-land/relike-utils
- Homepage: https://github.com/noman-land/relike-utils#readme
- Issues: https://github.com/noman-land/relike-utils/issues
- npm.io page: https://npm.io/package/relike-utils

## Dependencies (4)

- [q](https://npm.io/package/q.md) ^1.5.0
- [web3](https://npm.io/package/web3.md) ^0.18.4
- [babel-register](https://npm.io/package/babel-register.md) ^6.24.1
- [truffle-contract](https://npm.io/package/truffle-contract.md) ^2.0.0

## Recent versions

- 0.2.6 (latest) — 2017-07-27
- 0.2.5 — 2017-07-18
- 0.2.4 — 2017-07-18
- 0.2.3 — 2017-07-18
- 0.2.2 — 2017-07-18
- 0.2.1 — 2017-07-18
- 0.2.0 — 2017-07-18
- 0.1.9 — 2017-06-11
- 0.1.8 — 2017-06-11
- 0.1.7 — 2017-06-11
- 0.1.6 — 2017-06-11
- 0.1.5 — 2017-06-11
- 0.1.4 — 2017-06-11
- 0.1.3 — 2017-06-11
- 0.1.2 — 2017-06-11
- … 2 more at https://npm.io/package/relike-utils/versions

## README

# relike-utils

[![Join the chat at https://gitter.im/relike-utils/Lobby](https://badges.gitter.im/relike-utils/Lobby.svg)](https://gitter.im/relike-utils/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![npm version](https://badge.fury.io/js/relike-utils.svg)](https://badge.fury.io/js/relike-utils)

Javascript library for interfacing with ReLike, the decentralized public liking service, powered by Ethereum.

### Documentation

Everything in ReLike centers around the concept of an `entityId`. This is just a string of text but it represents anything that can be liked. Some examples of `entityId`s include:

    "cat"
    "dog"
    "Terminator 3"
    "🍕"
    "QmW84daiALvufneDcjDeoTFKR1bGQuHFUFv1fcSSRpmuCN"
    "https://www.theguardian.com/sport/2017/jun/10/nba-finals-cleveland-cavaliers-golden-state-warriors-game-4"

You can like or dislike any `entityId` you can think of. The sky is the limit. In its alpha stage it's very permissive so something is bound to break.

## How to use

1. Install the package

    ```bash
    npm i --save relike-utils
    ```
    
2. Import the package into your project

    ```js
    import ReLikeUtils from 'relike-utils';
    ```
    
3. Instantiate a `ReLikeUtils` object. This has all the methods you need to interact with the `ReLike` liking service on Ethereum.

    ```js
    const reLikeUtils = new ReLikeUtils();
    ```
    
    Upon instantiation, `ReLikeUtils` will automatically connect to whatever `currentProvider` it sees. An override is possible inside the config object. Please see below. 
    
    It will also start listening for [`ItemLiked`](https://github.com/noman-land/relike-utils/blob/master/contracts/ReLike.sol#L28) events. Every time someone likes or dislikes something on ReLike an event is fired. A callback can be provided to receive these events. Please see below.
     
    It will also start listening for any time the user changes accounts. A callback can be provided to receive the address of the new account. Please see below
    
    The constructor can optionally be given a config object with one or more of the following 
    
    ```js
    const reLikeUtils = new ReLikeUtils({
      // This function will be called every time ReLike notices the primary account changing
      onAccountChangeEvent: function(newAccount) {},
      
      // This function will be called every time ReLike gets an event notification of a new like
      onLikeEvent: function({ dislikes, entityId, likes, rating, user }) {},
      
      // This function will be fired when ReLike is initializing and should return a web3 object that ReLike will use instead of the one it finds
      // It receives the current web3 object if one was found
      web3Override: function(currentWeb3Object) {},
    });
    ```

#### List of methods and what they do

Most methods return promises.

```js
reLikeUtils.like(entityId)
```

Takes any string and likes it.

```js
reLikeUtils.unlike(entityId)
```

Takes any previously liked string and unlikes it. Will throw an error if the user hasn't liked this entity yet.

```js
reLikeUtils.dislike(entityId)
```

takes any string and dislikes it.

```js
reLikeUtils.unDislike(entityId)
```

Takes any previously disliked string and undislikes it. Will throw an error if the user hasn't disliked this entity yet.

```js
reLikeUtils.getActiveAccount()
```

Returns the user address currently active in web3.

```js
reLikeUtils.getMyRating(entityId)
```

Returns the user's current rating for a given string. The values are

    0 = unrated
    1 = like
    2 = dislike
    
```js
reLikeUtils.getLikeCount(entityId)
```

This returns an object that contains the aggregated like counts for any entity. The object is of the shape:

```js
{
  dislikes: 2,
  likes: 4
}
```

---
_Source: https://npm.io/package/relike-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
