Nuked: Probably Microwaved

    msw-client

    2.0.0 • Public • Published

    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!

    Install

    npm i msw-client

    DownloadsWeekly Downloads

    1

    Version

    2.0.0

    License

    ISC

    Last publish

    Collaborators

    • daveloper87