3 * AudioscrobblerController
4 * Audioscrobbler Support Class
6 * Original Author : Kent Sutherland <kent.sutherland@ithinksw.com>
7 * Responsibility : Kent Sutherland <kent.sutherland@ithinksw.com>
9 * Copyright (c) 2005 iThink Software.
14 #import "AudioscrobblerController.h"
16 static AudioscrobblerController *_sharedController = nil;
18 @implementation AudioscrobblerController
22 //[[AudioscrobblerController sharedController] attemptHandshake];
25 + (AudioscrobblerController *)sharedController
27 if (!_sharedController) {
28 _sharedController = [[AudioscrobblerController alloc] init];
30 return _sharedController;
35 if ( (self = [super init]) ) {
36 _handshakeCompleted = NO;
44 [_responseData release];
48 - (void)attemptHandshake
50 NSString *version = [[[NSBundle bundleWithPath:[[NSWorkspace sharedWorkspace] fullPathForApplication:@"iTunes.app"]] infoDictionary] objectForKey:@"CFBundleVersion"], *user = @"Tristrex";
51 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://post.audioscrobbler.com/?hs=true&p=1.1&c=est&v=\"%@\"&u=\"%@\"", version, user]];
52 NSURLConnection *connection;
54 _responseData = [[NSMutableData alloc] init];
55 connection = [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:url] delegate:self];
57 _handshakeCompleted = YES;
60 - (BOOL)handshakeCompleted
62 return _handshakeCompleted;
67 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
69 NSLog(@"Failed with an error: %@", error);
72 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
74 [_responseData appendData:data];
77 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
79 NSString *string = [[NSString alloc] initWithData:_responseData encoding:NSASCIIStringEncoding];
80 NSLog(@"Rawr: %@", string);