Welcome to grif's javascript wrapper, built with js, compatible with browser src and module imports; works both on the browser context and on the node context. If you encounter any issues or want to suggest features, please, create an issue.
Install with npm npm install @grifpkg/install
, then:
const Grif = require("@grifpkg/client")
/*
Resource and Release classes available through:
Grif.Resource, Grif.Release
*/
import {Grif, Release, Resource} from ("@grifpkg/client")
<script src="https://unpkg.com/@grifpkg/client/target/grifpkg.min.js"></script>
<script>
// only the Grif class is available
const grif = new Grif()
</script>
Please, avoid querying whenever it's possible, try fetching and caching resources and releases as much as possible; the REST API has an usage limit; if your project isn't aiming to create alternative clients for grifpkg but getting resource and release information, these projects are best suited for you:
- https://spiget.org/documentation/
- https://github.com/SpigotMC/XenforoResourceManagerAPI
For the folling examples, I'll be using ES6, using import, were the file accessing grifpkg-js should have the wrapper imported with import {Grif, Release, Resource} from ("@grifpkg/client")
and the top of the file.
new Grif().queryResource("resourceName", [optional_resourceAuthorName], [optional, service id; 0=spigot]).then((resources)=>{
if(resources.length<=0) return;
console.log("top match", resources[0])
})
Resource.fromId("grifResourceId").then((resource)=>{
console.log(resource)
})
Release.fromId("releaseId").then((release)=>{
console.log(release)
})
If you don't know the release id, this endpoint it's flexible and supports name-based querying if you know the parent resource
Release.fromId(null, resource, [optional_versionTag_nullOrUndefined_for_latest]).then((release)=>{
console.log(release)
})
You can access the same function from the Resource context by using
Resource.getRelease(optional_versionTag_nullOrUndefined_for_latest).then((release)=>{
console.log(release)
})
You can also list every single release for a Resource
Resource.getReleases().then((releases)=>{
console.log(releases)
})
Release.download(optional_username, optional_password).then((downloadableRelease)=>{
console.log("download using", downloadableRelease.url)
})
Grif will automatically login if a session is cached on the local storage, so you only need to run Grif.login()
once as long as the hostname doesn't change and you don't pass false
as a login argument.
Login by using GitHub's oAuth popup, must be triggered by a click in order to prevent popup blocking. You can pass false as a login argument (Grif.login(false)
) for prevent session saving with localStorage; default is true
.
Grif.login().then((session)=>{
console.log("logged in" session),
})
You can find a session hash by logging in using a popup, exploring the localstorage and getting the hash by base64-decoding it, or access https://api.grifpkg.com/rest/1/login/
, then open the console on the resulting page after logging in with GitHub; you'll get an alert since you opened the URL directly and the parent context isn't available; the hash is available under data.session.hash
.
const grif = new Grif("sessionHash")
const grif = new Grif()
grif.logout()
You can suggest download URLs for any suggestable object, such as Resource or Release. Resource suggestions are useful if all releases have a suggested URL but you still want a default download for new releases.
- Variables
- {{jsonResult}}: available only if you has an intermediate JSON request
- {{resourceId}}: external resource id
- {{resourceName}}: resource name
- {{releaseVersion}}: version tag
- {{releaseId}}: external release id
- {{releaseCreation}}: creation unix time
The variables may be used on the url schema and on the jsonURL
// no JSON
object.suggest("urlSchema")
// JSON (adds {{jsonResult}} variable); see https://jsonpath.com/
object.suggest("urlSchema", "jsonURL", "jsonPath")