Skip to content

Commit

Permalink
chore: Format
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Jul 29, 2022
1 parent 018cb87 commit d7c9127
Show file tree
Hide file tree
Showing 22 changed files with 223 additions and 185 deletions.
58 changes: 58 additions & 0 deletions .cfformat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"alignment.consecutive.assignments":false,
"alignment.consecutive.params":false,
"alignment.consecutive.properties":false,
"array.empty_padding":false,
"array.multiline.element_count":4,
"array.multiline.leading_comma":false,
"array.multiline.leading_comma.padding":true,
"array.multiline.min_length":40,
"array.padding":true,
"binary_operators.padding":true,
"brackets.padding":true,
"comment.asterisks":"align",
"for_loop_semicolons.padding":true,
"function_anonymous.empty_padding":false,
"function_anonymous.group_to_block_spacing":"spaced",
"function_anonymous.multiline.element_count":4,
"function_anonymous.multiline.leading_comma":false,
"function_anonymous.multiline.leading_comma.padding":true,
"function_anonymous.multiline.min_length":40,
"function_anonymous.padding":true,
"function_call.casing.builtin":"cfdocs",
"function_call.casing.userdefined":"camel",
"function_call.empty_padding":false,
"function_call.multiline.element_count":4,
"function_call.multiline.leading_comma":false,
"function_call.multiline.leading_comma.padding":true,
"function_call.multiline.min_length":40,
"function_call.padding":true,
"function_declaration.empty_padding":false,
"function_declaration.group_to_block_spacing":"spaced",
"function_declaration.multiline.element_count":4,
"function_declaration.multiline.leading_comma":false,
"function_declaration.multiline.leading_comma.padding":true,
"function_declaration.multiline.min_length":40,
"function_declaration.padding":true,
"indent_size":4,
"keywords.block_to_keyword_spacing":"spaced",
"keywords.empty_group_spacing":false,
"keywords.group_to_block_spacing":"spaced",
"keywords.padding_inside_group":true,
"keywords.spacing_to_block":"spaced",
"keywords.spacing_to_group":true,
"max_columns":120,
"method_call.chain.multiline":3,
"newline":"\n",
"parentheses.padding":true,
"strings.attributes.quote":"double",
"strings.quote":"double",
"struct.empty_padding":false,
"struct.multiline.element_count":4,
"struct.multiline.leading_comma":false,
"struct.multiline.leading_comma.padding":true,
"struct.multiline.min_length":40,
"struct.padding":true,
"struct.separator":": ",
"tab_indent":false
}
12 changes: 6 additions & 6 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ component {

function configure() {
settings = {
accountSID = getSystemSetting( "TWILIO_ACCOUNT_SID", "" ),
authToken = getSystemSetting( "TWILIO_AUTHTOKEN", "" )
accountSID: getSystemSetting( "TWILIO_ACCOUNT_SID", "" ),
authToken: getSystemSetting( "TWILIO_AUTHTOKEN", "" )
};
}

function onLoad() {
binder.map( "TwilioHyperClient@twilio-sdk" )
binder
.map( "TwilioHyperClient@twilio-sdk" )
.to( "hyper.models.HyperBuilder" )
.asSingleton()
.initWith(
username = settings.accountSID,
password = settings.authToken,
baseURL = "https://api.twilio.com/2010-04-01",
bodyFormat = "formFields",
headers = {
"Content-Type" = "application/x-www-form-urlencoded"
}
headers = { "Content-Type": "application/x-www-form-urlencoded" }
);
}

}
4 changes: 4 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"shortDescription":"CFML SDK to interact with the Twilio API",
"description":"CFML SDK to interact with the Twilio API",
"type":"modules",
"scripts": {
"format": "cfformat run models/**/*.cfc,tests/Application.cfc,tests/resources/**/*.cfc,tests/specs/**/*.cfc,ModuleConfig.cfc --overwrite",
"format:check": "cfformat check models/**/*.cfc,tests/Application.cfc,tests/resources/**/*.cfc,tests/specs/**/*.cfc,ModuleConfig.cfc"
},
"dependencies":{
"hyper":"^3.4.0"
},
Expand Down
17 changes: 8 additions & 9 deletions models/SignatureValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ component accessors="true" {
function validate( expectedSignature, uri, params = {} ) {
var paramsArray = params.keyArray();
paramsArray.sort( "text" );
return hmacSha1( uri & paramsArray.map( function( key ) {
return key & params[key];
} ).toList( "" ) ) == expectedSignature;
return hmacSha1(
uri & paramsArray
.map( function( key ) {
return key & params[ key ];
} )
.toList( "" )
) == expectedSignature;
}

private function hmacSha1( string ) {
return toBase64(
binaryDecode(
HMAC( string, authToken, "HMACSHA1" ),
"hex"
)
);
return toBase64( binaryDecode( hmac( string, authToken, "HMACSHA1" ), "hex" ) );
}

}
40 changes: 16 additions & 24 deletions models/TwilioClient.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ component singleton accessors="true" {
/**
* Look up information about a phone number.
*
* @phoneNumber The phone number to look up.
* @phoneNumber The phone number to look up.
* @withCallerName Should caller information be included in the response.
* (This costs extra.) [Deprecated in favor of @type] Default: false.
* @types An optional array of types of information to be
* included in the response. Options include 'carrier'
* and 'caller-name'. (This costs extra.)
* (This costs extra.) [Deprecated in favor of @type] Default: false.
* @types An optional array of types of information to be
* included in the response. Options include 'carrier'
* and 'caller-name'. (This costs extra.)
* @addons An optional array of addons to process and include
* in the response. (This may cost extra.)
*
Expand All @@ -32,23 +32,23 @@ component singleton accessors="true" {
function lookup(
phoneNumber,
withCallerName = false,
types = [],
types = [],
addons = []
) {
var req = newRequest()
.setBaseUrl( "https://lookups.twilio.com" )
.setUrl( "/v1/PhoneNumbers/#trim( arguments.phoneNumber )#" );
.setUrl( "/v1/PhoneNumbers/#trim( arguments.phoneNumber )#" );

if ( arguments.withCallerName ) {
req.withQueryParams( { "Type": "caller-name" } );
if ( arguments.withCallerName ) {
req.withQueryParams( { "Type": "caller-name" } );
}

for ( var type in arguments.types ) {
req.withQueryParams( { "Type": type } );
}
for ( var type in arguments.types ) {
req.withQueryParams( { "Type": type } );
}

for ( var addon in arguments.addons ) {
req.withQueryParams( { "AddOns": addon } );
for ( var addon in arguments.addons ) {
req.withQueryParams( { "AddOns": addon } );
}

return req;
Expand All @@ -68,11 +68,7 @@ component singleton accessors="true" {
return newRequest()
.setMethod( "POST" )
.setUrl( "/Accounts/#accountSID#/Messages.json" )
.setBody( {
"From" = arguments.from,
"To" = arguments.to,
"Body" = arguments.body
} );
.setBody( { "From": arguments.from, "To": arguments.to, "Body": arguments.body } );
}

/**
Expand All @@ -92,11 +88,7 @@ component singleton accessors="true" {
required string twiml,
struct additionalParams = {}
) {
var body = {
"From" = arguments.from,
"To" = arguments.to,
"Twiml" = arguments.twiml
};
var body = { "From": arguments.from, "To": arguments.to, "Twiml": arguments.twiml };
structAppend( body, additionalParams );

return newRequest()
Expand Down
45 changes: 23 additions & 22 deletions tests/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
/**
* Copyright Since 2005 Ortus Solutions, Corp
* www.coldbox.org | www.luismajano.com | www.ortussolutions.com | www.gocontentbox.org
**************************************************************************************
*/
component{
this.name = "A TestBox Runner Suite " & hash( getCurrentTemplatePath() );
// any other application.cfc stuff goes below:
this.sessionManagement = true;
// Turn on/off white space management
this.whiteSpaceManagement = "smart";
* Copyright Since 2005 Ortus Solutions, Corp
* www.coldbox.org | www.luismajano.com | www.ortussolutions.com | www.gocontentbox.org
**************************************************************************************
*/
component {

// any mappings go here, we create one that points to the root called test.
testsPath = getDirectoryFromPath( getCurrentTemplatePath() );
this.mappings[ "/tests" ] = testsPath;
rootPath = REReplaceNoCase( this.mappings[ "/tests" ], "tests(\\|/)", "" );
this.mappings[ "/root" ] = rootPath;
this.mappings[ "/twilio-sdk" ] = rootPath;
this.mappings[ "/hyper" ] = rootPath & "modules/hyper";
this.mappings[ "/testingModuleRoot" ] = listDeleteAt( rootPath, listLen( rootPath, '\/' ), "\/" );
this.name = "A TestBox Runner Suite " & hash( getCurrentTemplatePath() );
// any other application.cfc stuff goes below:
this.sessionManagement = true;
// Turn on/off white space management
this.whiteSpaceManagement = "smart";

// any mappings go here, we create one that points to the root called test.
testsPath = getDirectoryFromPath( getCurrentTemplatePath() );
this.mappings[ "/tests" ] = testsPath;
rootPath = reReplaceNoCase( this.mappings[ "/tests" ], "tests(\\|/)", "" );
this.mappings[ "/root" ] = rootPath;
this.mappings[ "/twilio-sdk" ] = rootPath;
this.mappings[ "/hyper" ] = rootPath & "modules/hyper";
this.mappings[ "/testingModuleRoot" ] = listDeleteAt( rootPath, listLen( rootPath, "\/" ), "\/" );
this.mappings[ "/app" ] = testsPath & "resources/app";
this.mappings[ "/coldbox" ] = testsPath & "resources/app/coldbox";
this.mappings[ "/testbox" ] = rootPath & "testbox";

// request start
public boolean function onRequestStart( String targetPage ){
return true;
}
// request start
public boolean function onRequestStart( String targetPage ) {
return true;
}

}
13 changes: 6 additions & 7 deletions tests/resources/ModuleIntegrationSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ component extends="coldbox.system.testing.BaseTestCase" {
function beforeAll() {
super.beforeAll();

getController().getModuleService()
.registerAndActivateModule( "twilio-sdk", "testingModuleRoot" );
getController().getModuleService().registerAndActivateModule( "twilio-sdk", "testingModuleRoot" );
}

/**
* @beforeEach
*/
* @beforeEach
*/
function setupIntegrationTest() {
setup();
}
Expand All @@ -18,16 +17,16 @@ component extends="coldbox.system.testing.BaseTestCase" {
var system = createObject( "java", "java.lang.System" );

var envValue = system.getEnv( name );
if ( ! isNull( envValue ) ) {
if ( !isNull( envValue ) ) {
return envValue;
}

var propValue = system.getProperty( name );
if ( ! isNull( propValue ) ) {
if ( !isNull( propValue ) ) {
return propValue;
}

if ( ! isNull( defaultValue ) ) {
if ( !isNull( defaultValue ) ) {
return defaultValue;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/resources/app/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ component {
COLDBOX_APP_KEY = "";

// application start
public boolean function onApplicationStart() {
public boolean function onApplicationStart(){
application.cbBootstrap = new coldbox.system.Bootstrap(
COLDBOX_CONFIG_FILE,
COLDBOX_APP_ROOT_PATH,
Expand All @@ -40,27 +40,27 @@ component {
}

// application end
public void function onApplicationEnd( struct appScope ) {
public void function onApplicationEnd( struct appScope ){
arguments.appScope.cbBootstrap.onApplicationEnd( arguments.appScope );
}

// request start
public boolean function onRequestStart( string targetPage ) {
public boolean function onRequestStart( string targetPage ){
// Process ColdBox Request
application.cbBootstrap.onRequestStart( arguments.targetPage );

return true;
}

public void function onSessionStart() {
public void function onSessionStart(){
application.cbBootStrap.onSessionStart();
}

public void function onSessionEnd( struct sessionScope, struct appScope ) {
public void function onSessionEnd( struct sessionScope, struct appScope ){
arguments.appScope.cbBootStrap.onSessionEnd( argumentCollection = arguments );
}

public boolean function onMissingTemplate( template ) {
public boolean function onMissingTemplate( template ){
return application.cbBootstrap.onMissingTemplate( argumentCollection = arguments );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/resources/app/config/CacheBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ component {
/**
* Configure CacheBox for ColdBox Application Operation
*/
function configure() {
function configure(){
/**
* --------------------------------------------------------------------------
* CacheBox Configuration (https://cachebox.ortusbooks.com)
Expand Down
10 changes: 5 additions & 5 deletions tests/resources/app/config/Coldbox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ component {
/**
* Configure the ColdBox App For Production
*/
function configure() {
function configure(){
/**
* --------------------------------------------------------------------------
* ColdBox Directives
Expand Down Expand Up @@ -138,9 +138,9 @@ component {
* }
*/
moduleSettings = {
"twilio-sdk": {
accountSID = getSystemSetting( "TWILIO_TEST_ACCOUNT_SID" ),
authToken = getSystemSetting( "TWILIO_TEST_AUTHTOKEN" )
"twilio-sdk" : {
accountSID : getSystemSetting( "TWILIO_TEST_ACCOUNT_SID" ),
authToken : getSystemSetting( "TWILIO_TEST_AUTHTOKEN" )
}
};

Expand Down Expand Up @@ -176,7 +176,7 @@ component {
/**
* Development environment
*/
function development() {
function development(){
// coldbox.customErrorTemplate = "/coldbox/system/exceptions/BugReport.cfm"; // static bug reports
coldbox.customErrorTemplate = "/coldbox/system/exceptions/Whoops.cfm"; // interactive bug report
}
Expand Down
Loading

0 comments on commit d7c9127

Please sign in to comment.