Simon Hunt | e672044 | 2015-01-15 12:21:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Remote Communications Module -- REST Service |
Simon Hunt | e672044 | 2015-01-15 12:21:06 -0800 | [diff] [blame] | 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
| 23 | var $log; |
| 24 | |
| 25 | angular.module('onosRemote') |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 26 | .factory('RestService', |
| 27 | ['$log', '$http', 'UrlFnService', |
| 28 | |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 29 | function (_$log_, $http, ufs) { |
Simon Hunt | e672044 | 2015-01-15 12:21:06 -0800 | [diff] [blame] | 30 | $log = _$log_; |
| 31 | |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 32 | function get(url, callback, errorCb) { |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 33 | var fullUrl = ufs.rsUrl(url); |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 34 | |
| 35 | $http.get(fullUrl).then(function (response) { |
Simon Hunt | e672044 | 2015-01-15 12:21:06 -0800 | [diff] [blame] | 36 | // success |
| 37 | callback(response.data); |
| 38 | }, function (response) { |
| 39 | // error |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 40 | var emsg = 'Failed to retrieve JSON data: ' + fullUrl; |
| 41 | $log.warn(emsg, response.status, response.data); |
| 42 | if (errorCb) { |
| 43 | errorCb(emsg); |
| 44 | } |
Simon Hunt | e672044 | 2015-01-15 12:21:06 -0800 | [diff] [blame] | 45 | }); |
| 46 | } |
| 47 | |
| 48 | return { |
| 49 | get: get |
| 50 | }; |
| 51 | }]); |
Simon Hunt | e672044 | 2015-01-15 12:21:06 -0800 | [diff] [blame] | 52 | }()); |