This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
ORSAdjixShortener.m
59 lines (50 loc) · 1.82 KB
/
ORSAdjixShortener.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
//
// ORSAdjixShortener.m
// URL Shorteners
//
// Created by Nicholas Toumpelis on 12/04/2009.
// Copyright 2009 Ocean Road Software. All rights reserved.
//
// Version 0.7
#import "ORSAdjixShortener.h"
@implementation ORSAdjixShortener
// This method returns the generated (shortened) URL that corresponds to the
// given (original) URL.
- (NSString *) generateURLFrom:(NSString *)originalURL {
/*NSString *requestURL = [NSString
stringWithFormat:@"http://api.adjix.com/shrinkLink?url=%@",
originalURL];
return [super generateURLFromRequestURL:requestURL]; */
return [self generateAuthenticatedURLFrom:originalURL];
}
// This method returns the generated (shortened) URL that corresponds to the
// given (original) URL using the specified set of authentication credentials.
- (NSString *) generateAuthenticatedURLFrom:(NSString *)originalURL {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *partnerID = [defaults stringForKey:@"AdjixPartnerID"];
NSString *partnerEmail = [defaults stringForKey:@"AdjixPartnerEmail"];
NSString *adType = [defaults stringForKey:@"AdjixAdType"];
int useIDOrEmail = [defaults integerForKey:@"AdjixUseIDOrEmail"];
BOOL generateUltraShortURLs = [defaults
boolForKey:@"AdjixGenerateUltraShortURLs"];
NSMutableString *requestURL = [NSMutableString
stringWithFormat:@"http://api.adjix.com/shrinkLink?url=%@",
originalURL];
if (useIDOrEmail == 0) {
if (partnerID) {
[requestURL appendFormat:@"&partnerID=%@", partnerID];
}
} else {
if (partnerEmail) {
[requestURL appendFormat:@"&partnerEmail=%@", partnerEmail];
}
}
if (adType) {
[requestURL appendFormat:@"&at=%@", adType];
}
if (generateUltraShortURLs) {
[requestURL appendString:@"&ultraShort=y"];
}
return [super generateURLFromRequestURL:requestURL];
}
@end