1.1.1 • Published 3 years ago

huiz-wrapper v1.1.1

Weekly downloads
17
License
MIT
Repository
github
Last release
3 years ago

Node.js API wrapper for Huiz.

This package is still a work in progress.

Installation

npm install huiz-wrapper

or

yarn add huiz-wrapper

then

import { Huiz } from 'huiz-wrapper';

Usage

// Creates Huiz object using a personal access token, set verbose=true if you want to see all requests
const huiz = new Huiz(token, verbose);
// Gets todays eat event instance using the house ID
const event = await huiz.event().getTodaysEatEventInstance(houseId);

Functions

For all of these functions you need a personal access token. For instructions, see Auth.

Documents

// Gets all documents from house given house ID
Huiz.document().getDocumentsFromHouse(houseId);
// Gets document from given document ID (assuming you have access)
Huiz.document().getDocumentFromId(documentId);

Events

All of these function names are self-explanatory

Huiz.event().getEventsFromHouse(houseId);
Huiz.event().getEventFromId(eventId);
Huiz.event().getEventParticipantsFromId(eventId);
Huiz.event().getEventInstanceFromEventId(eventId);
Huiz.event().getOnlyEventInstanceFromEventInstanceId(eventInstanceId);
Huiz.event().getEventAvailabilityFromEventInstanceId(eventInstanceId);
Huiz.event().getEventResponsibilityFromEventInstanceId(eventInstanceId);
Huiz.event().getEventInstanceFromEventInstanceId(eventInstanceId);
Huiz.event().getEventInstanceOnDateWithEventId(eventId, date);
Huiz.event().getEventInstanceOnDateWithSlug(houseId, date, slug);
Huiz.event().getTodaysEatEventInstance(houseId);
Huiz.event().getTodaysChoreEventInstance(houseId);
Huiz.event().setEventAvailabilityWithEventInstanceId(eventInstanceId, availability);

Expenses

Huiz.expense().getExpensesFromHouse(houseId);
Huiz.expense().getExpenseFromExpenseId(expenseId);
// Returns all of the house's expenses with descending date (newest first)
Huiz.expense().getExpensesFromHouseDescendingDate(houseId);
// Returns the i-th expense sorted by date descending
Huiz.expense().getIthExpenseFromHouse(houseId, i);

Houses

// Returns house given house ID (assuming you have access)
Huiz.house().getHouse(houseId);
// Returns all the user's houses
Huiz.house().getHouses();

Products

Huiz.product().getProductsFromHouse(houseId);
Huiz.product().getProductFromId(productId);
Huiz.product().getProductVariantsFromId(productId);

Recipes

Huiz.recipe().getRecipesFromHouse(houseId);
Huiz.recipe().getRecipeFromId(recipeId);
Huiz.recipe().getIngredientsFromRecipe(recipeId);
Huiz.recipe().getStepsFromRecipe(recipeId);
Huiz.recipe().getCommentsFromRecipe(recipeId);

Tags

Huiz.recipe().getTagsFromHouse(houseId);
Huiz.recipe().getTagFromId(tagId);

Units

Huiz.unit().getUnitsFromHouse(houseId);
Huiz.unit().getUnitFromId(unitId);

Users

Huiz.user().getUser(userId);
Huiz.user().getHouseUsers(houseId);

Advanced usage

Every request can also be provided with additional headers and queries. If you want to add your own headers and queries to any request, do the following:

import { Headers, Query } from '../huiz';

const myHeaders: Headers = {
    "Connection": "keep-alive",
}

const myQueries: Query = {
    "order[date]": "asc"
}

Auth

You can create a Huiz object with a personal access token. Provided you have a personal access token, you can store it in a .env file, in the .env.example provided there is space for your own personal access token as well as a default house ID, you can use it as follows:

require('dotenv').config({ path: '.env.local' });
const token = process.env.ACCESS_TOKEN;

const huiz = new Huiz(token);

Keep in mind that you do need the dotenv package to load .env files.

Once authenticated, you'll be able to use all functions in the wrapper. Without authentication, you won't be able to use this wrapper.

1.1.1

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago