Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This...

17
advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and Windows Live are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.

Transcript of Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This...

Page 1: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

cloud servicesaccess to everything over the web

Disclaimer: This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and Windows Live are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.

Page 2: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

what it iso “meta API”

• retrieve all information visible in touchdevelop app

• outlook: callbacks, plugins (meta apps)

o build on web standards• HTTP, REST, JSON

✿ touchdevelop.com/help/cloudservices

Page 3: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

architectureo front-ends

• TouchDevelop WP7 app talks with Azure Web Service

• (any) browser talks with Azure Web App

o Windows Identity Foundation• allows users to authenticate with Windows Live ID, Facebook

o Azure• web site talks with Azure Web Service

• web service controls Azure Storage

• storage (public data)

• storage (private data)

Page 4: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

AzureStorage (public)

AzureWeb

Service

AzureWeb Site

Windows Identity

Foundation

AzureStorage (private)

WP7 devices withTouchDevelop app

web browser

Page 5: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

HTTPo HyperText Transfer Protocol o the protocol used by the World Wide

Web

Page 6: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

HTTP exampleo Request Headers

• GET http://www.touchdevelop.com/api/ecvs HTTP/1.1 • Host: www.touchdevelop.com • Cache-Control: max-age=0 • Accept:

text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

• Accept-Encoding: gzip,deflate,sdch

o Response Headers• HTTP/1.1 200 OK • Content-Length: 451 • Expires: -1 Date: Fri, 10 Feb 2012 02:51:48 GMT • Content-Type: application/json; charset=utf-8 • Cache-Control: no-cache, no-store • Pragma: no-cache

Page 7: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

RESTo REST (Representational State Transfer) is a

lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP, WSDL, et al.).

o RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

Page 8: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

REST hereo Currently, only supported verb is ‘GET’o All accesses are stateless

Page 9: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

JSONo JSON (JavaScript Object Notation) is

a lightweight data-interchange format.

o two building blocks:• a collection of name/value pairs

(“object”, “record”, …)

• an ordered list of values (“array”, …)

Page 10: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

JSON grammarjson: string | number | boolean |

array | object

string/number/boolean follow grammar of corresponding JavaScript literals

array: “[“ [json (“,” comma)*] “]”field: string “:” jsonobject: “[“ field [(“,” field)*] “]”

example

[ “elem0”, 1, { “x” : “value of field x”, “y” : 42 }, false]

Page 11: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

JSON exampleo GET http://www.touchdevelop.com/api/ecvs HTTP/1.1

{ "kind":"script", "time":44139093, "id":"ezdf", "url":"http://touchdevelop.com/ezdf", "name":"Smart Rail Table", "description":"", "userid":"yvfc", "username":"Sascha M. B.", "icon":"directions", "iconbackground":"#008000", "iconurl":"https://az31353.vo.msecnd.net/c01/wbso.png", "positivereviews":0, "comments":0, …

Page 12: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

JSON example

… "capabilities":[ {"name":"sourcegeolocation","iconurl":"https://az31353.vo.msecnd.net/c01/qzgl.png"}, {"name":"sinkweb","iconurl":"https://az31353.vo.msecnd.net/c01/mopx.png"} ], "flows":[], "haserrors":false, "rootid":"dgig", "updateid":"ezdf", "ishidden":false, "islibrary":false, "installations":0, "runs":0}

Page 13: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

main listso /api/new-scriptso /api/top-scriptso /api/featured-scriptso /api/search?text=[text]o /api/userso /api/commentso /api/screenshotso /api/reviewso optional list parameters: ?

count=[number]&continuation=[token]

Page 14: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

publication propertieso /api/[id]o /api/[scriptid]/texto /api/[scriptid]/asto /api/[scriptid]/successorso /api/[scriptid]/baseo /api/[userid]/scriptso /api/[scriptid or userid or commentid]/commentso /api/[scriptid or userid]/screenshots o /api/[commentid or scriptid or userid]/reviews o /api/[userid]/picture

Page 15: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

apis: jsono Web→download json

Downloads a web service response as a JSON data structure

o Json Object→kindGets a json kind (string, number, boolean, object, array)

o string: Json Object→to stringo number: Json Object→to numbero boolean: Json Object→to booleano object: Json Object→keys, Json

Object→fieldo array: Json Object→at, Json Object→counto  

Page 16: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

exercise► in touchdevelop, write code that…• Posts the names of new scripts

• Posts links to the urls of new scripts

► in touchdevelop, write code that figures out…• of the (around) 100 new scripts,

which have at least one ♥ ?

☁ http://touchdevelop.com/axaw (solution)

Page 17: Advanced topics in touchdevelop cloud services access to everything over the web Disclaimer: This document is provided “as-is”. Information and views expressed.

advanced topics in touchdevelop

homework► in your favorite language, write code that figures out…• how many scripts are there?

• how many AST nodes does the biggest script have?

• which script got the most ♥ ?

• which user gave the most ♥ ?

• what is the longest script (number of lines)?

• which script got updated the most?