This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
BGLastFmSubmissionHandshaker.m
47 lines (37 loc) · 1.9 KB
/
BGLastFmSubmissionHandshaker.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// BGLastFmSubmissionHandshaker.m
// ApiHubTester
//
// Created by Ben Gummer on 17/07/08.
// Copyright 2008 Ben Gummer. All rights reserved.
//
#import "BGLastFmSubmissionHandshaker.h"
#import "CocoaCryptoHashing.h"
#import "HubStrings.h"
#import "HubNotifications.h"
@implementation BGLastFmSubmissionHandshaker
-(BGLastFmSubmissionHandshakeResponse *)performSubmissionHandshakeForUser:(NSString *)username withWebServiceSessionKey:(NSString *)wsSessionKey {
NSString *currentUnixTime = [NSString stringWithFormat:@"%d",(int)[[NSDate date] timeIntervalSince1970]];
NSString *authString = [[NSString stringWithFormat:@"%@%@",API_SECRET,currentUnixTime] md5HexHash];
NSString *handshakeUrlString = [NSString stringWithFormat:@"http://post.audioscrobbler.com/?hs=true&p=1.2.1&c=sld&v=0.52&u=%@&t=%@&a=%@&api_key=%@&sk=%@",username,currentUnixTime,authString,API_KEY,wsSessionKey];
NSURL *postURL = [NSURL URLWithString:handshakeUrlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:postURL];
[request setHTTPMethod:@"GET"];
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[request setTimeoutInterval:10.00];// timeout scrobble posting after 20 seconds
NSError *postingError;
NSHTTPURLResponse *response = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&postingError];
[request release];
BGLastFmSubmissionHandshakeResponse *responseObject;
if (responseData!=nil && [postingError code]!=-1001 && [response statusCode]==200) {
responseObject = [[BGLastFmSubmissionHandshakeResponse alloc] initWithData:responseData];
NSLog(@"SUB");
[[NSNotificationCenter defaultCenter] postNotificationName:APIHUB_WebServiceAuthorizationCompleted object:nil];
} else {
responseObject = [[BGLastFmSubmissionHandshakeResponse alloc] initWithData:nil];
}
return [responseObject autorelease];
}
@end