-
Notifications
You must be signed in to change notification settings - Fork 2
/
OAuthRESTTest.mxml
59 lines (48 loc) · 1.91 KB
/
OAuthRESTTest.mxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.force.http.rest.RESTConnection;
import com.force.oauth.OAuthConnection;
import com.force.utility.util;
import mx.collections.ArrayCollection;
import mx.rpc.AsyncResponder;
import mx.utils.ObjectUtil;
private var rest:RESTConnection;
private function init():void {
if(this.stage != null) {
login();
}
}
private function login():void {
trace("Login");
rest = new RESTConnection();
rest.oauthConnection = new OAuthConnection("","","https://127.0.0.1/");
rest.oauthConnection.login(this.stage,new mx.rpc.AsyncResponder(loginHandler,com.force.utility.util.genericError));
}
private function loginHandler(loginResult:Object, token:Object):void {
rest.oauth = loginResult;
rest.query("SELECT ID, Name from Contact LIMIT 5",new mx.rpc.AsyncResponder(queryHandler,com.force.utility.util.genericError));
}
private function queryHandler(queryResult:Array, token:Object):void {
resultGrid.dataProvider = new ArrayCollection(queryResult);
}
]]>
</fx:Script>
<s:Button x="10" y="10" label="Login" creationComplete="init()" click="login()"/>
<s:DataGrid x="30" y="68" width="584" height="253" requestedRowCount="4" id="resultGrid">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="Name" headerText="Name" width="350"></s:GridColumn>
<s:GridColumn dataField="Email" headerText="Email" ></s:GridColumn>
<s:GridColumn dataField="Phone" headerText="Phone" ></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:WindowedApplication>