try_api 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 302569a698388c272c2d099ef549b396ad9a05f8
4
- data.tar.gz: 4c86fce3728fab0c9405587327b614b9a52d2a3a
3
+ metadata.gz: b70f5119e6f6c1ed2758866e2b99d7fa5a3eaf27
4
+ data.tar.gz: 83ac4e4b5956d9c798d454bff2f794ceae5286ad
5
5
  SHA512:
6
- metadata.gz: 722ffabb57aa60a06aae2c6d69d57d2c49126b675d944b3b3e2e62b0c466014c2491919e8c5ff05ccfa5f2a721885a15a3b7df2f83c04cf30081306851c7d5f7
7
- data.tar.gz: 65dd4bf232109fcbebc681c7319593bb2ccbe473fe6fe01cf1495db95921455d87a42d0fda6ee9420aa3ded6d096bb449f58250a94a7cd8eed2a46a6a6d7bc3e
6
+ metadata.gz: '054497944b9ed98dd8ae2988331dd101cf73df63555c407d0cdfd8a7ec0fb2ec016ac5458a518658def7813ea15975efcbd187856c19356ccc0761087ff620f3'
7
+ data.tar.gz: 3b7156f93db5334342172fd6d52b13ac04e707b7d4c14533a24190f786a3d34fa97f4592ded796b836b73bd623ad47c42e9ba5835694b76bb015a50c34915d36
@@ -0,0 +1,298 @@
1
+ //= require try_api/params.directive
2
+ //= require try_api/param.directive
3
+ //= require try_api/paramsarray.directive
4
+ //= require try_api/paramsobject.directive
5
+ //= require try_api/image.directive
6
+ //= require try_api/curl.directive
7
+ //= require try_api/url.directive
8
+ //= require try_api/scrollspy.directive
9
+
10
+ var TryApiApp;
11
+
12
+ $(function() {
13
+ $('pre code').not('.no-binding').each(function(i, block) {
14
+ return block.css("border", "1px solid red");
15
+ });
16
+ $('.try-api-sidebar-menu').slimScroll({
17
+ height: '100%'
18
+ });
19
+ return Ladda.bind('.progress-demo button', {
20
+ callback: function(instance) {
21
+ var interval, progress;
22
+ progress = 0;
23
+ interval = setInterval((function() {
24
+ progress = Math.min(progress + Math.random() * 0.1, 1);
25
+ instance.setProgress(progress);
26
+ if (progress === 1) {
27
+ instance.stop();
28
+ clearInterval(interval);
29
+ }
30
+ }), 200);
31
+ }
32
+ });
33
+ });
34
+
35
+ TryApiApp = angular.module('TryApiApp', ['ngAnimate', 'ngCookies', 'TryApi', 'angular-ladda', 'hljs', 'tryApiScrollSpy.directives']);
36
+
37
+ TryApiApp.config([
38
+ '$httpProvider', 'hljsServiceProvider', function($httpProvider, hljsServiceProvider) {
39
+ return hljsServiceProvider.setOptions({
40
+ tabReplace: ' '
41
+ });
42
+ }
43
+ ]);
44
+
45
+ TryApiApp.run(['$http', '$rootScope', function($http, $rootScope) {}]);
46
+
47
+ TryApiApp.controller('HomeController', [
48
+ '$scope', '$timeout', '$sce', '$http', '$cookies', function($scope, $timeout, $sce, $http, $cookies) {
49
+ $scope.getHtml = function(html) {
50
+ return $sce.trustAsHtml(html);
51
+ };
52
+ $scope.getStatusCodeClass = function(code) {
53
+ switch (true) {
54
+ case code >= 200 && code < 300:
55
+ return 'text-success';
56
+ case code >= 300 && code < 400:
57
+ return 'text-warning';
58
+ case code >= 400 && code < 500:
59
+ return 'text-danger';
60
+ case code >= 500:
61
+ return 'text-danger';
62
+ default:
63
+ return 'text-info';
64
+ }
65
+ };
66
+ $scope.headers = [];
67
+ $scope.global_headers = {};
68
+ $scope.params = [];
69
+ $scope.methodSubmit = function(method) {
70
+ var fd, headers, path, url;
71
+ method.pending = true;
72
+ headers = {
73
+ 'Content-Type': void 0
74
+ };
75
+ method.headers.forEach(function(i) {
76
+ var header;
77
+ header = this;
78
+ return headers[header.name] = header.value;
79
+ });
80
+ path = $scope.project.host;
81
+ if ($scope.project.port) {
82
+ path += ':' + $scope.project.port;
83
+ }
84
+ path += '/' + method.submit_path;
85
+ fd = new FormData;
86
+ switch (method.method.toLowerCase()) {
87
+ case 'post':
88
+ case 'delete':
89
+ case 'put':
90
+ $.each(method.parameters, function(i) {
91
+ return $scope.addParameterToForm(fd, this);
92
+ });
93
+ if (fd.keys().next().done) {
94
+ fd = {};
95
+ }
96
+ break;
97
+ case 'get':
98
+ url = '';
99
+ $.each(method.parameters, function(i) {
100
+ return url = $scope.addParameterToUrl(url, this);
101
+ });
102
+ path += '?' + url;
103
+ }
104
+ return $http({
105
+ url: path,
106
+ data: fd,
107
+ transformRequest: angular.identity,
108
+ headers: headers,
109
+ method: method.method.toLowerCase()
110
+ }).success(method.response_handler).error(method.response_handler);
111
+ };
112
+ $http.get('<%= TryApi::Engine.routes.url_helpers.projects_path %>').success(function(data) {
113
+ $scope.project = data.project;
114
+ return $.each($scope.project.menu_items, function() {
115
+ var menu_item;
116
+ menu_item = this;
117
+ return menu_item.methods.forEach(function() {
118
+ var method;
119
+ method = this;
120
+ method.pending = false;
121
+ method.endpoint = $scope.project.endpoint;
122
+ method.response_handler = function(data, status, headers, config) {
123
+ var e;
124
+ method.pending = false;
125
+ try {
126
+ data = JSON.stringify(data, null, 2);
127
+ } catch (_error) {
128
+ e = _error;
129
+ }
130
+ return method.response = {
131
+ data: data,
132
+ headers: JSON.stringify(config.headers, null, 2),
133
+ status: status
134
+ };
135
+ };
136
+ switch (method.method.toLowerCase()) {
137
+ case 'web_socket':
138
+ method.submit = function() {
139
+ $.each(method.cookies, function(i) {
140
+ return $cookies.put(this.name, this.value);
141
+ });
142
+ method.pending = true;
143
+ method.connected = false;
144
+ method.response = {
145
+ data: []
146
+ };
147
+ if ('WebSocket' in window) {
148
+ method.ws = new WebSocket('ws://' + $scope.project.endpoint + '/' + method.submit_path);
149
+ method.ws.onopen = function() {
150
+ return $scope.$apply(function() {
151
+ method.pending = false;
152
+ method.response.data.push('Connected');
153
+ method.ws.send(JSON.stringify({
154
+ command: "subscribe",
155
+ identifier: JSON.stringify(method.identifier)
156
+ }));
157
+ method.response.data.push('Subscribed to ' + JSON.stringify(method.identifier));
158
+ return method.connected = true;
159
+ });
160
+ };
161
+ method.ws.onmessage = function(evt) {
162
+ return $scope.$apply(function() {
163
+ if (JSON.parse(evt.data).type !== 'ping') {
164
+ return method.response.data.push(evt.data);
165
+ }
166
+ });
167
+ };
168
+ return method.ws.onclose = function() {
169
+ return $scope.$apply(function() {
170
+ method.pending = false;
171
+ method.connected = false;
172
+ return method.response.data.push('Disconnected');
173
+ });
174
+ };
175
+ } else {
176
+ return method.response.data.push('WebSocket NOT supported by your Browser!');
177
+ }
178
+ };
179
+ return method.speak = function() {
180
+ method.ws.send(JSON.stringify({
181
+ command: "message",
182
+ data: JSON.stringify({
183
+ message: method.message,
184
+ action: 'speak'
185
+ }),
186
+ identifier: JSON.stringify(method.identifier)
187
+ }));
188
+ return method.message = '';
189
+ };
190
+ default:
191
+ return method.submit = function() {
192
+ return $scope.methodSubmit(method);
193
+ };
194
+ }
195
+ });
196
+ });
197
+ }).error(function(data, status, headers, config) {
198
+ if (status = 422) {
199
+ return alert(data.error);
200
+ }
201
+ });
202
+ $scope.pathBuild = function(path, next) {
203
+ if (next == null) {
204
+ next = '';
205
+ }
206
+ if (next) {
207
+ next = '[' + next + ']';
208
+ }
209
+ if (path) {
210
+ path += next;
211
+ } else {
212
+ path = next;
213
+ }
214
+ return path;
215
+ };
216
+ $scope.addSampleParameterToForm = function(form, parameter, path) {
217
+ if (path == null) {
218
+ path = '';
219
+ }
220
+ path = $scope.pathBuild(path, parameter.name);
221
+ switch (parameter.type) {
222
+ case 'boolean':
223
+ return form.append(path, parameter.value || false);
224
+ default:
225
+ if (parameter.value) {
226
+ return form.append(path, parameter.value || '');
227
+ }
228
+ }
229
+ };
230
+ $scope.addArrayToForm = function(form, parameter, path) {
231
+ if (path == null) {
232
+ path = '';
233
+ }
234
+ path = ($scope.pathBuild(path, parameter.name)) + '[]';
235
+ return $.each(parameter.values, function() {
236
+ return $.each(this, function() {
237
+ return $scope.addParameterToForm(form, this, path);
238
+ });
239
+ });
240
+ };
241
+ $scope.addParameterToForm = function(form, parameter, path) {
242
+ if (path == null) {
243
+ path = '';
244
+ }
245
+ if (parameter.type === 'array') {
246
+ $scope.addArrayToForm(form, parameter, path);
247
+ }
248
+ if (parameter.type === 'object') {
249
+ path = $scope.pathBuild(path, parameter.name);
250
+ return $.each(parameter.values, function() {
251
+ return $scope.addParameterToForm(form, this, path);
252
+ });
253
+ } else {
254
+ return $scope.addSampleParameterToForm(form, parameter, path);
255
+ }
256
+ };
257
+ $scope.addSampleParameterToUrl = function(url, parameter, path) {
258
+ if (path == null) {
259
+ path = '';
260
+ }
261
+ path = ($scope.pathBuild(path, parameter.name)) + '=';
262
+ switch (parameter.type) {
263
+ case 'boolean':
264
+ url += path + (parameter.value || false) + '&';
265
+ break;
266
+ default:
267
+ if (parameter.value) {
268
+ url += path + parameter.value + '&';
269
+ }
270
+ }
271
+ return url;
272
+ };
273
+ return $scope.addParameterToUrl = function(url, parameter, path) {
274
+ if (path == null) {
275
+ path = '';
276
+ }
277
+ switch (parameter.type) {
278
+ case 'array':
279
+ path = ($scope.pathBuild(path, parameter.name)) + '[]';
280
+ $.each(parameter.values, function() {
281
+ return $.each(this, function() {
282
+ return url = $scope.addParameterToUrl(url, this, path);
283
+ });
284
+ });
285
+ break;
286
+ case 'object':
287
+ path = $scope.pathBuild(path, parameter.name);
288
+ $.each(parameter.values, function() {
289
+ return url = $scope.addParameterToUrl(url, this, path);
290
+ });
291
+ break;
292
+ default:
293
+ url = $scope.addSampleParameterToUrl(url, parameter, path);
294
+ }
295
+ return url;
296
+ };
297
+ }
298
+ ]);
@@ -9,9 +9,9 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
9
9
  scope.$watch(function(){
10
10
  return JSON.stringify(scope.model);
11
11
  }, function(){
12
- let method = scope.model.method.toString().toUpperCase();
13
- let headers = [];
14
- let formData = scope.isFormData(scope.model.parameters);
12
+ var method = scope.model.method.toString().toUpperCase();
13
+ var headers = [];
14
+ var formData = scope.isFormData(scope.model.parameters);
15
15
 
16
16
  if(formData) {
17
17
 
@@ -25,8 +25,8 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
25
25
  })
26
26
  }
