JSONP support

Want something added? Ask for it here.
dylanegan
Newbie
Newbie
Posts: 3
Joined: December 11th, 2010, 2:40 pm

JSONP support

Post 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.
User avatar
inpheaux
Administrator
Administrator
Posts: 562
Joined: January 16th, 2008, 9:14 pm

Re: JSONP support

Post by inpheaux »

dylanegan wrote:Is there a newer repository available?
Development is done on launchpad now.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: JSONP support

Post 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.
dylanegan
Newbie
Newbie
Posts: 3
Joined: December 11th, 2010, 2:40 pm

Re: JSONP support

Post by dylanegan »

Is there a way to get this in for the next release? Should I go through launchpad?
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: JSONP support

Post by shypike »

I'll be happy to add it if I know what it's about.
Can you explain?
dylanegan
Newbie
Newbie
Posts: 3
Joined: December 11th, 2010, 2:40 pm

Re: JSONP support

Post 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.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: JSONP support

Post by shypike »

Added to the next test release of 0.6.0
vizzimo
Newbie
Newbie
Posts: 5
Joined: May 19th, 2011, 3:21 am

Re: JSONP support

Post 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]?
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: JSONP support

Post by shypike »

Yes and yes.
I know the API docs suck.
vizzimo
Newbie
Newbie
Posts: 5
Joined: May 19th, 2011, 3:21 am

Re: JSONP support

Post by vizzimo »

Thanks  ;D
vizzimo
Newbie
Newbie
Posts: 5
Joined: May 19th, 2011, 3:21 am

Re: JSONP support

Post 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.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: JSONP support

Post by shypike »

Do you supply a valid apikey?
vizzimo
Newbie
Newbie
Posts: 5
Joined: May 19th, 2011, 3:21 am

Re: JSONP support

Post 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..
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: JSONP support

Post by shypike »

In that case you'll have to wait for release 0.6.3 :)
vizzimo
Newbie
Newbie
Posts: 5
Joined: May 19th, 2011, 3:21 am

Re: JSONP support

Post 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?
Post Reply