Matteo Scandolo | 57aee47 | 2018-06-28 15:24:42 -0700 | [diff] [blame] | 1 | |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2017-present Open Networking Foundation |
| 5 | |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | import IPromise = angular.IPromise; |
| 20 | |
| 21 | export interface IXosVersionReaderService { |
| 22 | getVersion(): IPromise<string>; |
| 23 | } |
| 24 | |
| 25 | interface ICORDVersion { |
| 26 | data: { |
| 27 | version: string; |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | export class XosVersionReaderService implements IXosVersionReaderService { |
| 32 | |
| 33 | static $inject = ['$http', '$q', '$log']; |
| 34 | |
| 35 | constructor( |
| 36 | private $http: angular.IHttpService, |
| 37 | private $q: angular.IQService, |
| 38 | private $log: angular.ILogService |
| 39 | ) { |
| 40 | } |
| 41 | |
| 42 | public getVersion(): IPromise<string> { |
| 43 | const d = this.$q.defer(); |
| 44 | this.$http.get(`/version.json`) |
| 45 | .then((res: ICORDVersion) => { |
| 46 | d.resolve(res.data.version); |
| 47 | }) |
| 48 | .catch(e => { |
| 49 | this.$log.warn(`[XosVersionReaderService] Cannot read version`, e); |
| 50 | d.resolve('unknown'); |
| 51 | }); |
| 52 | return d.promise; |
| 53 | } |
| 54 | |
| 55 | } |