Javascript ========== Installation ------------ For use in Node: .. code-block:: bash npm install skywise-model Configuration ------------- To configure the client or service: .. code-block:: javascript 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: .. code-block:: javascript 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_ () - listModels_ () - listModelVariables_ () - getLatestForecast_ () - getForecast_ () - listForecasts_ () - getTimeSeries_ () .. _getModel: **getModel** (*modelId*) Returns a Promise for a Response from the `Model Information endpoint `_. **Request Syntax** .. code-block:: javascript 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: **listModels** () Returns a Promise for a Response from the `List Models endpoint `_. **Request Syntax** .. code-block:: javascript 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: **listModelVariables** (*modelId*) Returns a Promise for a Response from the `Model Variables endpoint `_. **Request Syntax** .. code-block:: javascript 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: **getLatestForecast** (*modelId*) Returns a Promise for a Response from the `Latest Forecast endpoint `_. **Request Syntax** .. code-block:: javascript 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: **getForecast** (*forecastId*) Returns a Promise for a Response from the `Forecast Information endpoint `_. **Request Syntax** .. code-block:: javascript 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: **listForecasts** (*modelId*) Returns a Promise for a Response from the `List Forecasts endpoint `_. **Request Syntax** .. code-block:: javascript 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: **getTimeSeries** (*forecastId*, *variableId*) Returns a Promise for a Response from the `Time Series endpoint `_. **Request Syntax** .. code-block:: javascript 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.