Mostly empty Audioscrobbler controller to communicate with the Audioscrobbler servers.
authorKent Sutherland <ksuther@ithinksw.com>
Wed, 2 Nov 2005 04:59:27 +0000 (04:59 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Wed, 2 Nov 2005 04:59:27 +0000 (04:59 +0000)
AudioscrobblerController.h [new file with mode: 0644]
AudioscrobblerController.m [new file with mode: 0644]

diff --git a/AudioscrobblerController.h b/AudioscrobblerController.h
new file mode 100644 (file)
index 0000000..6b62360
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ *     MenuTunes
+ *  AudioscrobblerController
+ *    Audioscrobbler Support Class
+ *
+ *  Original Author : Kent Sutherland <kent.sutherland@ithinksw.com>
+ *   Responsibility : Kent Sutherland <kent.sutherland@ithinksw.com>
+ *
+ *  Copyright (c) 2005 iThink Software.
+ *  All Rights Reserved
+ *
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@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 (file)
index 0000000..695c684
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ *     MenuTunes
+ *  AudioscrobblerController
+ *    Audioscrobbler Support Class
+ *
+ *  Original Author : Kent Sutherland <kent.sutherland@ithinksw.com>
+ *   Responsibility : Kent Sutherland <kent.sutherland@ithinksw.com>
+ *
+ *  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