package sample;

import java.util.ArrayList;
import java.util.Hashtable;

import com.google.gson.JsonElement;

import com.callr.Api;
import com.callr.exceptions.CallrException;

public class Quickstart {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void main(String[] args) {
		JsonElement		result 		= null;
		Hashtable		options 	= null;

		try {
//			options = new Hashtable();
//			options.put("proxy", "http://foo:bar@example.com:8080");

			Api tc = new Api("login", "password", options);

			Hashtable<String, Object> param = new Hashtable<String, Object>();
			param.put("flash_message", false);

//			1. "call" method: each parameter of the method as an argument
			result = tc.call("sms.send", "SMS", "+33123456789", "Hello, world", param);

//			"sms.send" API method return a string so it need to be converted.
			System.out.println(result.getAsString());

//			For more complex object you need to convert each object
//			https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/JsonElement.html
//			Example
//			{
//			 	"array": ["value", "other"]
//			}
//			To get index 0 of "array" you should do:
//			System.out.println(result.getAsJsonObject().get("array").getAsJsonArray().get(0).getAsString());

//			2. "send" method: parameter of the method is an array
			ArrayList array = new ArrayList();
			array.add("SMS");
			array.add("+33123456789");
			array.add("Hello, world");
			array.add(param);

			result = tc.send("sms.send", array);

			System.out.println(result.getAsString());
			
		} catch (CallrException e) {
			System.out.println(e.getMessage());
			System.out.println(e.data);
		}
	}
}

@@ -134,16 +134,42 @@
 r.Api;%0D%0A
+import com.callr.auth.*;%0D%0A
 import c
@@ -521,16 +521,38 @@
 new Api(
+new LoginPasswordAuth(
 %22login%22,
@@ -562,16 +562,17 @@
 assword%22
+)
 , option
@@ -1639,19 +1639,16 @@
 ng());%0D%0A
-%09%09%09
 %0D%0A%09%09%7D ca

update sample to new auth mechanism