I'm one of the developers for the dojotoolkit's rpc system and I
wanted to add digg in as one of the available endpoints and write a
little blog about how that was done. Dojo's rpc system already
provides access to services based on JsonRPC or JsonpServices with
simple description in the form of json, called SMD. I can and would
like to implement this quickly, but have a question and a feature
request and am wondering what the possibilities of either are :)
1) Can elements that are currently provided as part of the url also be
provided by a querystring parameter? For example, currenly to you
might do /errors/{code}?appkey=foobar.... I'm wondering if this is
also available as some thing like /errors?
code=1001&appkey=foobar.... .
2) In brief testing, the system is millimeters away from working with
the default config, meaning that only a definition (no code) would
even need to be written. The above issue would make that very easy,
but I might be able to work around it if that doesn't work or isn't
going to ever work. The other item however is currently a blocker as
it depends on other parts of the dojo system i'm not wanting to fiddle
with. The issue is simply that the callback function name passed to
the api is not accepted by the digg api and instead returns an
'alert('A Digg API request has an invalid callback argument.');' The
string passed as the callback parameter
'dojo.io.script.jsonp_dojoIoScript1._jsonpCallback'
This function is of course hooked up and managed in the background for
the dojo user so none of the complexity of jsonp style callbacks are
required and also to ensure there is no collision of function names
for callbacks. These functions are isolated to holder in the
providing packages namespace as appropriate, however the digg api
doesn't seem to like the fact that there are periods in the callback
function name, though they are neither inappropriate or invalid. I've
also verified that is not the underscores that it doesn't like. Would
it be possible to relax this restriction on the callback parameter?
Thanks,
Dustin
No. Currently the API only responds to requests in the fashion that is
documented here: http://apidoc.digg.com/. When attempting to use query
string parameters that aren't supported you should receive an
"Unrecognized argument" error.
> however the digg api
> doesn't seem to like the fact that there are periods in the callback
> function name, though they are neither inappropriate or invalid.
The Javascript response type decodes the JSON response and passes the
data to a Javascript callback function you specify in the callback
argument in the request. I believe the '.' character is not valid in a
Javascript function name, thus the restriction.
This is incorrect, the period certainly is valid. We will take a look
at relaxing the restriction.
-Kurt
True, the dots are not invalid. We restricted the callback arg to
just a simple identifier so that we wouldn't have to do any analysis
to prove there's no vulnerability in allowing operators like
dot. (Micah even suggested we allow square brackets, too, but I got
scared and ran away.)
>Would it be possible to relax this restriction on the callback parameter?
It's possible, but first let me ask you: Would it be onerous to
assign a reference to the function to a variable and then use that
variable as the callback?
The typical pattern for the type=javascript API call is:
<script>
function blee(jsonData) {
...
}
</script>
<script
src="http://services.digg.com/...?type=javascript&callback=blee..."></script>
In your case, you would calculate the function reference in the first
script tag.
<script>
blee = dojo.io.script.jsonp_dojoIoScript1._jsonpCallback;
</script>
I realize that's less elegant, and that may be enough of an argument,
but how much worse would it be? Or does it preclude the use of your
library altogether?
I'm not trying to talk you out of it. I'm sorta trying to talk
myself more completely into the need for dots.
At 01:53 PM 6/24/2008, Pat Diven II wrote:
>... it's crucial that the responses be handled in a certain order by
>unique functions.
>
>My solution ... a JavaScript array ...
I'm curious. How does the array ensure that the responses are
handled in a certain order? (Be gentle with me. I'm no Javascript expert.)
This sounds really interesting. Can you give a bit more complete
example? I'd like to see the Javascript code that sets up the array
in context with the API requests. Maybe you can point to an example
page that doesn't work because of the constraints on the callback value?
That discussion happened, and we've decided to allow member operators as well as regular identifiers.
Sorry this has taken so long. We've been busy with some bigger API
tasks, but I'll try to get this back on the front burner.
How are you planning to use it?