blob: aa451f9da618659be4509e253fc811f35aeec3e6 [file] [log] [blame]
Simon Hunte6720442015-01-15 12:21:06 -08001/*
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 Hunte6720442015-01-15 12:21:06 -080019 */
20(function () {
21 'use strict';
22
23 var $log;
24
25 angular.module('onosRemote')
Simon Huntbc76fb12015-02-26 18:09:54 -080026 .factory('RestService',
27 ['$log', '$http', 'UrlFnService',
28
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080029 function (_$log_, $http, ufs) {
Simon Hunte6720442015-01-15 12:21:06 -080030 $log = _$log_;
31
Simon Huntbc76fb12015-02-26 18:09:54 -080032 function get(url, callback, errorCb) {
Simon Hunt1e4a0012015-01-21 11:36:08 -080033 var fullUrl = ufs.rsUrl(url);
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080034
35 $http.get(fullUrl).then(function (response) {
Simon Hunte6720442015-01-15 12:21:06 -080036 // success
37 callback(response.data);
38 }, function (response) {
39 // error
Simon Huntbc76fb12015-02-26 18:09:54 -080040 var emsg = 'Failed to retrieve JSON data: ' + fullUrl;
41 $log.warn(emsg, response.status, response.data);
42 if (errorCb) {
43 errorCb(emsg);
44 }
Simon Hunte6720442015-01-15 12:21:06 -080045 });
46 }
47
48 return {
49 get: get
50 };
51 }]);
Simon Hunte6720442015-01-15 12:21:06 -080052}());