Giter Club home page Giter Club logo

codingtest-birdhouse-js's Introduction

birdhouse-js

npm version Test status

This is a typescript wrapper around the Smart BirdHouse API.

Usage

npm i @danieloaks/codingtest-birdhouse-js

import API from "@danieloaks/codingtest-birdhouse-js";

const api = new API({
  apiBase: "https://example.com",
});

async function run() {
  const page = 1;
  const entriesPerPage = 15;
  const res = await api.registration.getRegistrationPage(page, entriesPerPage);

  for (const item of res.items) {
    console.log(
      `${item.value}: ${item.birdhouse?.name || "No birdhouse registered"}`,
    );

    if (!item.birdhouse) {
      continue;
    }

    const occupancyPage = 1;
    const occupancyEntriesPerPage = 15;
    const occupancy = await api.occupancy.getOccupancy(
      item.birdhouse.ubidValue,
      occupancyPage,
      occupancyEntriesPerPage,
    );

    for (const state of occupancy.items) {
      console.log(
        `  ${state.createdAt.toLocaleDateString()} - birds: ${
          state.birds
        } - eggs: ${state.eggs}`,
      );
    }
  }
}

run();
c36ba382-959d-48ff-8b72-de092c88d55e: Tessa's Birdhouse
  11/1/2022 - birds: 0 - eggs: 2
  10/30/2022 - birds: 1 - eggs: 2
  10/29/2022 - birds: 1 - eggs: 3
  10/28/2022 - birds: 0 - eggs: 1
91aa01b8-4248-495a-8fc0-9323b4d74e1e: Daniel's Birdhouse
  11/1/2022 - birds: 1 - eggs: 2
  10/30/2022 - birds: 2 - eggs: 21
  10/29/2022 - birds: 4 - eggs: 42
  10/28/2022 - birds: 6 - eggs: 63

codingtest-birdhouse-js's People

Contributors

danieloaks avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.