metrafin
v1.0.0Metrafin API Node
Official Metrafin API Client for Node.js
GitHub | NPM | Official API Documentation
Install
npm i metrafin
const App = require('metrafin')
Usage
Create application
Create an application with its private token.
const myApp = new App('VLeIjSNigss5eqLcNf5Snv2kh_d-HWOv1-ojr952gpW0CyKt')
Resolve users
// in async context
const userInfoA = await myApp.resolveUser('username', 'ethan')
// => { error: null, userId: 'd2ed3320-af45-4136-bc51-bb48a62da7dc', username: 'ethan' }
// or...
const userInfoB = await myApp.resolveUser('userId', '9175009b-b215-4be8-a3a8-88322757804d')
// => { error: null, userId: 'd2ed3320-af45-4136-bc51-bb48a62da7dc', username: 'ethan' }
Create authorization instance using authorization code (authorization_code
)
Create an auth instance using an authorization_code
. You may access the accessToken as a property of the created authorization if all is successful.
It is recommended that you check that all of the OAuth scopes you expect are present in the auth instance's scopes
array.
const auth = await myApp.auth('rmxQPAll1kEhsc8u-IPwBkwyNdixJCSf', 'authorizationCode')
console.log('Auth accessToken: ' + auth.accessToken)
console.log('Auth userId: ' + auth.userId)
console.log('Auth scopes: ' + auth.scopes)
console.log('Auth expires: ' + auth.expires)
Create authorization instance using access token
Create an auth instance using an access token
.
const auth = await myApp.auth('rmxQPAll1kEhsc8u-IPwBkwyNdixJCSf', 'accessToken')
console.log('Auth accessToken: ' + auth.accessToken)
console.log('Auth userId: ' + auth.userId)
console.log('Auth scopes: ' + auth.scopes)
console.log('Auth expires: ' + auth.expires)
Get user profile
See profile information documentation for details about the profile response.
await auth.getProfile()
Get user permissions
See permissions documentation for details about the permissions response.
await auth.getPermissions()
Get user HonorScore
See HonorScore documentation for details about the HonorScore response.
await auth.getHonorScore()
Create reputation event
See reputation event documentation for details about reputation events.
await auth.createReputationEvent({
'context': 'public_comment',
'tag': 'spam',
'type': 'negative',
'description': 'Excessive commenting on a video'
})
// => {"error": null, "eventId": "0f6ca352-480a-468d-a99f-43580ccf4aff"}
List reputation events
await auth.getReputationEvents()
// => {"error": null, "reputationEvents": [ ... ]}
Update active status of reputation event
await auth.setReputationEventActive('ef8c4ce3-2f02-4647-ab5e-727387184e15', false)
// This will deactivate the reputation event with ID ef8c4ce3-2f02-4647-ab5e-727387184e15.
Feedback and questions
If you have questions or feedback about the package, feel free to let us know in GitHub issues.
Feel free to contribute through PRs as well. :)