From 97eb97cd6af1e3019980ed380a6cbaf1feae0abe Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Wed, 2 Nov 2005 04:59:27 +0000 Subject: [PATCH] Mostly empty Audioscrobbler controller to communicate with the Audioscrobbler servers. --- AudioscrobblerController.h | 25 ++++++++++++ AudioscrobblerController.m | 84 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 AudioscrobblerController.h create mode 100644 AudioscrobblerController.m diff --git a/AudioscrobblerController.h b/AudioscrobblerController.h new file mode 100644 index 0000000..6b62360 --- /dev/null +++ b/AudioscrobblerController.h @@ -0,0 +1,25 @@ +/* + * MenuTunes + * AudioscrobblerController + * Audioscrobbler Support Class + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * + * Copyright (c) 2005 iThink Software. + * All Rights Reserved + * + */ + +#import + +@interface AudioscrobblerController : NSObject { + BOOL _handshakeCompleted; + + NSMutableData *_responseData; +} ++ (AudioscrobblerController *)sharedController; + +- (void)attemptHandshake; +- (BOOL)handshakeCompleted; +@end diff --git a/AudioscrobblerController.m b/AudioscrobblerController.m new file mode 100644 index 0000000..695c684 --- /dev/null +++ b/AudioscrobblerController.m @@ -0,0 +1,84 @@ +/* + * MenuTunes + * AudioscrobblerController + * Audioscrobbler Support Class + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * + * Copyright (c) 2005 iThink Software. + * All Rights Reserved + * + */ + +#import "AudioscrobblerController.h" + +static AudioscrobblerController *_sharedController = nil; + +@implementation AudioscrobblerController + ++ (void)load +{ + //[[AudioscrobblerController sharedController] attemptHandshake]; +} + ++ (AudioscrobblerController *)sharedController +{ + if (!_sharedController) { + _sharedController = [[AudioscrobblerController alloc] init]; + } + return _sharedController; +} + +- (id)init +{ + if ( (self = [super init]) ) { + _handshakeCompleted = NO; + _responseData = nil; + } + return self; +} + +- (void)dealloc +{ + [_responseData release]; + [super dealloc]; +} + +- (void)attemptHandshake +{ + NSString *version = [[[NSBundle bundleWithPath:[[NSWorkspace sharedWorkspace] fullPathForApplication:@"iTunes.app"]] infoDictionary] objectForKey:@"CFBundleVersion"], *user = @"Tristrex"; + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://post.audioscrobbler.com/?hs=true&p=1.1&c=est&v=\"%@\"&u=\"%@\"", version, user]]; + NSURLConnection *connection; + + _responseData = [[NSMutableData alloc] init]; + connection = [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:url] delegate:self]; + + _handshakeCompleted = YES; +} + +- (BOOL)handshakeCompleted +{ + return _handshakeCompleted; +} + +#pragma mark - + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error +{ + NSLog(@"Failed with an error: %@", error); +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data +{ + [_responseData appendData:data]; +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection +{ + NSString *string = [[NSString alloc] initWithData:_responseData encoding:NSASCIIStringEncoding]; + NSLog(@"Rawr: %@", string); + [string release]; +} + +@end -- 2.20.1