@interep/api
v0.8.0
Published
A JS library to wrap the APIs from the Interep reputation service.
Downloads
52
Readme
Interep provides HTTP endpoints to interact with the reputation service. This library allows you to use those APIs with a simple JavaScript library.
🛠 Install
NPM or Yarn
Install the @interep/api
package with npm:
npm i @interep/api --save
or yarn:
yarn add @interep/api
CDN
You can also load it using a script
tag using unpkg:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/@interep/api/"></script>
or JSDelivr:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@interep/api/"></script>
📜 Usage
# new API(network: Network): API
import { API } from "@interep/api"
const api = new API()
const goerliApi = new API("goerli")
const kovanApi = new API("kovan")
const localApi = new API("local")
console.log(api.url) // "https://app.interep.link/api/v1"
console.log(goerliApi.url) // "https://goerli.interep.link/api/v1"
console.log(kovanApi.url) // "https://kovan.interep.link/api/v1"
console.log(localApi.url) // "http://localhost:3000/api/v1"
# api.getProviders(): Promise<string[]>
const providers = await api.getProviders()
API: api/v1/providers
# api.getGroups(): Promise<any[]>
const groups = await api.getGroups()
API: api/v1/groups
# api.getGroup(parameters: GetGroupRequest): Promise<any>
const group = await api.getGroup({
provider: "twitter",
name: "gold"
})
# api.getGroupMembers(parameters: GetGroupMembersRequest): Promise<string[]>
const members = await api.getGroupMembers({
provider: "twitter",
name: "gold",
limit: 1,
offset: 1
})
# api.hasMember(parameters: HasMemberRequest): Promise<boolean>
// For any provider group.
const hasMember = await api.hasMember({
provider: "twitter",
member: "1231231..."
})
// For specific group.
const hasMember = await api.hasMember({
provider: "twitter",
name: "gold",
member: "1231231..."
})
API (method: get): /api/v1/groups/:provider/:name/:member
# api.addMember(parameters: AddMemberRequest): Promise<boolean>
// For Web2 providers.
await api.addMember({
provider: "twitter",
name: "gold",
member: "1231231...",
authenticationHeader: "token <OAuth-token>"
})
// For Web3 providers.
await api.addMember({
provider: "poap",
name: "devcon4",
member: "1231231...",
userAddress: "0xueaoueao",
userSignature: "aueouaoe"
})
API (method: post): /api/v1/groups/:provider/:name/:member
# api.getMerkleTreeProof(parameters: GetMerkleTreeProofRequest): Promise<any>
const proof = await api.getMerkleTreeProof({
provider: "twitter",
name: "gold",
member: "1231231..."
})
# api.getMerkleTreeLeaves(parameters: GetMerkleTreeLeavesRequest): Promise<string[]>
const leaves = await api.getMerkleTreeLeaves({
root: "1212121...",
limit: 10
})
API: /api/v1/trees/:root
# api.hasMerkleTreeLeaf(parameters: HasMerkleTreeLeafRequest): Promise<boolean>
const hasMerkleTreeLeaf = await api.hasMerkleTreeLeaf({
root: "1212121...",
leaf: "2122131..."
})
# api.getMerkleTreeRootBatches(): Promise<any[]>
const rootBatches = await api.getMerkleTreeRootBatches()
API: /api/v1/batches
# api.getMerkleTreeRootBatch(parameters: GetMerkleTreeRootBatchRequest): Promise<any>
const rootBatch = await api.getMerkleTreeRootBatch({
root: "1212121..."
})