package com.example.kisibox;

import com.manavo.rest.RestApi;
import android.app.Activity;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.util.Log;


public class KisiApi extends RestApi {

	public KisiApi(Activity activity) {
		super(activity);
		
		SharedPreferences settings = getSharedPreferences("Config", MODE_PRIVATE);
		String authToken = settings.getString("authToken", "");

		this.BASE_URL = "https://kisi.de/";
		this.urlSuffix = ".json" + ( !authToken.isEmpty() ? "?auth_token=" + authToken : "" );
		this.rest.setHost("kisi.de");
		//this.rest.setPort(80);
		this.setUserAgent("AKey");

		this.acceptAllSslCertificates();
	}

	// return class instance so we can chain calls
	public KisiApi authorize(String email, String token) {
		// email acts as the username and token as the password of the basic auth
		this.rest.authorize(email, token);
		return this;
	}
	
	@Override // to make method public
	public void get(String url) {
		super.get(url);
	}
	
	@Override 
	public void post(String url) {
		super.post(url);
	}
}

@@ -495,9 +495,16 @@
 + ( 
-!
+KisiApi.
 auth
@@ -512,18 +512,16 @@
 oken
-.isEmpty()
+ != null
  ? %22
@@ -536,16 +536,24 @@
 ken=%22 + 
+KisiApi.
 authToke
@@ -690,12 +690,89 @@
 ();%0A
+%09public static void setAuthToken(String token) %7B%0A%09%09KisiApi.authToken = token;%0A
 %09%7D%0A
-%0A
 %09// 
@@ -866,127 +866,213 @@
 ing 
-token) %7B%0A%09%09// email acts as the username and token as the password of the basic auth%0A%09%09this.rest.authorize(email, token
+password) %7B%0A%09%09//addParameter(%22user%22, JSONObject(%22%7B%5C%22email%5C%22:%5C%22%22 + email + %22%5C%22,%5C%22password%5C%22:%5C%22%22 + password + %22%5C%22%7D%22));%0A%09%09addParameter(%22user%22, %22%7B%5C%22email%5C%22:%5C%22%22 + email + %22%5C%22,%5C%22password%5C%22:%5C%22%22 + password + %22%5C%22%7D%22
 );%0A%09

use static variable for auth token