0
App.StaticConfig = Ember.Object.extend({
    URL: null,
    parameters: null,
    consumerSecret: null,
    encodedSignature: null,
    callback: null,
});


var staticConfig = App.StaticConfig.create({
    URL: 'https://api.twitter.com/oauth/request_token',
    parameters: {
        oauth_consumer_key : 'key',
        oauth_nonce : 'kllo9940pd9333jh',
        oauth_timestamp : '1191242096',
        oauth_signature_method : 'HMAC-SHA1',
        oauth_version : '1.0',
    },

    consumerSecret : 'key',
    encodedSignature : oauthSignature.generate('POST', URL, parameters, consumerSecret),

});

App.TwitterController = Ember.ObjectController.extend({

    actions: {  

        loginTwitter: function() {
            console.log('Event Clicked');
            return new Ember.RSVP.Promise(function(resolve, reject) {
            Ember.$.ajax({
                url:         'https://api.twitter.com/oauth/request_token',
                type:        'POST',
                contentType: "jsonp",
                headers: {
                    "Authorization": 'OAuth oauth_callback='+ staticConfig.get('callback') +', oauth_consumer_key="", oauth_nonce="kllo9940pd9333jh", oauth_signature='+ staticConfig.get('encodedSignature') +', oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_version="1.0"'
                },

                contentType: 'application/x-www-form-urlencoded'
            }).then(function(response) {
                console.log('Successed');
                console.log(response);
                resolve (response);
            }, function(xhr, status, error) {
                console.log(error);
                console.log('In Error');
                reject(error);
            });
        });
        },
    }
});

At below line I get ReferenceError: parameters is not defined and also same for consumerSecret encodedSignature : oauthSignature.generate('POST', URL, parameters, consumerSecret),

Also is my creating oauth_signature and oauth_nonce correctly.

vkurchatkin
  • 13,364
  • 2
  • 47
  • 55
Sohaib Ahmed
  • 31
  • 1
  • 6

2 Answers2

1

Looks like encodedSignature can be nicely implemented as computed property:

encodedSignature : function () {
  var URL = this.get('URL');
  var parameters = this.get('parameters');
  var consumerSecret = this.get('consumerSecret');

  return oauthSignature.generate('POST', URL, parameters, consumerSecret)
}.property('URL', 'parameters', 'consumer_secret')
vkurchatkin
  • 13,364
  • 2
  • 47
  • 55
0

Well, parameters and consumerSecret are not set in your code, really: there are property names of the object you are creating, not declared variables.

laruiss
  • 3,780
  • 1
  • 18
  • 29
  • when i declare variable it give the error 'SyntaxError: missing : after property id' I declare variable in the TwitterController. – Sohaib Ahmed Oct 01 '14 at 12:23