package org.obudget.client;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.http.client.UrlBuilder;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.jsonp.client.JsonpRequestBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

class BudgetAPICaller extends JsonpRequestBuilder {
	private UrlBuilder url;

	public BudgetAPICaller() {
		url = new UrlBuilder();
//		url.setHost("budget.yeda.us");
//		url.setPort(80);
		url.setHost("127.0.0.1");
		url.setPort(12345);
		url.setPath("00");
	}
	
	public void setCode( String code ) {
		url.setPath(code);
	}

	public void setParameter( String key, String value ) {
		url.setParameter(key, value);
	}
	
	public void go( final BudgetAPICallback callback ) {
		requestObject(url.buildString(), new AsyncCallback<JavaScriptObject>() {
			@Override
			public void onSuccess(JavaScriptObject result) {
				JSONArray array = new JSONArray(result);
				callback.onSuccess(array);
			}

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Failed to access API: "+caught.getMessage());
			}
			
		});		
	}
}

@@ -449,18 +449,16 @@
 lder();%0A
-//
 %09%09url.se
@@ -467,29 +467,36 @@
 ost(
-%22budget.yeda.us%22
+Window.Location.getHost()
 );%0A
-//
 %09%09ur
@@ -509,60 +509,53 @@
 ort(
-80);%0A%09%09url.setHost(%22127.0.0.1%22);%0A%09%09url.s
+Integer.parseInt( Window.Location.g
 etPort(
-12345
+) )
 );%0A%09

fix bug with api caller