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
/
BGAudioScrobblerXmlRpcPost.m
71 lines (57 loc) · 1.84 KB
/
BGAudioScrobblerXmlRpcPost.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// BGAudioScrobblerXmlRpcPost.m
// ScrobblePod
//
// Created by Ben Gummer on 24/04/08.
// Copyright 2008 Ben Gummer. All rights reserved.
//
#import "BGAudioScrobblerXmlRpcPost.h"
#import "BGAudioScrobblerXmlRpcParameter.h"
#import "CocoaCryptoHashing.h"
@implementation BGAudioScrobblerXmlRpcPost
@synthesize methodName;
- (id) init
{
self = [super init];
if (self != nil) {
postParameters = [NSMutableArray new];
}
return self;
}
- (void) dealloc
{
[postParameters release];
[super dealloc];
}
-(void)addPostParameter:(id)theParameter {
BGAudioScrobblerXmlRpcParameter *postParameter = [[BGAudioScrobblerXmlRpcParameter alloc] initWithParameter:theParameter];
[postParameters addObject:postParameter];
[postParameter release];
}
-(NSArray *)postParameters {
return postParameters;
}
-(NSString *)challengeFromPassword:(NSString *)aPass andTimestamp:(NSString *)aTime {
return [[NSString stringWithFormat:@"%@%@",[aPass md5HexHash],aTime] md5HexHash];
}
-(void)addAuthParametersWithUsername:(NSString *)aUsername andPassword:(NSString *)aPassword {
NSString *timestamp = [self timestamp];
NSString *challenge = [self challengeFromPassword:aPassword andTimestamp:timestamp];
[self addPostParameter:aUsername];
[self addPostParameter:timestamp];
[self addPostParameter:challenge];
}
-(NSString *)timestamp {
return [NSString stringWithFormat:@"%d",(int)[[NSDate date] timeIntervalSince1970]];
}
-(NSString *)xmlDescription {
NSMutableString *xmlString = [NSMutableString stringWithCapacity:300];
[xmlString appendFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>%@</methodName><params>",methodName];
int i;
for (i = 0; i < postParameters.count; i++) {
[xmlString appendString:[[postParameters objectAtIndex:i] xmlDescription]];
}
[xmlString appendString:@"</params></methodCall>"];
return xmlString;
}
@end