Skip to content

Instantly share code, notes, and snippets.

@CodeDotJS
Last active May 21, 2017 21:20
Show Gist options
  • Save CodeDotJS/c0738762f9ad96668ccfca2a66a7f8bd to your computer and use it in GitHub Desktop.
Save CodeDotJS/c0738762f9ad96668ccfca2a66a7f8bd to your computer and use it in GitHub Desktop.
'use strict';
const got = require('got');
const user = process.argv[2];
const opts = process.argv[3];
const url = `http://en.gravatar.com/${user}.json`;
if (!user || ! opts) {
console.log('Gimme what I need');
process.exit(1);
}
/*
opts can be -
--id
--hash
--requestHash
--profileUrl
--preferredUsername
--thumbnailUrl
--displayName
--aboutMe
--currentLocation
--emails
--accounts
--urls
*/
got(url, {json: true}).then(res => {
const boi = res.body;
const data = boi.entry[0].opts;
// returns undefined because opts is a string
console.log(data);
});
// I was thinking to use this as a solution to my problem, but looks like it's not working
Object.prototype.getKeyByValue = function(value) {
for (const prop in this) {
if (this.hasOwnProperty(prop)) {
if (this[prop] === value)
return prop;
}
}
}
const test = {
id: '--id',
hash: '--hash'
};
const a = test.getKeyByValue('--id');
console.log(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment