assets/scripts/core.js in bfdotcom-theme-0.2.2 vs assets/scripts/core.js in bfdotcom-theme-0.2.3
- old
+ new
@@ -88,8 +88,111 @@
function addMinutes(date, minutes) {
return new Date(date + minutes*60000)
}
+var apigClientFactory = {};
+apigClientFactory.newClient = function (config) {
+ var apigClient = { };
+ if(config === undefined) {
+ config = {
+ accessKey: '',
+ secretKey: '',
+ sessionToken: '',
+ region: aws_region,
+ apiKey: undefined,
+ defaultContentType: 'application/json',
+ defaultAcceptType: 'application/json'
+ };
+ }
+ if(config.accessKey === undefined) {
+ config.accessKey = '';
+ }
+ if(config.secretKey === undefined) {
+ config.secretKey = '';
+ }
+ if(config.apiKey === undefined) {
+ config.apiKey = '';
+ }
+ if(config.sessionToken === undefined) {
+ config.sessionToken = '';
+ }
+ if(config.region === undefined) {
+ config.region = aws_region;
+ }
+ //If defaultContentType is not defined then default to application/json
+ if(config.defaultContentType === undefined) {
+ config.defaultContentType = 'application/json';
+ }
+ //If defaultAcceptType is not defined then default to application/json
+ if(config.defaultAcceptType === undefined) {
+ config.defaultAcceptType = 'application/json';
+ }
+ // extract endpoint and path from url
+ var invokeUrl = api_gateway_url;
+ var endpoint = /(^https?:\/\/[^\/]+)/g.exec(invokeUrl)[1];
+ var pathComponent = invokeUrl.substring(endpoint.length);
+ var sigV4ClientConfig = {
+ accessKey: config.accessKey,
+ secretKey: config.secretKey,
+ sessionToken: config.sessionToken,
+ serviceName: 'execute-api',
+ region: config.region,
+ endpoint: endpoint,
+ defaultContentType: config.defaultContentType,
+ defaultAcceptType: config.defaultAcceptType
+ };
+ var authType = 'NONE';
+ if (sigV4ClientConfig.accessKey !== undefined && sigV4ClientConfig.accessKey !== '' && sigV4ClientConfig.secretKey !== undefined && sigV4ClientConfig.secretKey !== '') {
+ authType = 'AWS_IAM';
+ }
+ var simpleHttpClientConfig = {
+ endpoint: endpoint,
+ defaultContentType: config.defaultContentType,
+ defaultAcceptType: config.defaultAcceptType
+ };
+ var apiGatewayClient = apiGateway.core.apiGatewayClientFactory.newClient(simpleHttpClientConfig, sigV4ClientConfig);
+ apigClient.commentsPost = function (params, body, additionalParams) {
+ if(additionalParams === undefined) { additionalParams = {}; }
+ apiGateway.core.utils.assertParametersDefined(params, [], ['body']);
+ var commentsPostRequest = {
+ verb: 'post'.toUpperCase(),
+ path: pathComponent + uritemplate('/comments').expand(apiGateway.core.utils.parseParametersToObject(params, [])),
+ headers: apiGateway.core.utils.parseParametersToObject(params, []),
+ queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
+ body: body
+ };
+ return apiGatewayClient.makeRequest(commentsPostRequest, authType, additionalParams, config.apiKey);
+ };
+ return apigClient;
+};
+
+function submitComment() {
+ var commentText = $('#commentText').text()
+ var userInfo = getUserInfo()
+ $('#submitButton').hide()
+ $('#commentText').hide()
+ $('#submittingComment').show()
+ var apigClient = apigClientFactory.newClient();
+ apigClient.commentsPost({}, {
+ "authorName": userInfo.name,
+ "authorEmail": userInfo.email,
+ "postUrl": window.location.pathname,
+ "comment": commentText
+ }, additionalParams)
+ .then(function(result){
+ //This is where you would put a success callback
+ $('#commentSuccess').show()
+ $('#submittingComment').hide()
+ }).catch( function(result){
+ //This is where you would put an error callback
+ $('#commentError').show()
+ $('#submittingComment').hide()
+ });
+}
+
$(document).ready(function() {
refreshSignedInStatus()
+ $('#commentSuccess').hide()
+ $('#commentError').hide()
+ $('#submittingComment').hide()
})