Skip to content

Instantly share code, notes, and snippets.

@mittsh
Created September 29, 2017 12:04
Show Gist options
  • Save mittsh/958cda76f4df3b31b62066a227c73ed6 to your computer and use it in GitHub Desktop.
Save mittsh/958cda76f4df3b31b62066a227c73ed6 to your computer and use it in GitHub Desktop.
// context docs: https://paw.cloud/docs/reference/ExtensionContext
// request docs: https://paw.cloud/docs/reference/Request
// DynamicString docs: https://paw.cloud/docs/reference/DynamicString
// DynamicValue docs: https://paw.cloud/docs/reference/DynamicValue
function logRequestVariableInfo(requestVariable) {
console.log('Request Variable: ' + requestVariable.name + '\n' +
' Request: ' + requestVariable.request.name + '\n' +
' Value: ' + requestVariable.value + '\n' +
' Description: ' + requestVariable.description + '\n' +
' Required: ' + requestVariable.required + '\n' +
' Schema: ' + JSON.stringify(requestVariable.schema));
}
function logDynamicValue(dynamicValue, request) {
if (dynamicValue.type === 'com.luckymarmot.RequestVariableDynamicValue') {
// it's a request variable
var requestVariable = request.getVariableById(dynamicValue.variableUUID);
logRequestVariableInfo(requestVariable);
}
else {
console.log('Dynamic Value: Type: ' + dynamicValue.type);
}
}
function getUrlPattern(request){
var requestUrl = request.getUrl(true); // DynamicString
var components = requestUrl.components; // Array of DynamicString
var urlPattern = ''; // string
for (var i = 0; i < components.length; i++) {
var component = components[i];
if (typeof component === 'string') {
// component (string)
urlPattern += component;
}
else {
// let's log it
logDynamicValue(component, request);
// component (DynamicValue)
if (component.type === 'com.luckymarmot.RequestVariableDynamicValue') {
// it's a request variable
var requestVariable = request.getVariableById(component.variableUUID);
if (requestVariable) {
urlPattern += '{' + requestVariable.name + '}';
}
else {
urlPattern += '{unknown}';
}
}
else {
urlPattern += component.getEvaluatedString();
}
}
}
return urlPattern;
};
function evaluate(context){
var request = context.getCurrentRequest(); // Request
return getUrlPattern(request);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment