Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
More tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldaviva committed Aug 1, 2013
1 parent 231b329 commit 9e74f17
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 22 deletions.
44 changes: 22 additions & 22 deletions scripts/yelp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@ 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
});
}

function getRating(){
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
};
});
}
Expand Down
3 changes: 3 additions & 0 deletions tools/duplicate_nicknames.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

node nicknames.js | uniq -D -w 3
25 changes: 25 additions & 0 deletions tools/malformed_phones.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

17 changes: 17 additions & 0 deletions tools/nicknames.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 9e74f17

Please sign in to comment.