16974100 building applications with google apis

Upload: madhavnv1624

Post on 09-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 16974100 Building Applications With Google APIs

    1/34

    Building Applications

    withGoogle APIs

    Ray Cromwell

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    2/34

    Theres an API for that

    code.google.com shows 60+ APIs

    full spectrum (client, server, mobile, cloud) application oriented (android, opensocial)

    Does Google have a Platform?

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    3/34

    Application EcosystemClient

    Earth

    O3D

    Server

    Datastore

    JPA/JDO/Other

    REST/JSON, GWT,ProtocolBuffers

    App ServicesDocs

    BloggerSpreadsheets

    Base

    Media

    Social

    OpenSocialFriendConnectGData Contacts

    UtilityMaps/GeoTranslate

    GVizSearchAuth

    ... $$$AdSenseCheckout

    PHP Java

    Python Ruby

    MySQL

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    4/34

    Timefire

    Store and Index large # of time series data

    Scalable Charting Engine Social Collaboration

    Story Telling + Video/Audio sync

    Like Google Maps but for Time

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    5/34

    Android Version

    98% Shared Code with Web version

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    6/34

    Android

    Full API stack

    Tight integration with WebKit browser Local database, 2D and 3D APIs External XML UI/Layout system

    Makes separating presentation from logiceasier, benefits code sharing

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    7/34

    How was this done?

    Google Web Toolkit is the Foundation

    Target GWT JRE as LCD Use Guice Dependency Injection for

    platform-specific APIs

    Leverage GWT 1.6 event system

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    8/34

    ExampleApp Code

    JREDevice/Service

    interfaces

    Android

    Impl

    Browser

    Impl

    Guice

    AndroidSpecific

    GWTSpecific

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    9/34

    Shared Widget Eventsinterface HasClickHandler

    interface HasClickHandler

    addClickHandler(injectedHandler)

    addClickHandler(injectedHandler)

    Gin binds GwtHandlerImpl toinjectedHandler

    Guice binds AndroidHandlerImpl toinjectedHandler

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    10/34

    Guice

    Dependency Injection API like Spring

    Without the XML cruft! Very terse, method chaining syntax

    Compact, yet Powerful

    Works on Android, AppEngine, GWT

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    11/34

    Gin (Guice for GWT)

    Supports most of Guice API Leverages GWT compile-time Generators

    Lightweight and efficient

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    12/34

    Dependency Injectionpublic class Checkout {

    @Injectpublic Checkout(OrderProcessor proc) {this.processor=proc;

    }}

    vs

    this.processor = OrderProcessorFactory.create();

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    13/34

    List of APIs Used

    OpenSocial GWT Android

    Friend

    Connect Contacts Analytics

    Gadgets GViz Maps

    Spreadsheet YouTube Checkout

    Guice AppEngine Blogger

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    14/34

    Social

    I want to:

    Get Friends

    Send messages Post Activities

    OpenSocial/Google Friend Connect Google Data Contacts API

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    15/34

    Social ImplementationOption 1 - Android REST, GWT JS wrapper

    Option 2 - Android REST, GWT RPC REST

    Option 3 - Android,GWT -> Server REST

    JSNI calls to container APIs

    Fetch REST urls from client

    Fetch REST urls from client

    Fetch REST on Server via RPC

    Fetch REST on Server via RPC

    Fetch REST on Server via RPC

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    16/34

    Implementation Cont

    Introduce ShareProvider interface

    getContacts/sendMessage/logActivity Use Guice to inject one of the impls

    Option 3 requires only 1 impl.

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    17/34

    Portability Pattern

    Stick to GWT JRE classes if possible Hide platform details behind interfaces

    Use Guice to inject on Android and GWT

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    18/34

    Client Server

    Communication

    REST with JSON or XML ProtocolBuffers

    GWT RPC

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    19/34

    REST

    Serialize/Deserialize to JSON or XML

    Pros: Portable to any client Efficient for Browser Cons: Hard to tell if someone changes

    something

    May be less efficient for mobile, android

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    20/34

    ProtocolBuffers

    Used internally by all Google Services

    Compact and Fast Composeable

    Forward-compatible messaging

    No polymorphism

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    21/34

    GWT RPC

    Easy to use with GWT

    Reasonable performance Works with Java type system

    But what of other clients, like Android

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    22/34

    GWT RPC on Android

    with Guice/Gin Inject implementation of RPC interface

    Use java.lang.reflect.Proxy to dynamicallyimplement methods Use SerializationStreamWriter to encode

    method invocation with parameters

    Use HttpClient to perform network I/O

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    23/34

    User Management

    Needs:

    Manage profile

    Authenticate Authorize

    Google Accounts API on AppEngine OpenID Relying Party/oAuth

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    24/34

    Data Management

    Traditional: RDBMS

    AppEngine (BigTable)

    Document-Oriented (Spreadsheet) GData APIs

    JDO/DataNucleus can address all three. What of client storage on Android/HTML5?

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    25/34

    Gadgets

    Deployable bite sized applications

    Runs on

    portals like iGoogle OpenSocial containers (MySpace, etc)

    Google Friend Connect sites In Maps, Calendar, and Spreadsheets

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    26/34

    Visualization

    High level API to number of Google charts

    Javascript and GWT APIs available Third parties can submit new extensions/

    visualizations.

    Third parties can also add new datasources.

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    27/34

    Multimedia

    Picasa GData API Youtube GData API

    Youtube Chromeless Player

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    28/34

    Google Checkout

    Checkout API

    Merchant Calc API Notification API

    Order Processing API

    Subscription API

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    29/34

    Checkout Flow

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    30/34

    Checkout IntegrationCheckout

    XML SchemasJAXBXJC

    JavaPOJOs Merchant LogicAppEngine

    Checkout

    Serialized XMLCheckoutRequest

    Notifications

    Authentication/AuthorizationShopping Cart

    Charging

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    31/34

    Small Caveat

    JAXB isnt whitelisted in AppEngine

    Move it to a private package (com.foo) Use JARJAR or IDE refactoring One other 1-line patch needed

    Contact me later if you want a workingversion

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    32/34

    Theres more

    60+ APIs documented on code.google.com

    Many more semi-official APIs incode.google.com/p

    Soft-launched APIs in Labs

    Related APIs provided by projects likeApache Shindig, Chromium, OpenSocialFoundation, Open Web groups.

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    33/34

    Theres an API for that

    Google provides services for almost allparts of the application stack

    Often based on open specs, librariesreleased as open source

    Vendor-Lockin can be avoided in somecases (AppEngine JDO)

    One Stop Shopping

    Monday, June 1, 2009

  • 8/8/2019 16974100 Building Applications With Google APIs

    34/34

    Q&A