try_api 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/try_api/application.js.coffee.erb +71 -82
- data/app/assets/javascripts/try_api/curl.directive.js +51 -4
- data/app/assets/javascripts/try_api/param.directive.js.coffee +1 -1
- data/app/assets/javascripts/try_api/paramsobject.directive.js.coffee +34 -1
- data/app/models/try_api/parameter.rb +1 -0
- data/lib/generators/try_api/templates/try_api/base.yml +48 -4
- data/lib/try_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9534478c173d1e484e488f3b934c964c7b23c4d6
|
4
|
+
data.tar.gz: 88e19a1d971b76301655d98ca866e4e4a652ff56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7388beb701f29e2285805c9b4c27e7cd32e2f939aa07402e66a06310ebbe0caceb228538c37405e06f7346dc044c483fdc703644d4b299a08c09b35de8a4310f
|
7
|
+
data.tar.gz: 58fd00c734499d5b93ca6bc80bd14f77941a219776ef112095174d2456fc92be158523a0d043ef011f803efa471e3c809b18a3d0dc45a7d754de4d27269584c9
|
@@ -86,55 +86,35 @@ TryApiApp.controller 'HomeController', [
|
|
86
86
|
header = this
|
87
87
|
headers[header.name] = header.value
|
88
88
|
|
89
|
-
path =
|
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
|
90
96
|
|
91
97
|
switch method.method.toLowerCase()
|
92
|
-
when 'post'
|
93
|
-
fd = new FormData
|
98
|
+
when 'post', 'delete', 'put'
|
94
99
|
fd.append 'a', 'a' # TODO sending empty array causes EOFError
|
95
100
|
|
96
101
|
$.each method.parameters, (i) ->
|
97
102
|
$scope.addParameterToForm fd, this
|
98
|
-
|
99
|
-
$http.post path, fd,
|
100
|
-
transformRequest: angular.identity
|
101
|
-
headers: headers
|
102
|
-
.success method.response_handler
|
103
|
-
.error method.response_handler
|
104
|
-
when 'delete'
|
105
|
-
url = ''
|
106
|
-
|
107
|
-
$.each method.parameters, (i) ->
|
108
|
-
url = $scope.addParameterToUrl(url, this)
|
109
|
-
|
110
|
-
$http.delete path + '?' + url,
|
111
|
-
transformRequest: angular.identity
|
112
|
-
headers: headers
|
113
|
-
.success method.response_handler
|
114
|
-
.error method.response_handler
|
115
103
|
when 'get'
|
116
104
|
url = ''
|
117
|
-
|
118
105
|
$.each method.parameters, (i) ->
|
119
106
|
url = $scope.addParameterToUrl(url, this)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
$scope.addParameterToForm fd, this
|
132
|
-
|
133
|
-
$http.put path, fd,
|
134
|
-
transformRequest: angular.identity
|
135
|
-
headers: headers
|
136
|
-
.success method.response_handler
|
137
|
-
.error method.response_handler
|
107
|
+
path += '?' + url
|
108
|
+
|
109
|
+
$http({
|
110
|
+
url: path,
|
111
|
+
data: fd,
|
112
|
+
transformRequest: angular.identity,
|
113
|
+
headers: headers,
|
114
|
+
method: method.method.toLowerCase()
|
115
|
+
})
|
116
|
+
.success(method.response_handler)
|
117
|
+
.error(method.response_handler)
|
138
118
|
|
139
119
|
$http.get('<%= TryApi::Engine.routes.url_helpers.projects_path %>').success (data) ->
|
140
120
|
$scope.project = data.project
|
@@ -204,52 +184,61 @@ TryApiApp.controller 'HomeController', [
|
|
204
184
|
if status = 422
|
205
185
|
alert data.error
|
206
186
|
|
207
|
-
$scope.
|
208
|
-
if
|
209
|
-
|
210
|
-
$.each parameter.values, ->
|
211
|
-
value = this
|
212
|
-
$.each value, ->
|
213
|
-
subparameter = this
|
214
|
-
switch subparameter.type
|
215
|
-
when 'boolean'
|
216
|
-
form.append parameter.name + '[]' + subparameter.name, subparameter.value || false
|
217
|
-
else
|
218
|
-
form.append parameter.name + '[]' + subparameter.name, subparameter.value || ''
|
219
|
-
if parameter.type == 'object'
|
220
|
-
$.each parameter.values, ->
|
221
|
-
subparameter = this
|
222
|
-
switch subparameter.type
|
223
|
-
when 'boolean'
|
224
|
-
form.append parameter.name + '[' + subparameter.name + ']', subparameter.value || false
|
225
|
-
else
|
226
|
-
form.append parameter.name + '[' + subparameter.name + ']', subparameter.value || ''
|
187
|
+
$scope.pathBuild = (path, next) ->
|
188
|
+
if path
|
189
|
+
path += '[' + next + ']'
|
227
190
|
else
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
191
|
+
path = next
|
192
|
+
return path
|
193
|
+
|
194
|
+
$scope.addSampleParameterToForm = (form, parameter, path = '') ->
|
195
|
+
path = $scope.pathBuild path, parameter.name
|
196
|
+
switch parameter.type
|
197
|
+
when 'boolean'
|
198
|
+
form.append path, parameter.value || false
|
199
|
+
else
|
200
|
+
if parameter.value
|
201
|
+
form.append path, parameter.value || ''
|
202
|
+
|
203
|
+
$scope.addArrayToForm = (form, parameter, path = '') ->
|
204
|
+
form.append 'a', 'a' # TODO sending empty array causes EOFError
|
205
|
+
path = ($scope.pathBuild path, parameter.name) + '[]'
|
206
|
+
$.each parameter.values, ->
|
207
|
+
$.each this, ->
|
208
|
+
$scope.addParameterToForm form, this, path
|
209
|
+
|
210
|
+
$scope.addParameterToForm = (form, parameter, path = '') ->
|
236
211
|
if parameter.type == 'array'
|
212
|
+
$scope.addArrayToForm form, parameter, path
|
213
|
+
if parameter.type == 'object'
|
214
|
+
path = $scope.pathBuild path, parameter.name
|
237
215
|
$.each parameter.values, ->
|
238
|
-
|
239
|
-
$.each value, ->
|
240
|
-
subparameter = this
|
241
|
-
switch subparameter.type
|
242
|
-
when 'boolean'
|
243
|
-
url = url + parameter.name + '[]' + (subparameter.name || '') + '=' + (subparameter.value || false) + '&'
|
244
|
-
else
|
245
|
-
if subparameter.value
|
246
|
-
url = url + parameter.name + '[]' + (subparameter.name || '') + '=' + subparameter.value + '&'
|
216
|
+
$scope.addParameterToForm form, this, path
|
247
217
|
else
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
218
|
+
$scope.addSampleParameterToForm form, parameter, path
|
219
|
+
|
220
|
+
$scope.addSampleParameterToUrl = (url, parameter, path = '') ->
|
221
|
+
path = ($scope.pathBuild path, parameter.name) + '='
|
222
|
+
switch parameter.type
|
223
|
+
when 'boolean'
|
224
|
+
url += path + (parameter.value || false) + '&'
|
225
|
+
else
|
226
|
+
if parameter.value
|
227
|
+
url += path + parameter.value + '&'
|
228
|
+
return url
|
229
|
+
|
230
|
+
$scope.addParameterToUrl = (url, parameter, path = '') ->
|
231
|
+
switch parameter.type
|
232
|
+
when 'array'
|
233
|
+
path = ($scope.pathBuild path, parameter.name) + '[]'
|
234
|
+
$.each parameter.values, ->
|
235
|
+
$.each this, ->
|
236
|
+
url = $scope.addParameterToUrl url, this, path
|
237
|
+
when 'object'
|
238
|
+
path = $scope.pathBuild path, parameter.name
|
239
|
+
$.each parameter.values, ->
|
240
|
+
url = $scope.addParameterToUrl url, this, path
|
241
|
+
else
|
242
|
+
url = $scope.addSampleParameterToUrl url, parameter, path
|
254
243
|
return url
|
255
244
|
]
|
@@ -25,18 +25,65 @@ angular.module('TryApi').directive('curl', ['$filter', function($filter) {
|
|
25
25
|
})
|
26
26
|
}
|
27
27
|
|
28
|
-
|
28
|
+
let params = '';
|
29
|
+
let urlParams = '';
|
29
30
|
|
30
31
|
if(scope.model.parameters && scope.model.parameters.length > 0) {
|
31
|
-
if (
|
32
|
-
|
32
|
+
if (scope.model.method == 'get') {
|
33
|
+
urlParams += scope.toUrlParameters(scope.model.parameters);
|
34
|
+
}else if (formData) {
|
35
|
+
params += ' -c -include ' + scope.toFormDataKeys(scope.model.parameters);
|
33
36
|
} else {
|
34
|
-
|
37
|
+
params += ' -d "' + JSON.stringify(scope.toJsonParameters(scope.model.parameters)).replace(/"/g, '\\"').replace(/,/g, ', ') + '"';
|
35
38
|
}
|
36
39
|
}
|
37
40
|
|
41
|
+
scope.curlString = 'curl -X ' + method + ' ' + headers.join('') + params + ' ' + scope.model.endpoint + '/' + scope.model.submit_path + urlParams;
|
42
|
+
|
38
43
|
}, true)
|
39
44
|
|
45
|
+
scope.toUrlParameters = function(parameters,prefix,result){
|
46
|
+
if(!result)
|
47
|
+
result = [];
|
48
|
+
|
49
|
+
if(parameters && parameters.length > 0){
|
50
|
+
parameters.forEach(function(parameter){
|
51
|
+
|
52
|
+
let name = '';
|
53
|
+
|
54
|
+
if(prefix) {
|
55
|
+
name = prefix + '[' + parameter.name + ']';
|
56
|
+
}else{
|
57
|
+
name = parameter.name;
|
58
|
+
}
|
59
|
+
|
60
|
+
if(parameter.type == 'array'){
|
61
|
+
if(parameter.values && parameter.values.length > 0){
|
62
|
+
let i = 0;
|
63
|
+
parameter.values.forEach(function(value){
|
64
|
+
let temp_parameters = [];
|
65
|
+
for(let k in value){
|
66
|
+
temp_parameters.push(value[k]);
|
67
|
+
}
|
68
|
+
scope.toUrlParameters(temp_parameters, name + '[]', result);
|
69
|
+
i++;
|
70
|
+
})
|
71
|
+
}
|
72
|
+
}else{
|
73
|
+
let value = '';
|
74
|
+
|
75
|
+
if(parameter.type == 'image'){
|
76
|
+
|
77
|
+
}else{
|
78
|
+
value = parameter.value || '';
|
79
|
+
result.push(name + '=' + value);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
});
|
83
|
+
}
|
84
|
+
return '?' + result.join('&');
|
85
|
+
}
|
86
|
+
|
40
87
|
scope.toFormDataKeys = function(parameters, prefix){
|
41
88
|
let result = '';
|
42
89
|
|
@@ -52,7 +52,7 @@ angular.module('TryApi').directive 'param', [
|
|
52
52
|
' <div class="row">' +
|
53
53
|
' <div class="col-md-4 text-right">' +
|
54
54
|
' <b>{{ parameter.name }}</b>' +
|
55
|
-
' <span class="text-muted label label-warning">
|
55
|
+
' <span class="text-muted label label-warning">object</span>' +
|
56
56
|
' </div>' +
|
57
57
|
' <div class="col-md-8">' +
|
58
58
|
' <div class="text-muted small" ng-bind-html="getHtml(parameter.description)"></div>' +
|
@@ -6,6 +6,28 @@ angular.module('TryApi').directive 'paramsobject', [
|
|
6
6
|
|
7
7
|
scope.parameter.values = jQuery.extend(true, {}, scope.parameter.parameters)
|
8
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
|
+
|
9
31
|
return {
|
10
32
|
link: link
|
11
33
|
restrict: 'A'
|
@@ -13,8 +35,19 @@ angular.module('TryApi').directive 'paramsobject', [
|
|
13
35
|
scope:
|
14
36
|
parameter: '=ngModel'
|
15
37
|
template: '' +
|
16
|
-
'<div style="border: 1px solid lightgray; margin: 1px 1px 1px 10px">' +
|
38
|
+
'<div style="border: 1px solid lightgray; margin: 1px 1px 1px 10px; padding: 0 10px 10px">' +
|
17
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>' +
|
18
51
|
'</div>'
|
19
52
|
}
|
20
53
|
]
|
@@ -4,6 +4,7 @@ module TryApi
|
|
4
4
|
typesafe_accessor :type, String
|
5
5
|
typesafe_accessor :parameters, Array, default: [], items_type: TryApi::Parameter
|
6
6
|
typesafe_accessor :required, Boolean, default: true
|
7
|
+
typesafe_accessor :custom, Boolean, default: false, if: -> { self.type == 'object' }
|
7
8
|
typesafe_accessor :description, String
|
8
9
|
end
|
9
10
|
end
|
@@ -126,14 +126,58 @@ menu_items:
|
|
126
126
|
-
|
127
127
|
name: 'array'
|
128
128
|
type: 'array'
|
129
|
-
description: 'Yes! this is array which can include other sets of parameters.
|
129
|
+
description: 'Yes! this is array which can include other sets of parameters.'
|
130
130
|
parameters:
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
-
|
132
|
+
name: 'id'
|
133
|
+
type: 'integer'
|
134
134
|
-
|
135
135
|
name: 'text'
|
136
136
|
type: 'text'
|
137
|
+
-
|
138
|
+
name: 'object'
|
139
|
+
type: 'object'
|
140
|
+
parameters:
|
141
|
+
-
|
142
|
+
name: 'string'
|
143
|
+
type: 'string'
|
144
|
+
-
|
145
|
+
name: 'integer'
|
146
|
+
type: 'integer'
|
147
|
+
-
|
148
|
+
name: 'boolean'
|
149
|
+
type: 'boolean'
|
150
|
+
-
|
151
|
+
name: 'image'
|
152
|
+
type: 'image'
|
153
|
+
-
|
154
|
+
name: 'array'
|
155
|
+
type: 'array'
|
156
|
+
description: 'Yes! this is array which can include other sets of parameters.'
|
157
|
+
parameters:
|
158
|
+
-
|
159
|
+
name: 'id'
|
160
|
+
type: 'integer'
|
161
|
+
-
|
162
|
+
name: 'custom_object'
|
163
|
+
type: 'object'
|
164
|
+
custom: true
|
165
|
+
description: 'Object with ability add fileds in real time.'
|
166
|
+
parameters:
|
167
|
+
-
|
168
|
+
name: 'string'
|
169
|
+
type: 'string'
|
170
|
+
-
|
171
|
+
name: 'integer'
|
172
|
+
type: 'integer'
|
173
|
+
-
|
174
|
+
name: 'array'
|
175
|
+
type: 'array'
|
176
|
+
description: 'Yes! this is array which can include other sets of parameters.'
|
177
|
+
parameters:
|
178
|
+
-
|
179
|
+
name: 'id'
|
180
|
+
type: 'integer'
|
137
181
|
-
|
138
182
|
title: 'Endpoint with URL parameters.'
|
139
183
|
path: '/search/:q'
|
data/lib/try_api/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.7
|
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-
|
11
|
+
date: 2017-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|