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
/
Copy pathORSTrimShortener.m
48 lines (41 loc) · 1.69 KB
/
ORSTrimShortener.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
//
// ORSTrimShortener.m
// URL Shorteners
//
// Created by Nicholas Toumpelis on 12/04/2009.
// Copyright 2009 Ocean Road Software. All rights reserved.
//
// Version 0.7
#import "ORSTrimShortener.h"
@implementation ORSTrimShortener
// This method returns the generated (shortened) URL that corresponds to the
// given (original) URL.
- (NSString *) generateURLFrom:(NSString *)originalURL {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:@"TrimUseAuthenticationCredentials"]) {
return [self generateAuthenticatedURLFrom:originalURL];
} else {
NSString *requestURL = [NSString
stringWithFormat:@"http://api.tr.im/api/trim_simple?url=%@",
originalURL];
return [[super generateURLFromRequestURL:requestURL] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
}
// 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 *username = [defaults stringForKey:@"TrimUsername"];
NSString *password = [defaults stringForKey:@"TrimPassword"];
NSMutableString *requestURL = [NSMutableString
stringWithFormat:@"http://api.tr.im/api/trim_simple?url=%@",
originalURL];
if (username) {
[requestURL appendFormat:@"&username=%@", username];
}
if (password) {
[requestURL appendFormat:@"&password=%@", password];
}
return [[super generateURLFromRequestURL:requestURL] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
@end