Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Apps de consumo de APIs de Internet para mobile phones

1,252 views

Published on

Web Apps é um modo fácil e rápido de se construir aplicações para Série 40, entretanto existe o desafio de fazer uma App consumir APIs de Internet. Este webinar tem como objetivo mostrar métodos e boas práticas de consumo de APIs de Internet para a Web Apps Série 40.

Published in: Technology, Business

Apps de consumo de APIs de Internet para mobile phones

  1. 1. ECOSYSTEM1
  2. 2. Interação Nokia Developer http://www.developer.nokia.com Twitter: @nokiadev_brasil Grupo Devs S40 no Nokia Developer http://www.developer.nokia.com/Co mmunity/Discussion/group.php?grou pid=1142
  3. 3. Apps de consumo deAPIs de Internet paramobile phonesRaymundo JuniorDesenvolvedor – INdTEvangelista Nokia de Tecnologia3
  4. 4. Conteúdo• Device S40• Estrutura do Projeto• Main• Template• Lib• Service• JSON Viewer• View1• View2• View3• Estudo de Caso 4
  5. 5. Device S40Nokia Developer• http://www.developer.nokia.com/Devices/Device_sp ecifications/?filter1=s405
  6. 6. Estrutura do Projeto6
  7. 7. Mainvar main = {init : function(){view1.init();}};7
  8. 8. Templatevar template = {item_view1 : <div class="item-view1"onclick="mwl.switchClass(#content,view*,view2);view2.init({ID});">{TEXT}</div>,item_view2 : <divonclick="mwl.switchClass(#content,view*,view3);view3.init({ID});">{TEXT}</div>,item_view3 : <div>{TEXT}</div>};8
  9. 9. Libvar lib = {call: function(url, successCallback, errorCallback){var request = new XMLHttpRequest();try {request.open("GET", url, true);request.onreadystatechange = function(){if (request.readyState == 4) {if (request.status == 200) {successCallback(eval(( + request.responseText + )));} else {errorCallback("error status: " + request.status);}}};request.send(null);} catch (e) {errorCallback("error try: " + e);}}}; 9
  10. 10. Servicevar BASE_URL = http://justkaws.com/json/;10
  11. 11. Servicevar URLS = {plataformas : index.php?opcao=plataformas,devices : index.php?opcao=devices&id={ID},device : index.php?opcao=device&id={ID}};11
  12. 12. ServicegetView2 : function(id, success, error) {var url = service.getUrl(devices).replace("{ID}",id);lib.call(url, success, error);},getView3 : function(id, success, error) {var url = service.getUrl(device).replace("{ID}", id);lib.call(url, success, error);}12
  13. 13. Servicevar BASE_URL = http://justkaws.com/json/;var URLS = {plataformas : index.php?opcao=plataformas,devices : index.php?opcao=devices&id={ID},device : index.php?opcao=device&id={ID}};var service = { getUrl: function(id) { return BASE_URL + URLS[id]; }, getView1 : function(success, error) { var url = service.getUrl(plataformas); lib.call(url, success, error);},getView2 : function(id, success, error) {var url = service.getUrl(devices).replace("{ID}", id);lib.call(url, success, error);},getView3 : function(id, success, error) {var url = service.getUrl(device).replace("{ID}", id);lib.call(url, success, error);}}; 13
  14. 14. JSON Viewer LINK: http://jsonviewer.stack.hu/14
  15. 15. JSON Viewer LINK: http://jsonviewer.stack.hu/15
  16. 16. View1init : function(){document.getElementById(title-view1).innerHTML ="Plataformas NOKIA";service.getView1(function(data){view1.render(data);},function(data){document.getElementById(view-content1).innerHTML =data;});},16
  17. 17. View1render : function(data){var dados = data.json;var limit = dados.length; var itemTemplate = template.item_view1; var itens = "";for (var x = 0; x< limit; x++){var params = dados[x].platform + [!{#?#?#}!] + dados[x].id;itens += itemTemplate.replace("{TEXT}",dados[x].platform).replace("{ID}", params);}document.getElementById(view-content1).innerHTML = itens;}17
  18. 18. View1var view1 = {init : function(){document.getElementById(title-view1).innerHTML = "Plataformas NOKIA";service.getView1(function(data){view1.render(data);},function(data){document.getElementById(view-content1).innerHTML = data;});},render : function(data){var dados = data.json;var limit = dados.length; var itemTemplate = template.item_view1; var itens = "";for (var x = 0; x< limit; x++){var params = dados[x].platform + [!{#?#?#}!] + dados[x].id;itens += itemTemplate.replace("{TEXT}", dados[x].platform).replace("{ID}", params);}document.getElementById(view-content1).innerHTML = itens;}}; 18
  19. 19. View2init : function(args){var vetor = args.split([!{#?#?#}!]);document.getElementById(title-view2).innerHTML = vetor[0];service.getView2( vetor[1],function(data){view2.render(data);},function(data){document.getElementById(view-content2).innerHTML = data;});}, 19
  20. 20. View2render : function(data){var dados = data.json;var limit = dados.length;var itemTemplate = template.item_view2;var itens = "";for (var x = 0; x< limit; x++){var params = dados[x].name + [!{#?#?#}!] + dados[x].id;itens += itemTemplate.replace("{TEXT}",dados[x].name).replace("{ID}", params);}document.getElementById(view-content2).innerHTML = itens;}20
  21. 21. View2var view2 = {init : function(args){var vetor = args.split([!{#?#?#}!]);document.getElementById(title-view2).innerHTML = vetor[0];service.getView2( vetor[1],function(data){view2.render(data);},function(data){document.getElementById(view-content2).innerHTML = data;});},render : function(data){var dados = data.json;var limit = dados.length;var itemTemplate = template.item_view2;var itens = "";for (var x = 0; x< limit; x++){var params = dados[x].name + [!{#?#?#}!] + dados[x].id;itens += itemTemplate.replace("{TEXT}", dados[x].name).replace("{ID}", params);}document.getElementById(view-content2).innerHTML = itens;}}; 21
  22. 22. View3init : function(args){var vetor = args.split([!{#?#?#}!]);document.getElementById(title-view3).innerHTML = vetor[0];service.getView3( vetor[1],function(data){view3.render(data);},function(data){document.getElementById(view-content3).innerHTML = data;});}, 22
  23. 23. View3render : function(data){var dados = data.json;var limit = dados.length;var itemTemplate = template.item_view3;var itens = "";for (var x = 0; x< limit; x++){itens += itemTemplate.replace("{TEXT}", dados[x].label + ": "+ dados[x].value);}document.getElementById(view-content3).innerHTML =itens;}23
  24. 24. View3var view3 = {init : function(args){var vetor = args.split([!{#?#?#}!]);document.getElementById(title-view3).innerHTML = vetor[0];service.getView3( vetor[1],function(data){view3.render(data);},function(data){document.getElementById(view-content3).innerHTML = data;});},render : function(data){var dados = data.json;var limit = dados.length;var itemTemplate = template.item_view3;var itens = "";for (var x = 0; x< limit; x++){itens += itemTemplate.replace("{TEXT}", dados[x].label + ": " + dados[x].value);}document.getElementById(view-content3).innerHTML = itens;}}; 24
  25. 25. Estudo de Caso25
  26. 26. Obrigado!Raymundo JuniorDesenvolvedor – INdTEvangelista de TecnologiaE-mail: raymundo.ferreira-junior@indt.org.brTwitter: twitter.com/justkawsSite: justkaws.comBlog: blog.justkaws.com26

×