ShortTermForecast by Year and Letter

Get short term forecast by Cap Id, Year and Letter

by CAPDev

HTML

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/8.7/styles/agate.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.7/highlight.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<div class="container body-content">
    
<h3>Short Term Forecast</h3>

    <p>Get short term forecast by cap id, Year and Letter</p>
    <div ng-controller="shortTermForecastYearLetterCtrl as vm">
        <div>
            <div class="form-group">
                <label>Authentication Token</label>
                <textarea class="form-control" cols="15" rows="9" ng-model="vm.token" placeholder="authentication token" required></textarea>
            </div>
            <div class="form-group">
                <label>Cap Id</label>
                <input type="text" class="form-control" placeholder="cap id" ng-model="vm.capId" required>
            </div>
           <div class="form-group">
            <label>Year</label>
            <input type="text" class="form-control" placeholder="year" ng-model="vm.year" required>
        </div>
        <div class="form-group">
            <label>Letter</label>
            <input type="text" class="form-control" placeholder="letter" ng-model="vm.letter" required>
        </div>
            <div class="form-group">
                <label>Mileage</label>
                <input type="text" class="form-control" placeholder="mileage" ng-model="vm.mileage" required>
            </div>
            <div class="form-group">
                <label>Valuation Date</label>
                <input type="text" class="form-control" placeholder="Valuation Date" ng-model="vm.valuationDate" required>
            </div>
            <div class="form-inline" style="margin-top: 20px;">
                <div class="form-group">
                    <label>Month From</label>
                    <input...

CSS

body {
    padding-top:0;
    padding-bottom: 20px;
}
.body-content {
    padding-left: 15px;
    padding-right: 15px;
}
input, select, textarea {
    max-width: 280px;
}
pre, code {
    max-height: 400px;
}
p {
    font-size:16px;
}

JavaScript

angular.module('capApiDemo', []);

angular.module('capApiDemo').directive('ngHighlight', function () {
    return {
        restrict: 'A',
        link: function ($scope, element, attrs) {
            $scope.$watch(attrs.ngHighlight, function (newValue) {
                element.text(newValue);
                hljs.highlightBlock(element[0]);
            });
        }
    };
});

angular.module('capApiDemo')
    .controller('shortTermForecastYearLetterCtrl', shortTermForecastYearLetterCtrl);

shortTermForecastYearLetterCtrl.$inject = ['$http'];

function shortTermForecastYearLetterCtrl($http) {
    var vm = this;
    vm.token = '';
    vm.capId = '';
    vm.year = '';
    vm.letter = '';
    vm.shortTermForecast = '';
    vm.selectedFormat = 'application/json';

    vm.getShortTermForecast = getShortTermForecast;

    function getShortTermForecast() {
        vm.shortTermForecast = '';
        var options = getOptions();
        var requestUrl = 'https://services.cap.co.uk/ShortTermForecast/v1/1/byYearLetter?capId=' + vm.capId + '&year=' + vm.year + '&letter=' + vm.letter + options;
        $http({
            method: 'GET',
            url: requestUrl,
            headers: {
                'Authorization': 'Bearer ' + vm.token,
                    'Accept': vm.selectedFormat
            }
        })
            .then(function (response) {
            vm.resultAvailable = true;
            if (vm.selectedFormat === 'application/json') {
                vm.shortTermForecast = JSON.stringify(response.data, undefined, 2);
            } else {
                vm.shortTermForecast = response.data;
            }
        })
            .
        catch (function (errResponse) {
            vm.resultAvailable = true;
            if (vm.selectedFormat === 'application/json') {
                vm.shortTermForecast = JSON.stringify(errResponse.data, undefined, 2);
            } else {
                vm.shortTermForecast = errResponse.data;
            }
        });
    }

...