Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions src/main/js/controllers/TryingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,44 @@ define(function(){
// Read the method
var method = endpoint.get("method").trim().toLowerCase();

//Read jsonType
var className = endpoint.get("className");
var jsonType = endpoint.get("jsonType");

// Read the parameters
var ajaxParams = {};
var requiredMissing = false;
var headers = {};

_.each(params, function(param){

var name = param.model.get("name");
var value = getValueFrom( param.el );
var paramel = param.el;

if (name.indexOf('.') !== -1) {
paramel = param.el.prevObject;
}

var value = getValueFrom( paramel );
var required = param.model.get("required");

if (required && value === null) {
requiredMissing = true;
}

// URL param?
if( param.model.get("urlParam") ) {

// Replace all occurrences on URL
endpointUrl = endpointUrl.split("{" + name + "}").join(value);

} else if( value != null ) {
// Header param?
} else if ( param.model.get("headerParam" ) ) {

//Set this as header param
headers[ name ] = value;

} else if ( value != null ) {

// Add to send on Ajax request
if( !ajaxParams[ name ] ) {
Expand All @@ -46,6 +69,19 @@ define(function(){

});

//Check if need to create a json
if ( jsonType && className) {
var obj = new Object();
obj[className] = ajaxParams;
ajaxParams = JSON.stringify(obj);
}

//Check if missing a required parameter
if (requiredMissing) {
APIBuddy.trigger( "updateStatus", {label: "Missing required parameter", className: "status-red"} );
return;
}

// Should we send the method as a parameter?
if( Config.methodParam ) {

Expand Down Expand Up @@ -79,8 +115,12 @@ define(function(){

data: ajaxParams,

headers: headers,

traditional: traditionalSerialization,

contentType: "application/json",

dataType: "text",

crossDomain: true,
Expand Down
2 changes: 2 additions & 0 deletions src/main/js/models/EndpointModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ define(function(){
dynamicParams: false,
url: "",
method: "GET",
jsonType: false,
className: null,
params: [],
errors: []
},
Expand Down
12 changes: 11 additions & 1 deletion src/main/js/models/ParamModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ define(function(){
globalParam: false,
urlParam: false,
multiValue: false,
multipart: false
multipart: false,
required: false,
headerParam: false
},

getLabel: function() {
Expand All @@ -21,6 +23,14 @@ define(function(){
}

return this.get("label");
},

getDescription: function () {
if (this.get("required")) {
return this.get("description") + ' (REQUIRED)';
}

return this.get("description");
}

});
Expand Down
2 changes: 1 addition & 1 deletion src/main/templates/tryingTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2 class="try-title">[<%= method %>] <%= label %></h2>

</div>

<span class="try-param-desc"><%= param.get("description") %></span>
<span class="try-param-desc"><%= param.getDescription() %></span>

</td>
</tr>
Expand Down