-
Notifications
You must be signed in to change notification settings - Fork 0
Testing Process
- npm >= 6.14
- node >= 14
At the moment, the easiest way is to clone the repo at https://github.com/FAIRsharing/FAIRSharing-API-Client and install npm dependencies (the npm package will be published after the first test phase). You can then run:
npm pack
This generates a .tgz file. Create a new project, move the .tgz file there.
mv fairsharing-api-client-0.0.1-alpha.0.tgz ~/path/to/my/project/fairsharing-api-client-0.0.1-alpha.0.tgz
Now, in your package.json
file, you can add the dependency. Note how the library version actually points the archive filepath instead of the actual version number.
{
"dependencies": {
"fairsharing-api-client": "./fairsharing-api-client-0.0.1-alpha.0.tgz"
}
}
Finally, you can run npm install
in your project.
// import the library and create the client.
const fairsharingClient = require("fairsharing-api-client")
let client = fairsharingClient("https://dev-api.fairsharing.org")
<!-- Import the code -->
<script type="application/javascript" src="./node_modules/fairsharing-api-client/dist/fairsharing.min.js">
</script>
<!-- Alternatively, you can use it directly from the CDN
<script type="application/javascript" src="https://fairsharingapiclientcdn.netlify.app/fairsharing.min.js">
</script>
-->
<!-- Now, client is a function available as a var -->
<script type="module">
let client = fairsharingClient("https://dev-api.fairsharing.org")
</script>
Step 3: register an account at https://fairsharing.netlify.app/#/accounts/signup
You will receive an email containing a link. Clicking that link will redirect on our beta version where your account doesn't exist. Thus, expect an error message. Copy the value of confirmation_token
from the URL and go to this new URL:
https://fairsharing.netlify.app/#/users/confirmation?confirmation_token=MY_TOKEN_GOES_HERE
Alternatively, you can programmatically validate the token. Copy the value of the confirmation_token and go back to your html or javascript file:
let client = fairsharingClient("https://dev-api.fairsharing.org")
client.confirmAccount("MyTokenValue").then((res) => { console.log(res) }); // confirm your account
// If your token is expired, you can send a new one:
client.resendConfirmation({email: "[email protected]"}).then((res) => { console.log(res) });
Without this step you will not be able to interact with the client (error 401 or 403).
Go to https://fairsharing.netlify.app/, login and click your name to access your profile page. On your profile page, at the top right click the menu button then "Edit Profile". At the bottom of the page, you can add an existing organisation from the left table.
// When in the browser, you can enable a cache that relies on the localStorage. The input is in hours, default to 24. You will get a warning if trying to enable the cache in node.
client.enableCache(1)
// Login with a promise. Also works with async if needed.
client.login("user", "password").then(async () => {
let country = await client.getCountry(1); // First request hits the servers
console.log(country)
country = await client.getCountry(1); // Second request hits the cache
console.log(country)
await client.logout(); // Logout to revoke your token
}).catch((e)=> {
console.log("ERROR:", e)
}).finally(() => {
client.clearCache(); // Clear the cache when you are done.
});
Step 6: check the documentation: https://fairsharingapidoc.netlify.app/
For the list of methods you can use.
Create a new issue and select the "Test Report" template.