|
30 | 30 | import android.view.ViewGroup; |
31 | 31 | import android.widget.TextView; |
32 | 32 |
|
| 33 | +import net.servicestack.android.AndroidServiceClient; |
| 34 | +import net.servicestack.client.AsyncSuccess; |
| 35 | +import net.servicestack.client.Log; |
| 36 | + |
33 | 37 | public class MainActivity extends FragmentActivity implements ActionBar.TabListener { |
34 | 38 |
|
35 | 39 | /** |
@@ -175,6 +179,37 @@ public void onClick(View view) { |
175 | 179 | } |
176 | 180 | }); |
177 | 181 |
|
| 182 | + rootView.findViewById(R.id.btn_test_cookie) |
| 183 | + .setOnClickListener(new View.OnClickListener() { |
| 184 | + @Override |
| 185 | + public void onClick(View view) { |
| 186 | +// final AndroidServiceClient client = new AndroidServiceClient("http://validation.web-app.io", getContext()); |
| 187 | + final AndroidServiceClient client = new AndroidServiceClient("http://validation.web-app.io"); |
| 188 | + client.postAsync(new validationdtos.Authenticate() |
| 189 | + .setProvider("credentials") |
| 190 | + .setUserName("admin@email.com") |
| 191 | + .setPassword("p@55wOrd") |
| 192 | + , new AsyncSuccess<validationdtos.AuthenticateResponse>() { |
| 193 | + @Override |
| 194 | + public void success(validationdtos.AuthenticateResponse response) { |
| 195 | + try { |
| 196 | + client.setTokenCookie(response.getBearerToken()); |
| 197 | + } catch (Exception e) { |
| 198 | + Log.e(e); |
| 199 | + } |
| 200 | + client.getAsync(new validationdtos.GetContacts(), new AsyncSuccess<validationdtos.GetContactsResponse>() { |
| 201 | + @Override |
| 202 | + public void success(validationdtos.GetContactsResponse response) { |
| 203 | + for (validationdtos.Contact contact : response.results) { |
| 204 | + Log.d("CONTACT: " + contact.name); |
| 205 | + } |
| 206 | + } |
| 207 | + }); |
| 208 | + } |
| 209 | + }); |
| 210 | + } |
| 211 | + }); |
| 212 | + |
178 | 213 | return rootView; |
179 | 214 | } |
180 | 215 | } |
|
0 commit comments