Skip to content

Instantly share code, notes, and snippets.

@thurloat
Created February 4, 2011 15:10
Show Gist options
  • Save thurloat/811205 to your computer and use it in GitHub Desktop.
Save thurloat/811205 to your computer and use it in GitHub Desktop.
Is this un-readable?
/**
* OAuth request message skeleton for every request.
* before the final url is generated, it must be run through
* the oauth Timestamp & Signature generators
*
* @constructor
*/
sd.OAuth2.AuthMessage = function(code) {
if (code !== undefined) {
this.parameters = {};
if(code == 'refresh_token'){
this.parameters['refresh_token'] = sd.Prefs.get('refresh_token');
this.parameters['grant_type'] = 'refresh_token';
} else{
this.parameters['code'] = code;
this.parameters['grant_type'] = 'authorization_code';
}
this.parameters['client_id'] = sd.OAuth2.application_key;
this.parameters['client_secret'] = sd.OAuth2.application_key_secret;
this.parameters['redirect_uri'] = sd.OAuth2.close_url;
this.action = sd.OAuth2.token_url;
this.method = 'POST';
} else {
this.parameters = {
response_type: 'code',
client_id: sd.OAuth2.application_key,
redirect_uri: sd.OAuth2.close_url};
this.action = sd.OAuth2.authorize_url;
this.method = 'GET';
}
};
/**
* OAuth request message skeleton for every request.
* before the final url is generated, it must be run through
* the oauth Timestamp & Signature generators
*
* @constructor
*/
sd.OAuth2.AuthMessage = function(code) {
var missing_code = (code === undefined);
this.parameters = missing_code
? { response_type: 'code',
client_id: sd.OAuth2.application_key,
redirect_uri: sd.OAuth2.close_url }
: (code == 'refresh_token')
? { refresh_token: sd.Prefs.get('refresh_token'),
grant_type: 'refresh_token',
client_id: sd.OAuth2.application_key,
client_secret: sd.OAuth2.application_key_secret,
redirect_uri: sd.OAuth2.close_url }
: { code: code,
grant_type: 'authorization_code',
client_id: sd.OAuth2.application_key,
client_secret: sd.OAuth2.application_key_secret,
redirect_uri: sd.OAuth2.close_url };
this.action = missing_code ? sd.OAuth2.authorize_url : sd.OAuth2.token_url;
this.method = missing_code ? 'GET' : 'POST'
};
/**
* OAuth request message skeleton for every request.
* before the final url is generated, it must be run through
* the oauth Timestamp & Signature generators
*
* @constructor
*/
sd.OAuth2.AuthMessage = function(code) {
var missing_code = (code === undefined);
this.parameters = missing_code ? { response_type: 'code', client_id: sd.OAuth2.application_key, redirect_uri: sd.OAuth2.close_url } : (code == 'refresh_token') ? { refresh_token: sd.Prefs.get('refresh_token'), grant_type: 'refresh_token', client_id: sd.OAuth2.application_key, client_secret: sd.OAuth2.application_key_secret, redirect_uri: sd.OAuth2.close_url } : { code: code, grant_type: 'authorization_code', client_id: sd.OAuth2.application_key, client_secret: sd.OAuth2.application_key_secret, redirect_uri: sd.OAuth2.close_url };
this.action = missing_code ? sd.OAuth2.authorize_url : sd.OAuth2.token_url;
this.method = missing_code ? 'GET' : 'POST'
};
@honza
Copy link

honza commented Feb 4, 2011

CoffeeScript

sd.OAuth2.AuthMessage = (code) ->
  if code?
    if code is "refresh_token"
      @parameters['refresh_token'] = sd.Prefs.get('refresh_token')
      @paramaters['grant_token'] = 'refresh_token'
      @parameters =
        code: code,
        grant_type: 'authorization_code',
        client_id: sd.OAuth2.application_key,
        client_secret: sd.OAuth2.application_key_secret,
        redirect_uri: sd.OAuth2.close_url
      @action = sd.OAuth2.token_url
      @method = 'POST'
  else
    @parameters =
      response_type: 'code',
      client_id: sd.OAuth2.application_key,
      redirect_uri: sd.OAuth2.close_url
    @action = sd.OAuth2.authorize_url
    @method = 'GET'

@thurloat
Copy link
Author

thurloat commented Feb 4, 2011

I've updated the if statement to be more correct. Want to update your coffeescript?

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