package com.lukekorth.httpebble.receivers;

import static com.getpebble.android.kit.Constants.MSG_DATA;
import static com.getpebble.android.kit.Constants.TRANSACTION_ID;

import org.json.JSONException;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;

import com.getpebble.android.kit.PebbleKit;
import com.getpebble.android.kit.util.PebbleDictionary;

public class PebbleDataReceiver extends IntentService {

	public PebbleDataReceiver() {
		super("PebbleDataReceiver");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		int transactionId = intent.getIntExtra(TRANSACTION_ID, -1);
		PebbleKit.sendAckToPebble(this, transactionId);
		
        String data = intent.getStringExtra(MSG_DATA);
        if (data != null && data.length() != 0) {
			PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
			WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
					"PebbleDataReceiver");
			wakeLock.acquire();

        	try {
                PebbleDictionary pebbleDictionary = PebbleDictionary.fromJson(data);

                //process data here            
            } catch (JSONException e) {
                // silently fail
            }

			wakeLock.release();
        }
	}

}

@@ -466,16 +466,58 @@
 tionary;
+%0Aimport com.lukekorth.httpebble.Constants;
 %0A%0Apublic
@@ -808,19 +808,11 @@
 d);%0A
+%0A
 %09%09
-%0A        
 Stri
@@ -854,24 +854,18 @@
 _DATA);%0A
-        
+%09%09
 if (data
@@ -1103,39 +1103,21 @@
 );%0A%0A
-        %09try %7B%0A                
+%09%09%09try %7B%0A%09%09%09%09
 Pebb
@@ -1186,68 +1186,913 @@
 );%0A%0A
-                //process data here            %0A            
+%09%09%09%09// http request%0A%09%09%09%09if (pebbleDictionary.getString(Constants.HTTP_URL_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09%09// timezone infomation%0A%09%09%09%09else if (pebbleDictionary%0A%09%09%09%09%09%09.getUnsignedInteger(Constants.HTTP_TIME_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09%09// location information%0A%09%09%09%09else if (pebbleDictionary%0A%09%09%09%09%09%09.getUnsignedInteger(Constants.HTTP_LOCATION_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09%09// setting entries in key-value store%0A%09%09%09%09else if (pebbleDictionary%0A%09%09%09%09%09%09.getInteger(Constants.HTTP_COOKIE_STORE_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09%09// removing entries from key-value store%0A%09%09%09%09else if (pebbleDictionary%0A%09%09%09%09%09%09.getInteger(Constants.HTTP_COOKIE_LOAD_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09%09// deleting entries from key-value store%0A%09%09%09%09else if (pebbleDictionary%0A%09%09%09%09%09%09.getInteger(Constants.HTTP_COOKIE_DELETE_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09%09// fsync%0A%09%09%09%09else if (pebbleDictionary%0A%09%09%09%09%09%09.getUnsignedInteger(Constants.HTTP_COOKIE_LOAD_KEY) != null) %7B%0A%0A%09%09%09%09%7D%0A%09%09%09
 %7D ca
@@ -2119,24 +2119,12 @@
 ) %7B%0A
-                
+%09%09%09%09
 // s
@@ -2140,20 +2140,11 @@
 ail%0A
-            
+%09%09%09
 %7D%0A%0A%09
@@ -2169,16 +2169,10 @@
 ();%0A
-        
+%09%09
 %7D%0A%09%7D

Add check for possible requests