Page 1 of 2

JSONP support

Posted: December 11th, 2010, 8:33 pm
by dylanegan
I added JSONP support in with a simple patch;

Code: Select all

--- sabnzbd/interface.py	2010-11-15 12:54:48.000000000 -0800
+++ interface.py	2010-12-11 17:31:07.000000000 -0800
@@ -515,7 +515,10 @@
         if kwargs.get('mode', '') not in ('version', 'auth'):
             msg = check_apikey(kwargs)
             if msg: return msg
-        return self.api_handler(kwargs)
+        response = self.api_handler(kwargs)
+        if kwargs.get('output') == 'json' and kwargs.get('callback') is not None:
+          response = '%s(%s)' % (kwargs.get('callback'), response)
+        return response
 
 
     def api_handler(self, kwargs):
It would be great to have this available. Also I found an SVN repository that seems to be really old. Is there a newer repository available? I'd like to mirror it on GitHub.

Re: JSONP support

Posted: December 11th, 2010, 9:34 pm
by inpheaux
dylanegan wrote:Is there a newer repository available?
Development is done on launchpad now.

Re: JSONP support

Posted: December 12th, 2010, 7:04 am
by shypike
I should remove that old repository.
The only reason the Assembla site is still active is that it contains
a number of improvement requests that haven't been copied to Launchpad.

Re: JSONP support

Posted: December 20th, 2010, 3:37 pm
by dylanegan
Is there a way to get this in for the next release? Should I go through launchpad?

Re: JSONP support

Posted: December 20th, 2010, 5:20 pm
by shypike
I'll be happy to add it if I know what it's about.
Can you explain?

Re: JSONP support

Posted: December 20th, 2010, 6:20 pm
by dylanegan
http://en.wikipedia.org/wiki/JSON#JSONP - essentially it allows me to talk to the application directly from JS from another domain. Im writing a HTML/JS application to manage my local media center and want to talk to SABnzbd+ directly from my iPhone browser.

Re: JSONP support

Posted: December 27th, 2010, 7:53 am
by shypike
Added to the next test release of 0.6.0

Re: JSONP support

Posted: May 19th, 2011, 3:25 am
by vizzimo
Was this feature implemented in 0.6.0? I can't find it in the documentation. If so, how do I specify the callback function in the URL? IS it just http://****:8080/sabnzbd/api/?output=json&callback=[somecallbackfunction]?

Re: JSONP support

Posted: May 19th, 2011, 5:30 am
by shypike
Yes and yes.
I know the API docs suck.

Re: JSONP support

Posted: May 19th, 2011, 7:55 am
by vizzimo
Thanks  ;D

Re: JSONP support

Posted: June 1st, 2011, 9:58 am
by vizzimo
Did you guys implement this function in for all API calls? I can't get this to work with i.e. "error: API Key Incorrect".. It will return just normal JSON and not JSONP.

Re: JSONP support

Posted: June 1st, 2011, 10:04 am
by shypike
Do you supply a valid apikey?

Re: JSONP support

Posted: June 1st, 2011, 10:08 am
by vizzimo
shypike wrote: Do you supply a valid apikey?
No, i didn't.. That's the idea. I am writing an application in JavaScript and i have a function that checks for a valid api key. But all returns must be in JSONP. But when I give up an unvalid key, it just returns as a string (JSON) and not a callback function (JSONP), which means I can't do anything with the returned data.

PS: I get the same with the api call "http://host:port/sabnzbd/api?mode=auth".. So it seems that SabNZBd doesn't always return JSONP..

Re: JSONP support

Posted: June 1st, 2011, 1:17 pm
by shypike
In that case you'll have to wait for release 0.6.3 :)

Re: JSONP support

Posted: June 1st, 2011, 1:30 pm
by vizzimo
shypike wrote: In that case you'll have to wait for release 0.6.3 :)
Thank you for taking care of this, I really hope this will be fixed in the next release! Do you want me to make a list of api methods who do not work with JSONP, or isn't that necessary?