Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

66 displayer api #106

Merged
merged 25 commits into from Mar 31, 2012

Conversation

Projects
None yet
2 participants
Contributor

brianloveswords commented Mar 31, 2012

[issue #66] All right, I think this sucker is done.

Contributor

brianloveswords commented Mar 31, 2012

Updated description, I think this is ready to roll.

Contributor

brianloveswords commented Mar 31, 2012

/displayer/convert/email looks like so:

@cmcavoy cmcavoy commented on the diff Mar 31, 2012

@@ -59,6 +59,12 @@ router(app)
.get('/issuer/validator', 'issuer.validator')
.post('/issuer/validator', 'issuer.validator')
+
+ .get('/displayer/:dUserId/groups.:format?', 'displayer.userGroups')
@cmcavoy

cmcavoy Mar 31, 2012

Contributor

I like that format is configurable...nice.

@cmcavoy cmcavoy commented on the diff Mar 31, 2012

controllers/displayer.js
+// ------------
+function displayerAPIVersion (request, response, next) {
+ return formatResponse({
+ status: 'okay',
+ version: '0.5.0'
+ }, request, response)
+}
+
+function emailToUserIdView (request, response, next) {
+ return response.render('email-converter');
+}
+
+function emailToUserId (request, response, next) {
+ // don't use formatter here -- we aren't supporting jsonp or CORS for
+ // the email to userId API because we want to discourage people including
+ // email addresses in cleartext (such as in the source of some javascript)
@cmcavoy

cmcavoy Mar 31, 2012

Contributor

+1

@cmcavoy cmcavoy commented on the diff Mar 31, 2012

controllers/displayer.js
+ User.findOne({ email: email }, function (err, user) {
+ if (err) {
+ logger.debug('displayer#emailToUserId: there was an error getting the user');
+ logger.debug('email: ' + email);
+ logger.debug('error: ' + JSON.stringify(err));
+ return response.send({
+ status: 'error',
+ error: 'error trying to pull user `' + email + '` from database'
+ }, 400)
+ }
+
+ if (!user)
+ return response.send({
+ status: 'missing',
+ error: 'Could not find a user by the email address `' + email + '`'
+ }, 404)
@cmcavoy

cmcavoy Mar 31, 2012

Contributor

if the errors are json, are you setting the content type to json?

@brianloveswords

brianloveswords Mar 31, 2012

Contributor

express is smart about detecting what content type to send it as. If response.send is given an object it will automatically JSON.stringify it and set the content-type to application/json unless told otherwise.

@brianloveswords brianloveswords commented on the diff Mar 31, 2012

controllers/group.js
group.save(function (err) {
- if (err) return res.send('nope', 500);
- res.contentType('json');
- res.send({status: 'okay'});
+ if (err) {
+ logger.debug('there was an error updating a group:');
+ logger.debug(err);
+ return response.send({
+ status: 'error',
+ error: 'there was an unknown error. it has been logged.'
+ }, 500);
+ }
+
+ response.contentType('json');
@brianloveswords

brianloveswords Mar 31, 2012

Contributor

(continued from above)
This is actually extraneous, express will know to send it as JSON.

brianloveswords added a commit that referenced this pull request Mar 31, 2012

@brianloveswords brianloveswords merged commit a94e4cf into development Mar 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment