1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
dojo.provide("dojo.data.YahooStore");
|
|
|
12 |
dojo.require("dojo.data.core.RemoteStore");
|
|
|
13 |
dojo.require("dojo.lang.declare");
|
|
|
14 |
dojo.require("dojo.io.ScriptSrcIO");
|
|
|
15 |
dojo.declare("dojo.data.YahooStore", dojo.data.core.RemoteStore, {_setupQueryRequest:function (result, requestKw) {
|
|
|
16 |
var start = 1;
|
|
|
17 |
var count = 1;
|
|
|
18 |
if (result) {
|
|
|
19 |
start = result.start || start;
|
|
|
20 |
count = result.count || count;
|
|
|
21 |
}
|
|
|
22 |
var sourceUrl = "http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=dojo&language=en&query=" + result.query + "&start=" + start + "&results=" + count + "&output=json";
|
|
|
23 |
requestKw.url = sourceUrl;
|
|
|
24 |
requestKw.transport = "ScriptSrcTransport";
|
|
|
25 |
requestKw.mimetype = "text/json";
|
|
|
26 |
requestKw.jsonParamName = "callback";
|
|
|
27 |
}, _resultToQueryMetadata:function (json) {
|
|
|
28 |
return json.ResultSet;
|
|
|
29 |
}, _resultToQueryData:function (json) {
|
|
|
30 |
var data = {};
|
|
|
31 |
for (var i = 0; i < json.ResultSet.totalResultsReturned; ++i) {
|
|
|
32 |
var record = json.ResultSet.Result[i];
|
|
|
33 |
var item = {};
|
|
|
34 |
item["Url"] = [record.Url];
|
|
|
35 |
item["Title"] = [record.Title];
|
|
|
36 |
item["Summary"] = [record.Summary];
|
|
|
37 |
var arrayIndex = (json.ResultSet.firstResultPosition - 1) + i;
|
|
|
38 |
data[arrayIndex.toString()] = item;
|
|
|
39 |
}
|
|
|
40 |
return data;
|
|
|
41 |
}});
|
|
|
42 |
|