@@ -117,6 +117,44 @@ Itunes.prototype.login = function(username, password) {
117117 } ) ;
118118} ;
119119
120+ Itunes . prototype . changeProvider = function ( providerId , callback ) {
121+ var self = this ;
122+ async . whilst ( function ( ) {
123+ return self . _queue . paused ;
124+ } , function ( callback ) {
125+ setTimeout ( function ( ) {
126+ callback ( null ) ;
127+ } , 500 ) ;
128+ } , function ( error ) {
129+ request . get ( {
130+ url : 'https://analytics.itunes.apple.com/analytics/api/v1/settings/provider/' + providerId ,
131+ headers : self . getHeaders ( )
132+ } , function ( error , response , body ) {
133+ //extract the account info cookie
134+ var myAccount = / m y a c i n f o = .+ ?; / . exec ( self . _cookies ) ;
135+
136+ if ( myAccount == null || myAccount . length == 0 ) {
137+ error = error || new Error ( 'No account cookie :( Apple probably changed the login process' ) ;
138+ } else {
139+ var cookies = response ? response . headers [ 'set-cookie' ] : null ;
140+
141+ if ( error || ! ( cookies && cookies . length ) ) {
142+ error = error || new Error ( 'There was a problem with loading the login page cookies.' ) ;
143+ } else {
144+ //extract the itCtx cookie
145+ var itCtx = / i t c t x = .+ ?; / . exec ( cookies ) ;
146+ if ( itCtx == null || itCtx . length == 0 ) {
147+ error = error || new Error ( 'No itCtx cookie :( Apple probably changed the login process' ) ;
148+ } else {
149+ self . _cookies = myAccount [ 0 ] + " " + itCtx [ 0 ] ;
150+ }
151+ }
152+ }
153+ callback ( error ) ;
154+ } ) ;
155+ } ) ;
156+ } ;
157+
120158Itunes . prototype . getApps = function ( callback ) {
121159 var url = 'https://analytics.itunes.apple.com/analytics/api/v1/app-info/app' ;
122160 this . getAPIURL ( url , callback ) ;
@@ -127,6 +165,11 @@ Itunes.prototype.getSettings = function(callback) {
127165 this . getAPIURL ( url , callback ) ;
128166} ;
129167
168+ Itunes . prototype . getUserInfo = function ( callback ) {
169+ var url = 'https://analytics.itunes.apple.com/analytics/api/v1/settings/user-info' ;
170+ this . getAPIURL ( url , callback ) ;
171+ } ;
172+
130173Itunes . prototype . request = function ( query , callback ) {
131174 this . _queue . push ( {
132175 query : query ,
0 commit comments