npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

msw-client

v2.0.0

Published

Magic Seaweed API forecast data client

Downloads

22

Readme

Build Status Coverage Status Code Climate NPM Dependency Status devDependency Status

msw-client

Description

Node client library to allow easy communication with the Magic Seaweed API

You will Need to contact Magic Seaweed in order to get an API key. Please make sure you read their terms first.

See release notes for new release details.

Usage

Available on npm. NOTE: Version 2.0.0 is only supported in Node 5+. For versions lower than Node 5 use msw-client v1.4.1

firstly you need to install into your dependencies:

npm install msw-client --save

Constructor, API key and SpotId

Then simply create an instance of the client:

const MSW = require('msw-client');
const MswClient = new MSW({
    apikey: 'YOUR_API_KEY',
    spot_id: 2 // must be a number
});

Both apikey and spot_id are required.

spot_id indicates the spot / beach you want to get forecast data for

spot_id: 1449 // this is rest bay

To figure out your spot_id visit the surf report for that beach on the Magic Seaweed website and look at the url:

http://magicseaweed.com/Porthcawl-Rest-Bay-Surf-Report/1449/ - spot id is the last parameter

Once set in the constructor, the spot_id can be retrieved or updated at any point:

MswClient.getSpotId(); // 2
MswClient.setSpotId(3); // must be a number

To make a request simply call:

MswClient.request().then(data => {
  console.log(data);
}).catch(err => {
  console.log(err);
});

These will respond with an array of objects as documented MSW API

Units

As of version 1.1.0 you can now set the unit to your country region so that measurements and temperature are returned as you would expect in your region.

e.g. temperature returns as F for US requests.

There are three valid unit types: 'uk', 'us' or 'eu'.

You can set units on the constructor:

const MSW = require('msw-client');
const MswClient = new MSW({
    apikey: 'YOUR_API_KEY',
    spot_id: 2 // must be a number
    units: 'us' // must be a string
});

or via the setUnits function

MswClient.setUnits('us');
MswClient.getUnits(); // returns 'us';

If not set it will default to uk

MswClient.getUnits(); // returns 'uk';

Fields

You can also add fields to filter the data you want.

This can either be done via the constructor:

const MSW = require('msw-client');
const MswClient = new MSW({
    apikey: 'YOUR_API_KEY',
    spot_id: 2,
    fields: ['timestamp', 'wind'] // must be an array
});

or at any point in your code via functions:

MswClient.addField('timestamp'); // add single field by string name
MswClient.addFields(['timestamp', 'wind']); // add fields by array

You can also retrieve and remove fields:

MswClient.getFields(); // ['timestamp', 'wind'] returns fields array
MswClient.removeField('timestamp'); // remove single field by string name
MswClient.removeAllFields(); // I wonder what this does...

A list of fields are available based on the response data. More details here: MSW API

Feel free to submit issues and contribute.

Surfs Up!