diff --git a/scripts/yelp.js b/scripts/yelp.js index 7be5b57..fac2d7f 100644 --- a/scripts/yelp.js +++ b/scripts/yelp.js @@ -3,43 +3,43 @@ this.yelp = (function(){ var BUSINESS_ID = 'bluejeans-mountain-view'; var ACCESS_PARAMS = { - consumerKey: "wq6N1ApR2G6CvL1d5IhKFQ", - consumerSecret: "6_G7aiIJVO4ZugkN4VmE1rkzYN8", - token: "EbVtea8l0sAcWn85sFZ1xm_4tpRhv-yf", - tokenSecret: "7gtqhRMHYvuAnKfUwLGi5mofBe8" + consumerKey : "wq6N1ApR2G6CvL1d5IhKFQ", + consumerSecret : "6_G7aiIJVO4ZugkN4VmE1rkzYN8", + token : "EbVtea8l0sAcWn85sFZ1xm_4tpRhv-yf", + tokenSecret : "7gtqhRMHYvuAnKfUwLGi5mofBe8" }; var REQ_PARAMS = [ - ['callback', 'cb'], - ['oauth_consumer_key', ACCESS_PARAMS.consumerKey], - ['oauth_consumer_secret', ACCESS_PARAMS.consumerSecret], - ['oauth_token', ACCESS_PARAMS.token], + ['callback', 'cb'], + ['oauth_consumer_key', ACCESS_PARAMS.consumerKey], + ['oauth_consumer_secret', ACCESS_PARAMS.consumerSecret], + ['oauth_token', ACCESS_PARAMS.token], ['oauth_signature_method', 'HMAC-SHA1'] ]; function _sendRequest(urlTail, method){ var requestEnvelope = { - action: 'http://api.yelp.com/v2/'+urlTail, - method: method, - parameters: REQ_PARAMS + action : 'http://api.yelp.com/v2/'+urlTail, + method : method || 'GET', + parameters : REQ_PARAMS }; OAuth.setTimestampAndNonce(requestEnvelope); OAuth.SignatureMethod.sign(requestEnvelope, { - consumerSecret: ACCESS_PARAMS.consumerSecret, - tokenSecret: ACCESS_PARAMS.tokenSecret + consumerSecret : ACCESS_PARAMS.consumerSecret, + tokenSecret : ACCESS_PARAMS.tokenSecret }); var parameterMap = OAuth.getParameterMap(requestEnvelope.parameters); parameterMap.oauth_signature = OAuth.percentEncode(parameterMap.oauth_signature); return $.ajax({ - url: requestEnvelope.action, - type: requestEnvelope.method, - dataType: 'jsonp', - data: parameterMap, - jsonpCallback: 'cb', - cache: true + url : requestEnvelope.action, + type : requestEnvelope.method, + dataType : 'jsonp', + data : parameterMap, + jsonpCallback : 'cb', + cache : true }); } @@ -47,9 +47,9 @@ this.yelp = (function(){ return _sendRequest('business/'+BUSINESS_ID, 'GET') .then(function(data){ return { - stars: data.rating, - reviews: data.review_count, - img: data.rating_img_url + stars : data.rating, + reviews : data.review_count, + img : data.rating_img_url }; }); } diff --git a/tools/duplicate_nicknames.sh b/tools/duplicate_nicknames.sh new file mode 100755 index 0000000..a1b11f3 --- /dev/null +++ b/tools/duplicate_nicknames.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +node nicknames.js | uniq -D -w 3 diff --git a/tools/malformed_phones.js b/tools/malformed_phones.js new file mode 100644 index 0000000..088b4e6 --- /dev/null +++ b/tools/malformed_phones.js @@ -0,0 +1,25 @@ +var people = require('../people'); +var _ = require('lodash'); + +var PHONE_PATTERN = /^\d{3}-\d{3}-\d{4}$/; + +function isValidPhoneNumber(phoneNumber){ + return PHONE_PATTERN.test(phoneNumber); +} + +console.log("Malformed phone numbers:"); + +_(people) + .forEach(function(person){ + var mobilePhone = person.mobilePhone; + var workPhone = person.workPhone; + + if(mobilePhone && !isValidPhoneNumber(mobilePhone)){ + console.warn("%s: %s", person.fullname, person.mobilePhone); + } + + if(workPhone && !isValidPhoneNumber(workPhone)){ + console.warn("%s: %s", person.fullname, person.workPhone); + } + }); + diff --git a/tools/nicknames.js b/tools/nicknames.js new file mode 100644 index 0000000..3353038 --- /dev/null +++ b/tools/nicknames.js @@ -0,0 +1,17 @@ +var people = require('../people'); +var _ = require('lodash'); + +_(people) + .sortBy('fullname') + .map(function(person){ + person.nickname = person.fullname.split(/\s/).map(function(name){ + var firstInitial = name.charAt(0).toLowerCase(); + return (firstInitial == '(') + ? '' + : firstInitial; + }).join(''); + return person; + }) + .forEach(function(person){ + console.log(person.nickname + '\t' + person.fullname); + });