Using Web Services in Your Gadget/Widget
-
Upload
goodfriday -
Category
Technology
-
view
2.266 -
download
1
description
Transcript of Using Web Services in Your Gadget/Widget
Using Web Services in your Gadget
Alan Lewis – eBay Technical Evangelist
NGW024
2 eBay Inc. confidential
Hi
3 eBay Inc. confidential
I lost my voice earlier this morning
4 eBay Inc. confidential
:-(
5 eBay Inc. confidential
I have some cool stuff to show you though
6 eBay Inc. confidential
:-)
7 eBay Inc. confidential
So, I’ll give it a try
8 eBay Inc. confidential
Here goes…
9 eBay Inc. confidential
Huh? What’s this presentation about???
• Web Services
– You may have heard of them
– Yes, they are actually useful
– No, you don’t have to use SOAP
– Lots of services are out there for you to use (finally)
• Gadgets
– Or Widgets
– Or Plugins
– Or Panels
– Definition: “mini-applications that let you perform common tasks and provide you with fast access to information”
– Translation: They do cool stuff
10 eBay Inc. confidential
Why Should I Care?
• Gadgets are cool
• Web services offer lots of reusable data and functionality
• MIXing them up (nice plug) in your gadget saves you headaches
• Alternative to doing it this way – server side coding
– Need to scale your server to handle traffic from gadget
– Different skill set required
– Eww!!!
11 eBay Inc. confidential
So, what sorts of web services are out there?
• I’m so glad you asked… here is a totally random example:
eBay Web Services!!!
• Please permit me a short detour to summarize
12 eBay Inc. confidential
eBay Web Service Features
• Search
• Listing Items
• Transaction/Order Management
• My eBay
• eBay Stores
• Feedback Management
• Watch List
• Bidding (with signed agreement)
• In short, almost everything you can do on the site
13 eBay Inc. confidential
Different Flavors of eBay Web Services
• SOAP
• XML (HTTP POST) – Both support the same feature set (all calls)
– Calls go over HTTPS
• REST (HTTP GET)– supports GetSearchResults call
14 eBay Inc. confidential
Sample Call Request
XML API:
<?xml version="1.0" encoding="utf-8"?>
<GetSearchResultsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>ABC123</eBayAuthToken>
</RequesterCredentials>
<Query>iPod Nano</Query>
</GetSearchResultsRequest>
REST API
http://rest.api.ebay.com/restapi?CallName=GetSearchResults&RequestToken=ABC123=&RequestUserId=alanlewis0&Query=iPod%20Nano&Schema=1
15 eBay Inc. confidential
Sample Call Response
XML API and REST API (same response)
<?xml version="1.0" encoding="utf-8"?>
<GetSearchResultsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
…
<Item>
<ItemID>4036874357</ItemID>
…
<SellingStatus>
<BidCount>31</BidCount>
<CurrentPrice currencyID="USD">80.0</CurrentPrice>
</SellingStatus>
<Site>US</Site>
<Title>Used Apple iPod Nano MP3 Player Good Condition</Title>
…
</Item>
…
</GetSearchResultsRequest>
16 eBay Inc. confidential
And Now…
Demo
17 eBay Inc. confidential
Live.com
• Supports RSS feeds and Gadgets
• Gadgets are implemented in javascript + CSS
• Still alpha feel – emerging feature set and very buggy at times (especially with CSS support)
18 eBay Inc. confidential
Design Philosophy
• Gadgets call for a fresh design approach
• Sort of like code for mobile devices– Limited screen real-estate
– Limited functionality/APIs
• Except not– Still coding for the browser– multiple windows/tabs, cross-browser issues
– Asynchronous interaction, more bandwidth
19 eBay Inc. confidential
Challenge 1: Security Restrictions
• Calls can’t go across domains– If the gadget was served up from www.mydomain.com, can’t call api.ebay.com
• Live.com solution to this: proxy!– Supports XML data (except XHTML) and RSS feeds
– Currently only supports HTTP GET (contrary to docs – support for POST will be added in the future)
– Can’t proxy HTTPS yet, so only option for eBay is REST API
var r = Web.Network.createRequest( Web.Network.Type.XML,
searchQuery,
{proxy:"generic"},
eBaySearchCallback);
20 eBay Inc. confidential
Challenge 2: Namespaces
• IE javascript engine can’t handle XML data in default namespaces
• Solution: Use ugly RegEx hack to remove namespace:
var rootText = response.responseText;
var re = /xmlns="urn:ebay:apis:eBLBaseComponents"/g;
rootText = rootText.replace(re, "");
var responseWithoutNamespaces;
if (window.ActiveXObject) {
responseWithoutNamespaces = new ActiveXObject("Microsoft.XMLDOM");
responseWithoutNamespaces.async="false";
responseWithoutNamespaces.loadXML(rootText);
}
else {
responseWithoutNamespaces = document.implementation.createDocument("","",null);
responseWithoutNamespaces.loadXML(rootText);
}
21 eBay Inc. confidential
And now…
• ANNOUNCING:
• The gadget is open sourced
• Commercial software-friendly open source license: CDDL
• Yeah!
• http://searchgadget.codebase.ebay.com
• Lets go check it out…
22 eBay Inc. confidential
Now More Code
• Here is the code, in-depth
23 eBay Inc. confidential
Other Web Services
• Lots to choose from: www.programmableweb.com
• REST is very popular, but has limitations
• RSS feeds are web services too
24 eBay Inc. confidential
Building Commercial Apps
• One issue to keep in mind is many Web services out there force non-commercial use
• Shameless plug: that’s not the case with eBay Web services
• One way to make money with your Gadget is to use an affiliate program like eBay’s:http://developer.ebay.com/affiliates
25 eBay Inc. confidential
Other Gadget/Widget Platforms
• Vista Sidebar
– Bundled with Vista, but limited capabilities (thusfar)
• Yahoo! Widget Engine (Konfabulator)
– Multi-platform support, integration with Desktop still clumsy
• Apple Dashboard
– Best desktop integration, but only for OSX
• Google Desktop – (Sidebar)
– Information-rich widgets, but harder to build, bundled with a product IT departments hate
• Google Personalized Home Page
– Sorta like live.com – less functionality but better visibility
26 eBay Inc. confidential
Learn More Stuff
• More on eBay Web Services: http://developer.ebay.comIts totally free!
• eBay Developers Conference, baby!June 10-12, Mandalay Bay, Las Vegas
• Live.com eBay Gadget available in the Gallery:microsoftgadgets.com
• Open sourced at: http://searchgadget.codebase.ebay.com
• Sanaz Ahari’s presentation immediately following this one, in C/D