Javascript

Installation

For use in Node:

npm install skywise-model

Configuration

To configure the client or service:

var Client = require('skywise-model/client')

let appId = 'your-app-id',
    appKey = 'your-app-key',
    client = new Client(appId, appKey)

Try It Out

If you can obtain a list of models, you should be good to go:

client.listModels().then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    for(let model of json){
        console.log(`${model.name} - ${model.description}`)
    }
})

Client

The client provides a low-level interface that correlates directly to the HTTP methods in the Model API. Its methods follow the pattern of fetch, returning Promises for Response objects from the API.

Available methods:

getModel (modelId)

Returns a Promise for a Response from the Model Information endpoint.

Request Syntax

let modelId = 'weatherops-global'

client.getModel(modelId).then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    console.log(`${json.name} - ${json.description}`)
})

Parameters

  • modelId (String:required) – this can be either the id or the name of the model.

listModels ()

Returns a Promise for a Response from the List Models endpoint.

Request Syntax

client.listModels().then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    for(let model of json){
        console.log(`${model.name} - ${model.description}`)
    }
})

listModelVariables (modelId)

Returns a Promise for a Response from the Model Variables endpoint.

Request Syntax

let modelId = 'my-model-id'

client.listForecastVariables(modelId).then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    for(let variable of json){
        console.log(`${variable.name} - ${variable.description}`)
    }
})

Parameters

  • modelId (String:required) – the id of the model.

getLatestForecast (modelId)

Returns a Promise for a Response from the Latest Forecast endpoint.

Request Syntax

let modelId = 'weatherops-global'

client.getLatestForecast(modelId).then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    console.log(`${forecast.id} - ${forecast.initTime}`)
})

Parameters

  • modelId (String:required) – the id of the model.

getForecast (forecastId)

Returns a Promise for a Response from the Forecast Information endpoint.

Request Syntax

let forecastId = 'my-forecast-id'

client.getForecast(forecastId).then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    console.log(`${forecast.id} - ${forecast.initTime}`)
})

Parameters

  • forecastId (String:required) – the id of the forecast.

listForecasts (modelId)

Returns a Promise for a Response from the List Forecasts endpoint.

Request Syntax

let modelId = 'weatherops-global'

client.listForecasts(modelId).then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    for(let forecast of json){
        console.log(`${forecast.id} - ${forecast.initTime}`)
    }
})

Parameters

  • modelId (String:required) – the id or name of the model.

getTimeSeries (forecastId, variableId)

Returns a Promise for a Response from the Time Series endpoint.

Request Syntax

let forecastId = 'my-forecast-id',
    variableName = 'my-variable-name'

client.getTimeSeries(forecastId, variableName, latitude, longitude).then(function(response){
    if(!response.ok){
        throw Error(response.statusText)
    }
    return response.json()
}).then(function(json){
    for(let item of json.series){
        console.log(`${item.validTime} - ${item.value} ${json.unit.label}`)
    }
})

Parameters

  • forecastId (String:required) – the forecast id.
  • variableName (String:required) – the variable name.
  • latitude (Number:required) – the latitude of your time series request.
  • longitude (Number:required) – the longitude of your time series request.