27
27
 
28
- let params = '';
29
- let urlParams = '';
28
+ var params = '';
29
+ var urlParams = '';
30
30
 
31
31
  if(scope.model.parameters && scope.model.parameters.length > 0) {
32
32
  if (scope.model.method == 'get') {
@@ -49,7 +49,7 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
49
49
  if(parameters && parameters.length > 0){
50
50
  parameters.forEach(function(parameter){
51
51
 
52
- let name = '';
52
+ var name = '';
53
53
 
54
54
  if(prefix) {
55
55
  name = prefix + '[' + parameter.name + ']';
@@ -59,10 +59,10 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
59
59
 
60
60
  if(parameter.type == 'array'){
61
61
  if(parameter.values && parameter.values.length > 0){
62
- let i = 0;
62
+ var i = 0;
63
63
  parameter.values.forEach(function(value){
64
- let temp_parameters = [];
65
- for(let k in value){
64
+ var temp_parameters = [];
65
+ for(var k in value){
66
66
  temp_parameters.push(value[k]);
67
67
  }
68
68
  scope.toUrlParameters(temp_parameters, name + '[]', result);
@@ -70,7 +70,7 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
70
70
  })
71
71
  }
72
72
  }else{
73
- let value = '';
73
+ var value = '';
74
74
 
75
75
  if(parameter.type == 'image'){
76
76
 
@@ -85,12 +85,12 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
85
85
  }
86
86
 
87
87
  scope.toFormDataKeys = function(parameters, prefix){
88
- let result = '';
88
+ var result = '';
89
89
 
90
90
  if(parameters && parameters.length > 0){
91
91
  parameters.forEach(function(parameter){
92
92
 
93
- let name = '';
93
+ var name = '';
94
94
 
95
95
  if(prefix) {
96
96
  name = prefix + '[' + parameter.name + ']';
@@ -100,10 +100,10 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
100
100
 
101
101
  if(parameter.type == 'array'){
102
102
  if(parameter.values && parameter.values.length > 0){
103
- let i = 0;
103
+ var i = 0;
104
104
  parameter.values.forEach(function(value){
105
- let temp_parameters = [];
106
- for(let k in value){
105
+ var temp_parameters = [];
106
+ for(var k in value){
107
107
  temp_parameters.push(value[k]);
108
108
  }
109
109
  result += scope.toFormDataKeys(temp_parameters, name + '[]');
@@ -111,7 +111,7 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
111
111
  })
112
112
  }
113
113
  }else{
114
- let value = '';
114
+ var value = '';
115
115
 
116
116
  if(parameter.type == 'image'){
117
117
  value = parameter.value ? '@' + parameter.value.name : '';
@@ -127,7 +127,7 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
127
127
  }
128
128
 
129
129
  scope.toJsonParameters = function(parameters){
130
- let result = {};
130
+ var result = {};
131
131
 
132
132
  if(parameters && parameters.length > 0){
133
133
  parameters.forEach(function(parameter){
@@ -135,8 +135,8 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
135
135
  if(parameter.values && parameter.values.length > 0){
136
136
  result[parameter.name] = [];
137
137
  parameter.values.forEach(function(value){
138
- let temp_parameters = [];
139
- for(let k in value){
138
+ var temp_parameters = [];
139
+ for(var k in value){
140
140
  temp_parameters.push(value[k]);
141
141
  }
142
142
  result[parameter.name].push(scope.toJsonParameters(temp_parameters));
@@ -151,15 +151,15 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
151
151
  }
152
152
 
153
153
  scope.isFormData = function(parameters){
154
- let result = false;
154
+ var result = false;
155
155
 
156
156
  if(parameters && parameters.length > 0){
157
157
  parameters.forEach(function(parameter){
158
158
  if(parameter.type == 'array'){
159
159
  if(parameter.values && parameter.values.length > 0){
160
160
  parameter.values.forEach(function(value){
161
- let temp_parameters = [];
162
- for(let k in value){
161
+ var temp_parameters = [];
162
+ for(var k in value){
163
163
  temp_parameters.push(value[k]);
164
164
  }
165
165
  result = scope.toJsonParameters(temp_parameters);
@@ -1,20 +1,19 @@
1
- angular.module('TryApi').directive 'param', [
2
- '$filter',
3
- '$sce'
4
- ($filter, $sce) ->
5
-
6
- link = (scope, element, attrs, ctrl) ->
7
- scope.unique_id = Math.random()
8
-
9
- scope.getHtml = (html) ->
10
- return $sce.trustAsHtml(html)
11
-
1
+ angular.module('TryApi').directive('param', [
2
+ '$filter', '$sce', function($filter, $sce) {
3
+ var link;
4
+ link = function(scope, element, attrs, ctrl) {
5
+ scope.unique_id = Math.random();
6
+ return scope.getHtml = function(html) {
7
+ return $sce.trustAsHtml(html);
8
+ };
9
+ };
12
10
  return {
13
- link: link
14
- restrict: 'A'
15
- require: 'ngModel'
16
- scope:
11
+ link: link,
12
+ restrict: 'A',
13
+ require: 'ngModel',
14
+ scope: {
17
15
  parameter: '=ngModel'
16
+ },
18
17
  template: '' +
19
18
  '<div class="col-md-4 text-right" ng-if=\'parameter.type != "array" && parameter.type != "object"\'>' +
20
19
  ' <b>{{ parameter.name }}</b>' +
@@ -60,5 +59,6 @@ angular.module('TryApi').directive 'param', [
60
59
  ' </div>' +
61
60
  ' <div paramsobject ng-model="parameter"></div>' +
62
61
  '</div>'
63
- }
64
- ]
62
+ };
63
+ }
64
+ ]);
@@ -0,0 +1,23 @@
1
+ angular.module('TryApi', []);
2
+
3
+ angular.module('TryApi').directive('params', [
4
+ function() {
5
+ var link;
6
+ link = function(scope, element, attrs, ctrl) {
7
+
8
+ };
9
+
10
+ return {
11
+ link: link,
12
+ restrict: 'A',
13
+ require: 'ngModel',
14
+ scope: {
15
+ parameters: '=ngModel'
16
+ },
17
+ template: '' +
18
+ '<div class="row parameter" ng-repeat="parameter in parameters">' +
19
+ ' <div param ng-model="parameter">' +
20
+ '</div>'
21
+ };
22
+ }
23
+ ]);
@@ -0,0 +1,30 @@
1
+ angular.module('TryApi').directive('paramsarray', [
2
+ '$filter', function($filter) {
3
+ var link;
4
+ link = function(scope, element, attrs, ctrl) {
5
+ scope.parameter.values = [];
6
+ scope.addItem = function() {
7
+ return scope.parameter.values.push(jQuery.extend(true, {}, scope.parameter.parameters));
8
+ };
9
+ return scope.deleteItem = function(index) {
10
+ return scope.parameter.values.splice(index, 1);
11
+ };
12
+ };
13
+ return {
14
+ link: link,
15
+ restrict: 'A',
16
+ require: 'ngModel',
17
+ scope: {
18
+ parameter: '=ngModel'
19
+ },
20
+ template: '' +
21
+ '<div class="try-api-array-item" ng-repeat="value in parameter.values track by $index">' +
22
+ ' <div params ng-model="value"></div>' +
23
+ ' <div class="try-api-array-item-close" ng-click="deleteItem($index)"><i class="fa fa-close"></i></div>' +
24
+ '</div>' +
25
+ '<div class="try-api-array-item try-api-array-item-add" ng-click="addItem()">' +
26
+ ' <a>Add</a>' +
27
+ '</div>'
28
+ };
29
+ }
30
+ ]);
@@ -0,0 +1,62 @@
1
+ angular.module('TryApi').directive('paramsobject', [
2
+ '$filter', function($filter) {
3
+ var link;
4
+ link = function(scope, element, attrs, ctrl) {
5
+ scope.parameter.values = jQuery.extend(true, {}, scope.parameter.parameters);
6
+ if (scope.parameter.custom) {
7
+ scope["new"] = {};
8
+ scope.checkDuplicate = function() {
9
+ var duplicate, parameters;
10
+ duplicate = false;
11
+ parameters = scope.parameter.parameters;
12
+ $.each(parameters, function() {
13
+ if (this.name === scope["new"].name) {
14
+ duplicate = true;
15
+ return false;
16
+ }
17
+ });
18
+ return duplicate;
19
+ };
20
+ return scope.addItem = function() {
21
+ var last;
22
+ if (scope["new"].name && scope["new"].type && !scope.checkDuplicate()) {
23
+ last = {
24
+ name: scope["new"].name,
25
+ type: scope["new"].type
26
+ };
27
+ if (last.type === 'object') {
28
+ last.custom = true;
29
+ last.parameters = [];
30
+ }
31
+ scope.parameter.parameters.push(last);
32
+ return scope.parameter.values[scope.parameter.parameters.length - 1] = last;
33
+ }
34
+ };
35
+ }
36
+ };
37
+ return {
38
+ link: link,
39
+ restrict: 'A',
40
+ require: 'ngModel',
41
+ scope: {
42
+ parameter: '=ngModel'
43
+ },
44
+ template: '' +
45
+ '<div style="border: 1px solid lightgray; margin: 1px 1px 1px 10px; padding: 0 10px 10px">' +
46
+ ' <div params ng-model="parameter.values"></div>' +
47
+ '</div>' +
48
+ '<div class="col-md-12" style="margin-top: 10px" ng-if="parameter.custom == true">' +
49
+ ' <div class="col-md-6">' +
50
+ ' <input type="text" ng-model="new.name" placeholder="field name">' +
51
+ ' </div>' +
52
+ ' <div class="col-md-6">' +
53
+ ' <input type="text" ng-model="new.type" placeholder="field type">' +
54
+ ' </div>' +
55
+ '</div>' +
56
+ '<div class="try-api-array-item try-api-array-item-add" style="margin-top: 50px" ng-click="addItem()" ng-if="parameter.custom == true">' +
57
+ ' <a>Add</a>' +
58
+ '</div>'
59
+
60
+ };
61
+ }
62
+ ]);
@@ -0,0 +1,54 @@
1
+ angular.module('TryApi').directive('url', [
2
+ '$filter', '$sce', function($filter, $sce) {
3
+ var link;
4
+ link = function(scope, element, attrs, ctrl) {
5
+ scope.isParameter = function(value) {
6
+ if (value) {
7
+ return value.indexOf(':') !== -1;
8
+ } else {
9
+ return false;
10
+ }
11
+ };
12
+ scope.parts = scope.pattern.split('/').filter(Boolean).map(function(i) {
13
+ var value;
14
+ value = scope.isParameter(i) ? '' : i;
15
+ return {
16
+ value: value,
17
+ placeholder: i
18
+ };
19
+ });
20
+ scope.$watch('parts', function() {
21
+ return scope.url = scope.parts.map(function(i) {
22
+ if (i.value === '') {
23
+ return '0';
24
+ } else {
25
+ return i.value;
26
+ }
27
+ }).join('/');
28
+ }, true);
29
+ return scope.inputStyle = function(part) {
30
+ var charWidth;
31
+ charWidth = 11.5;
32
+ return {
33
+ "width": (part.value.length + 1) * charWidth + "px",
34
+ "min-width": part.placeholder.length * charWidth + "px"
35
+ };
36
+ };
37
+ };
38
+ return {
39
+ link: link,
40
+ restrict: 'A',
41
+ require: 'ngModel',
42
+ scope: {
43
+ url: '=ngModel',
44
+ pattern: '=pattern'
45
+ },
46
+ template: '' +
47
+ '<span ng-repeat="part in parts track by $index">' +
48
+ '/' +
49
+ '<span ng-if="!isParameter(part.placeholder)">{{ part.value }}</span>' +
50
+ '<input ng-if="isParameter(part.placeholder)" ng-model="part.value" class="url-input" ng-style="inputStyle(part)" placeholder="{{ part.placeholder }}" scope="max-width: 90%; font-family:monospace;"/>' +
51
+ '</span>'
52
+ };
53
+ }
54
+ ]);
@@ -1,3 +1,3 @@
1
1
  module TryApi
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: try_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Skubenych
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,15 +34,15 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - MIT-LICENSE
36
36
  - Rakefile
37
- - app/assets/javascripts/try_api/application.js.coffee.erb
37
+ - app/assets/javascripts/try_api/application.js.erb
38
38
  - app/assets/javascripts/try_api/curl.directive.js
39
39
  - app/assets/javascripts/try_api/image.directive.js
40
- - app/assets/javascripts/try_api/param.directive.js.coffee
41
- - app/assets/javascripts/try_api/params.directive.js.coffee
42
- - app/assets/javascripts/try_api/paramsarray.directive.js.coffee
43
- - app/assets/javascripts/try_api/paramsobject.directive.js.coffee
40
+ - app/assets/javascripts/try_api/param.directive.js
41
+ - app/assets/javascripts/try_api/params.directive.js
42
+ - app/assets/javascripts/try_api/paramsarray.directive.js
43
+ - app/assets/javascripts/try_api/paramsobject.directive.js
44
44
  - app/assets/javascripts/try_api/scrollspy.directive.js
45
- - app/assets/javascripts/try_api/url.directive.js.coffee
45
+ - app/assets/javascripts/try_api/url.directive.js
46
46
  - app/assets/stylesheets/try_api/application.css.sass
47
47
  - app/controllers/try_api/application_controller.rb
48
48
  - app/controllers/try_api/pages_controller.rb
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.4.8
92
+ rubygems_version: 2.5.2
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Generates API UI from simple .yml manifest.
@@ -1,248 +0,0 @@
1
- #= require try_api/params.directive
2
- #= require try_api/param.directive
3
- #= require try_api/paramsarray.directive
4
- #= require try_api/paramsobject.directive
5
- #= require try_api/image.directive
6
- #= require try_api/curl.directive
7
- #= require try_api/url.directive
8
- #= require try_api/scrollspy.directive
9
-
10
- $ ->
11
- $('pre code').each (i, block) ->
12
- hljs.highlightBlock(block)
13
-
14
-
15
- $('.try-api-sidebar-menu').slimScroll
16
- height: '100%'
17
-
18
- Ladda.bind '.progress-demo button', callback: (instance) ->
19
- progress = 0
20
- interval = setInterval((->
21
- progress = Math.min(progress + Math.random() * 0.1, 1)
22
- instance.setProgress progress
23
- if progress == 1
24
- instance.stop()
25
- clearInterval interval
26
- return
27
- ), 200)
28
- return
29
-
30
-
31
- TryApiApp = angular.module('TryApiApp', [
32
- 'ngAnimate'
33
- 'ngCookies'
34
- 'TryApi'
35
- 'angular-ladda'
36
- 'hljs'
37
- 'tryApiScrollSpy.directives'
38
- ])
39
- TryApiApp.config [
40
- '$httpProvider'
41
- 'hljsServiceProvider'
42
- ($httpProvider, hljsServiceProvider) ->
43
- hljsServiceProvider.setOptions
44
- tabReplace: ' '
45
- ]
46
- TryApiApp.run [
47
- '$http'
48
- '$rootScope'
49
- ($http, $rootScope) ->
50
- ]
51
-
52
- TryApiApp.controller 'HomeController', [
53
- '$scope'
54
- '$timeout'
55
- '$sce'
56
- '$http',
57
- '$cookies'
58
- ($scope, $timeout, $sce, $http, $cookies) ->
59
-
60
-
61
- $scope.getHtml = (html) ->
62
- return $sce.trustAsHtml(html)
63
-
64
- $scope.getStatusCodeClass = (code) ->
65
- switch true
66
- when code >= 200 && code < 300
67
- return 'text-success'
68
- when code >= 300 && code < 400
69
- return 'text-warning'
70
- when code >= 400 && code < 500
71
- return 'text-danger'
72
- when code >= 500
73
- return 'text-danger'
74
- else
75
- return 'text-info'
76
-
77
- $scope.headers = []
78
- $scope.global_headers = {}
79
- $scope.params = []
80
-
81
- $scope.methodSubmit = (method) ->
82
- method.pending = true
83
- headers = {'Content-Type': undefined}
84
-
85
- $.each method.headers, (i)->
86
- header = this
87
- headers[header.name] = header.value
88
-
89
- path = $scope.project.host
90
- if $scope.project.port
91
- path += ':' + $scope.project.port
92
-
93
- path += '/' + method.submit_path
94
-
95
- fd = new FormData
96
-
97
- switch method.method.toLowerCase()
98
- when 'post', 'delete', 'put'
99
-
100
- $.each method.parameters, (i) ->
101
- $scope.addParameterToForm fd, this
102
-
103
- if fd.keys().next().done
104
- fd = {}
105
-
106
- when 'get'
107
- url = ''
108
- $.each method.parameters, (i) ->
109
- url = $scope.addParameterToUrl(url, this)
110
- path += '?' + url
111
-
112
- $http({
113
- url: path,
114
- data: fd,
115
- transformRequest: angular.identity,
116
- headers: headers,
117
- method: method.method.toLowerCase()
118
- })
119
- .success(method.response_handler)
120
- .error(method.response_handler)
121
-
122
- $http.get('<%= TryApi::Engine.routes.url_helpers.projects_path %>').success (data) ->
123
- $scope.project = data.project
124
- $.each $scope.project.menu_items, () ->
125
- menu_item = this
126
- $.each menu_item.methods, ()->
127
- method = this
128
- method.pending = false
129
- method.endpoint = $scope.project.endpoint;
130
- method.response_handler = (data, status, headers, config) ->
131
- method.pending = false
132
- try # TODO catch different types of response
133
- data = JSON.stringify(data, null, 2)
134
- catch e
135
-
136
- method.response =
137
- data: data
138
- headers: JSON.stringify(config.headers, null, 2)
139
- status: status
140
-
141
- switch method.method.toLowerCase()
142
- when 'web_socket'
143
- method.submit = ->
144
- $.each method.cookies, (i) ->
145
- $cookies.put(this.name, this.value)
146
-
147
- method.pending = true
148
- method.connected = false
149
- method.response = {data: []}
150
-
151
- if 'WebSocket' of window
152
- method.ws = new WebSocket('ws://' + $scope.project.endpoint + '/' + method.submit_path)
153
-
154
- method.ws.onopen = ->
155
- $scope.$apply ->
156
- method.pending = false
157
- method.response.data.push('Connected')
158
- method.ws.send(JSON.stringify({command: "subscribe", identifier: JSON.stringify(method.identifier)}))
159
- method.response.data.push('Subscribed to ' + JSON.stringify(method.identifier))
160
- method.connected = true
161
-
162
- method.ws.onmessage = (evt) ->
163
- $scope.$apply ->
164
- if(JSON.parse(evt.data).type != 'ping')
165
- method.response.data.push(evt.data)
166
-
167
- method.ws.onclose = ->
168
- $scope.$apply ->
169
- method.pending = false
170
- method.connected = false
171
- method.response.data.push('Disconnected')
172
-
173
- else
174
- method.response.data.push('WebSocket NOT supported by your Browser!')
175
-
176
- method.speak = ->
177
- method.ws.send JSON.stringify({
178
- command: "message",
179
- data: JSON.stringify({ message: method.message, action: 'speak'})
180
- identifier: JSON.stringify(method.identifier)
181
- })
182
- method.message = ''
183
- else
184
- method.submit = ->
185
- $scope.methodSubmit(method)
186
- .error (data, status, headers, config) ->
187
- if status = 422
188
- alert data.error
189
-
190
- $scope.pathBuild = (path, next = '') ->
191
- if next
192
- next = '[' + next + ']'
193
- if path
194
- path += next
195
- else
196
- path = next
197
- return path
198
-
199
- $scope.addSampleParameterToForm = (form, parameter, path = '') ->
200
- path = $scope.pathBuild path, parameter.name
201
- switch parameter.type
202
- when 'boolean'
203
- form.append path, parameter.value || false
204
- else
205
- if parameter.value
206
- form.append path, parameter.value || ''
207
-
208
- $scope.addArrayToForm = (form, parameter, path = '') ->
209
- path = ($scope.pathBuild path, parameter.name) + '[]'
210
- $.each parameter.values, ->
211
- $.each this, ->
212
- $scope.addParameterToForm form, this, path
213
-
214
- $scope.addParameterToForm = (form, parameter, path = '') ->
215
- if parameter.type == 'array'
216
- $scope.addArrayToForm form, parameter, path
217
- if parameter.type == 'object'
218
- path = $scope.pathBuild path, parameter.name
219
- $.each parameter.values, ->
220
- $scope.addParameterToForm form, this, path
221
- else
222
- $scope.addSampleParameterToForm form, parameter, path
223
-
224
- $scope.addSampleParameterToUrl = (url, parameter, path = '') ->
225
- path = ($scope.pathBuild path, parameter.name) + '='
226
- switch parameter.type
227
- when 'boolean'
228
- url += path + (parameter.value || false) + '&'
229
- else
230
- if parameter.value
231
- url += path + parameter.value + '&'
232
- return url
233
-
234
- $scope.addParameterToUrl = (url, parameter, path = '') ->
235
- switch parameter.type
236
- when 'array'
237
- path = ($scope.pathBuild path, parameter.name) + '[]'
238
- $.each parameter.values, ->
239
- $.each this, ->
240
- url = $scope.addParameterToUrl url, this, path
241
- when 'object'
242
- path = $scope.pathBuild path, parameter.name
243
- $.each parameter.values, ->
244
- url = $scope.addParameterToUrl url, this, path
245
- else
246
- url = $scope.addSampleParameterToUrl url, parameter, path
247
- return url
248
- ]
@@ -1,18 +0,0 @@
1
- angular.module 'TryApi', []
2
- angular.module('TryApi').directive 'params', [
3
- () ->
4
-
5
- link = (scope, element, attrs, ctrl) ->
6
-
7
- return {
8
- link: link
9
- restrict: 'A'
10
- require: 'ngModel'
11
- scope:
12
- parameters: '=ngModel'
13
- template: '' +
14
- '<div class="row parameter" ng-repeat="parameter in parameters">' +
15
- ' <div param ng-model="parameter">' +
16
- '</div>'
17
- }
18
- ]
@@ -1,30 +0,0 @@
1
- angular.module('TryApi').directive 'paramsarray', [
2
- '$filter'
3
- ($filter) ->
4
-
5
- link = (scope, element, attrs, ctrl) ->
6
-
7
- scope.parameter.values = []
8
-
9
- scope.addItem = ()->
10
- scope.parameter.values.push jQuery.extend(true, {}, scope.parameter.parameters)
11
-
12
- scope.deleteItem = (index)->
13
- scope.parameter.values.splice(index, 1)
14
-
15
- return {
16
- link: link
17
- restrict: 'A'
18
- require: 'ngModel'
19
- scope:
20
- parameter: '=ngModel'
21
- template: '' +
22
- '<div class="try-api-array-item" ng-repeat="value in parameter.values track by $index">' +
23
- ' <div params ng-model="value"></div>' +
24
- ' <div class="try-api-array-item-close" ng-click="deleteItem($index)"><i class="fa fa-close"></i></div>' +
25
- '</div>' +
26
- '<div class="try-api-array-item try-api-array-item-add" ng-click="addItem()">' +
27
- ' <a>Add</a>' +
28
- '</div>'
29
- }
30
- ]
@@ -1,53 +0,0 @@
1
- angular.module('TryApi').directive 'paramsobject', [
2
- '$filter'
3
- ($filter) ->
4
-
5
- link = (scope, element, attrs, ctrl) ->
6
-
7
- scope.parameter.values = jQuery.extend(true, {}, scope.parameter.parameters)
8
-
9
- if scope.parameter.custom
10
-
11
- scope.new = {}
12
-
13
- scope.checkDuplicate = () ->
14
- duplicate = false
15
- parameters = scope.parameter.parameters
16
- $.each parameters, ->
17
- if this.name == scope.new.name
18
- duplicate = true
19
- return false
20
- return duplicate
21
-
22
- scope.addItem = () ->
23
- if scope.new.name && scope.new.type && !scope.checkDuplicate()
24
- last = { name: scope.new.name, type: scope.new.type }
25
- if last.type == 'object'
26
- last.custom = true
27
- last.parameters = []
28
- scope.parameter.parameters.push(last)
29
- scope.parameter.values[scope.parameter.parameters.length - 1] = last
30
-
31
- return {
32
- link: link
33
- restrict: 'A'
34
- require: 'ngModel'
35
- scope:
36
- parameter: '=ngModel'
37
- template: '' +
38
- '<div style="border: 1px solid lightgray; margin: 1px 1px 1px 10px; padding: 0 10px 10px">' +
39
- ' <div params ng-model="parameter.values"></div>' +
40
- '</div>' +
41
- '<div class="col-md-12" style="margin-top: 10px" ng-if="parameter.custom == true">' +
42
- ' <div class="col-md-6">' +
43
- ' <input type="text" ng-model="new.name" placeholder="field name">' +
44
- ' </div>' +
45
- ' <div class="col-md-6">' +
46
- ' <input type="text" ng-model="new.type" placeholder="field type">' +
47
- ' </div>' +
48
- '</div>' +
49
- '<div class="try-api-array-item try-api-array-item-add" style="margin-top: 50px" ng-click="addItem()" ng-if="parameter.custom == true">' +
50
- ' <a>Add</a>' +
51
- '</div>'
52
- }
53
- ]
@@ -1,47 +0,0 @@
1
- angular.module('TryApi').directive 'url', [
2
- '$filter',
3
- '$sce'
4
- ($filter, $sce) ->
5
-
6
- link = (scope, element, attrs, ctrl) ->
7
-
8
- scope.isParameter = (value) ->
9
- if value
10
- return value.indexOf(':') != -1
11
- else
12
- return false
13
-
14
- scope.parts = scope.pattern.split('/').filter(Boolean).map (i)->
15
- value = if scope.isParameter(i) then '' else i
16
- {
17
- value: value,
18
- placeholder: i
19
- }
20
-
21
- scope.$watch 'parts', ->
22
- scope.url = scope.parts.map((i)->
23
- if i.value == '' then '0' else i.value
24
- ).join('/')
25
- , true
26
-
27
- scope.inputStyle = (part) ->
28
- charWidth = 11.5;
29
- return {
30
- "width": ((part.value).length + 1) * charWidth + "px",
31
- "min-width": ((part.placeholder).length) * charWidth + "px"
32
- }
33
-
34
- return {
35
- link: link
36
- restrict: 'A'
37
- require: 'ngModel'
38
- scope:
39
- url: '=ngModel'
40
- pattern: '=pattern'
41
- template: '<span ng-repeat="part in parts track by $index">' +
42
- '/' +
43
- '<span ng-if="!isParameter(part.placeholder)">{{ part.value }}</span>' +
44
- '<input ng-if="isParameter(part.placeholder)" ng-model="part.value" class="url-input" ng-style="inputStyle(part)" placeholder="{{ part.placeholder }}" scope="max-width: 90%; font-family:monospace;"/>' +
45
- '</span>'
46
- }
47
- ]