Penggunaan REST API Tandif untuk Filtering pada Adobe AIR (Android version)
1 komentar Published Senin, 13 Februari 2012 by TB Saepul Anwar in AIR, Android, flexPada beberapa hari yang lalu penulis mendapat undangan dari tandif.com untuk mencoba API yang mereka buat. Awalnya saya hanya mencoba secara sederhana, yakni dengan melalui browser saja, dengan memasukkan alamat API –nya pada URL address browser dikarenakan sangat sederhananya format API yang digunakan, doc-nya ada di sini.
Format-nya sebagi berikut :
http://green.tandif.com/api/v1/text/check?api_key=your_api_key_here&text=your_text_here
Jika kalian belum mengetahui tandif, dari website tandif, saya bisa ambil kesimpulan, bahwa tandif berfokus pada layanan filtering untuk content yang berbau pornografi. Ok, langsung saja ya. di sini saya buat aplikasi kecil yang bisa dijadikan aplikasi android pada pemrograman Adobe AIR. so cek aja code-nya di bawah ini1 <?xml version="1.0" encoding="utf-8"?>
2 <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
3 xmlns:s="library://ns.adobe.com/flex/spark"
4 creationComplete="view1_creationCompleteHandler(event)" title="Filter">
5 <fx:Declarations>
6 <!-- Place non-visual elements (e.g., services, value objects) here -->
7 </fx:Declarations>
8 <s:TextInput id="TextInput_URL" x="10" y="30" width="178" height="37" text=""/>
9 <s:Label x="10" y="10" text="URL"/>
10 <s:TextArea id="TextArea_Content" x="9" y="75" width="279" height="130"
11 text="fuck my ass and my dick"/>
12 <s:Button x="200" y="27" width="88" height="41" label="Ektract"
13 click="button2_clickHandler(event)"/>
14 <s:Label x="10" y="263" text="Result"/>
15 <s:TextArea id="TextArea_Result" x="10" y="286" height="116"/>
16 <s:Button x="201" y="213" width="88" height="41" label="Filter"
17 click="button1_clickHandler(event)"/>
18
19 <fx:Script>
20 <![CDATA[
21 import com.adobe.utils.StringUtil;
22
23 import mx.events.FlexEvent;
24 import mx.rpc.events.ResultEvent;
25 import mx.rpc.http.HTTPService;
26
27 private static const API_KEY_TANDIF:String = "YOUR_API_KEY_HERE";
28 private static const API_KEY_ALCHEMY:String = "YOUR_API_KEY_HERE";
29 private static const INCREMENT:int = 1000;
30
31 private var _httpService_Filter:HTTPService = new HTTPService();
32 private var _httpService_Ektract:HTTPService = new HTTPService();
33 private var _dataArrayStrings:Array = [];
34
35 private var _last:int = 0;
36 private var _index:int = 1;
37
38 private function do_filter():void{
39
40 _index = 1;
41 _dataArrayStrings = [];
42
43 var str:String = TextArea_Content.text;
44
45 // Proses Menyimpan String ke dalam Array, supaya bisa dipecah menjadi String yang lebih pendek.
46 if(str.length>INCREMENT){
47
48 var count:int = Math.floor(str.length/INCREMENT);
49
50 for (var i:int=0; i<count; i++){
51
52 var s1:String = "";
53
54 if(i == count){
55 s1 = str.substr(i*INCREMENT, str.length);
56 }else{
57 s1 = str.substr(i*INCREMENT, INCREMENT*(i+1));
58 }
59
60 _dataArrayStrings.push(s1);
61 }
62 }
63 if(_dataArrayStrings.length>0){
64
65 _httpService_Filter.url = "http://green.tandif.com/api/v1/text/check?api_key="+API_KEY_TANDIF+"&text="+_dataArrayStrings[0];
66 _dataArrayStrings.shift();
67 }else{
68 _httpService_Filter.url = "http://green.tandif.com/api/v1/text/check?api_key="+API_KEY_TANDIF+"&text="+TextArea_Content.text;
69 }
70 _httpService_Filter.send();
71 }
72
73 private function do_ektract():void {
74 _httpService_Ektract.url = "http://access.alchemyapi.com/calls/url/URLGetRawText?apikey="+API_KEY_ALCHEMY+"&url="+TextInput_URL.text+"&outputMode=json";
75 _httpService_Ektract.send();
76
77 }
78
79 protected function view1_creationCompleteHandler(event:FlexEvent):void
80 {
81 _httpService_Filter.addEventListener(ResultEvent.RESULT, onResult_Filtering, false, 0, true);
82 _httpService_Filter.resultFormat = HTTPService.RESULT_FORMAT_TEXT;
83 _httpService_Filter.showBusyCursor = true;
84
85 _httpService_Ektract.addEventListener(ResultEvent.RESULT, onResult_Ekstract, false, 0, true);
86 _httpService_Ektract.resultFormat = HTTPService.RESULT_FORMAT_TEXT;
87 _httpService_Ektract.showBusyCursor = true;
88
89 }
90
91 private function onResult_Filtering(e:ResultEvent):void{
92
93 try{
94 var data:Object = JSON.parse(e.result as String);
95 TextArea_Result.text += "String "+_last+" - "+(INCREMENT*_index) +" : "+(data.result as String)+"\n";
96 }catch(e:Error){
97
98 TextArea_Result.text += "No Result \n";
99 }
100
101 if(_dataArrayStrings.length > 0){
102
103 _httpService_Filter.url = "http://green.tandif.com/api/v1/text/check?api_key="+API_KEY_TANDIF+"&text="+_dataArrayStrings[0];
104 _httpService_Filter.send();
105 _dataArrayStrings.shift();
106
107 _last = (INCREMENT*_index);
108 _index++;
109
110 }
111 }
112
113 private function onResult_Ekstract(e:ResultEvent):void{
114
115 var data:Object = JSON.parse(e.result as String);
116 var str:String = data.text;
117
118 str = str.replace(/[^a-zA-Z0-9]/g, ' ');
119 str = str.replace(/\n/g, '');
120 str = StringUtil.trim(str);
121 TextArea_Content.text = str;
122
123 }
124
125 private function htmlUnescape(str:String):String
126 {
127 return new XMLDocument(str).firstChild.nodeValue;
128 }
129
130 protected function button1_clickHandler(event:MouseEvent):void
131 {
132 do_filter();
133 }
134
135 protected function button2_clickHandler(event:MouseEvent):void
136 {
137 do_ektract();
138 }
139
140 ]]>
141 </fx:Script>
142 </s:View>
I’m Speaker Adobe Flash Camp 2011 Indonesia
2 komentar Published Senin, 17 Januari 2011 by TB Saepul Anwar in AIR, Android, my Activities, Playbook
Besok saya akan mempresentasikan “Development Playbook Application with Adobe AIR 2.5 and QNX SDK”, slide udah dibuat aplikasi demo udah ready, mudah-mudah berjalan dengan lancar dan fun, sedikit bocoran, saya akan menampilkan aplikasi playbook dan android yang saya buat dalam 2 minggu bersama tim saya. Aplikasi tersebut memiliki content movie, wheather, television, sport, event, restaurant, dan jual-beli
“See You Tommorow guys!”
Here the detail schedule Flash Camp 2011
Time | Agenda |
07:30 - 08:00 | Registration |
08:00 - 08:15 | Opening |
08:16 - 09:15 | Bridging Adobe Flex, Adobe Air to Java Web Application with Adobe BlazeDS by Nova Saputra, Java Developer |
09:16 - 10:15 | Developer and Designer Workflow by Ahmad Fathi Hadi and Nata Chen, RIA Developer, Game/Creative Producer |
10:16 - 11:15 | Behind the scenes of MAX Racer and building realtime multiplayer experiences by Tom Krcha, Adobe Evangelist |
11:16 - 12:15 | Creating mashup apps using various social media API's and AS3 by Arie M. Prasetyo, Flex & Web Developer |
12:16 - 13:15 | Break |
13:16 - 14:15 | Virtual World with AS3isolib by Anggie Bratadinata, Flash Engineer |
14:16 - 15:15 | Development Playbook Application with Adobe AIR 2.5 and QNX SDK by Tubagus S. Anwar, Flex/AIR Developer |
12:16 - 13:15 | Break |
15:46 - 16:45 | Augmented Reality by Rizal Akbar, Flash Developer |
16:46 - 17:15 | Adobe User Group Indonesia by Ahmad Fathi Hadi |
17:16 - 18:00 | DoorPrize |
***
My Profil

- TB Saepul Anwar
- I'm Flex and AIR Fan's also Entrepreneur, I like Flex and AIR because i like make code with MXML and AS 3.0 and enjoy the Flash Output. My backgroud is Multimedia, I Like design, Video, 3D, and animation.
Arsip Blog
Label
- AIR (18)
- Android (2)
- BlazeDS (1)
- flex (20)
- my Activities (4)
- php (1)
- Playbook (1)
- Project (1)
- Tutorial AIR (2)
- Tutorial Flex (2)