#import <Foundation/Foundation.h>

//  Created by Juan Leon, NotOptimal.net, Feb 08.
//  Free to use, as long as the credit line above is included in the source.
//
//#define GOOGLE_CLIENT_AUTH_URL @"https://www.google.com/accounts/ClientLogin"
#define GOOGLE_CAPTCHA_STANDARD_UNLOCK_URL @"https://www.google.com/accounts/DisplayUnlockCaptcha"

#define GOOGLE_CLIENT_AUTH_URL @"http://localhost/~fedor/all.cgi/Hi%23There%40You@AreCool"

#ifndef TRUE
#define TRUE YES
#define FALSE NO
#endif

NSString *pluginVersion = @"GNUstepLoginTest1";

@interface GDataLoginTestAppDelegate : NSObject 
{
}

- (void) sendMessage: sender;

@end

@implementation GDataLoginTestAppDelegate

- (void) sendMessage: sender
{
//define our return objects
  //begin NSURLConnection prep:
  NSMutableURLRequest *httpReq = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:GOOGLE_CLIENT_AUTH_URL] ];
  [httpReq setTimeoutInterval:10.0];
  NSHTTPURLResponse *response = nil;
  NSError *error = nil;
  NSData *data = nil;
  NSString *responseStr = nil;
  //this should be quick, and to keep same workflow, we'll do this sync.
  //this should also get us by without messing with threads and run loops on Tiger.
  data = [NSURLConnection sendSynchronousRequest:httpReq returningResponse:&response error:&error];
  
  if ([data length] > 0) {
    responseStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    NSLog(@"Response : %@", responseStr);
  }
  else {
    NSLog(@"Error %@", error);
  }
}

@end

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  GDataLoginTestAppDelegate *object;

  object = [[GDataLoginTestAppDelegate alloc] init];
  [object sendMessage: nil];

  [pool drain];
    return 0;
}
