Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return STHTTPRequest #49

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions STTwitter/NSString+STTwitter.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ extern NSUInteger kSTTwitterDefaultShortURLLengthHTTPS;

// use default values for URL shortening
- (NSInteger)numberOfCharactersInATweet;
- (NSString *)stringByConvertingHTMLToPlainText;
-(NSString *)stringByRemovingURLs;
-(NSString *)stringByRemovingMentions;

@end
66 changes: 66 additions & 0 deletions STTwitter/NSString+STTwitter.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,70 @@ - (NSInteger)numberOfCharactersInATweet {
shortURLLengthHTTPS:kSTTwitterDefaultShortURLLengthHTTPS];
}


- (NSString *)stringByConvertingHTMLToPlainText {
return [[[self stringByReplacingOccurrencesOfString: @"&" withString: @"&"]
stringByReplacingOccurrencesOfString: @">" withString: @">"]
stringByReplacingOccurrencesOfString: @"&lt;" withString: @"<"];

}

-(NSString *)stringByRemovingURLs{
NSString *s = [self precomposedStringWithCanonicalMapping];


NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(https?://\\S+)"
options:0
error:&error];

NSArray *matches = [regex matchesInString:s
options:0
range:NSMakeRange(0, [s length])];

NSMutableArray* arr=[[NSMutableArray alloc] init];

for (NSTextCheckingResult *match in matches) {

NSString* matchStr=[s substringWithRange:match.range];
[arr addObject:matchStr];
}

for (NSString * match in arr) {
s=[s stringByReplacingOccurrencesOfString:match withString:@""];
}

return s;
}


-(NSString *)stringByRemovingMentions{
NSString *s = [self precomposedStringWithCanonicalMapping];


NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\b[@\\w]+\\b"
options:0
error:&error];

NSArray *matches = [regex matchesInString:s
options:0
range:NSMakeRange(0, [s length])];

NSMutableArray* arr=[[NSMutableArray alloc] init];

for (NSTextCheckingResult *match in matches) {

NSString* matchStr=[s substringWithRange:match.range];
[arr addObject:matchStr];
}

for (NSString * match in arr) {
s=[s stringByReplacingOccurrencesOfString:match withString:@""];
}

return s;
}


@end
2 changes: 1 addition & 1 deletion STTwitter/STTwitterAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ NS_ENUM(NSUInteger, STTwitterAPIErrorCode) {
The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
*/

- (void)postStatusUpdate:(NSString *)status
- (id)postStatusUpdate:(NSString *)status
mediaDataArray:(NSArray *)mediaDataArray // only one media is currently supported, help/configuration.json returns "max_media_per_upload" = 1
possiblySensitive:(NSNumber *)possiblySensitive
inReplyToStatusID:(NSString *)inReplyToStatusID
Expand Down
8 changes: 4 additions & 4 deletions STTwitter/STTwitterAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,12 @@ - (void)postAPIResource:(NSString *)resource
errorBlock:errorBlock];
}

- (void)postAPIResource:(NSString *)resource
- (id)postAPIResource:(NSString *)resource
parameters:(NSDictionary *)parameters
successBlock:(void(^)(NSDictionary *rateLimits, id json))successBlock
errorBlock:(void(^)(NSError *error))errorBlock {

[self postResource:resource
return [self postResource:resource
baseURLString:kBaseURLStringAPI
parameters:parameters
progressBlock:nil
Expand Down Expand Up @@ -827,7 +827,7 @@ - (void)postStatusUpdate:(NSString *)status
}];
}

- (void)postStatusUpdate:(NSString *)status
- (id)postStatusUpdate:(NSString *)status
mediaDataArray:(NSArray *)mediaDataArray // only one media is currently supported, help/configuration.json returns "max_media_per_upload" = 1
possiblySensitive:(NSNumber *)possiblySensitive
inReplyToStatusID:(NSString *)inReplyToStatusID
Expand All @@ -852,7 +852,7 @@ - (void)postStatusUpdate:(NSString *)status
md[@"media[]"] = [mediaDataArray objectAtIndex:0];
md[kSTPOSTDataKey] = @"media[]";

[self postAPIResource:@"statuses/update_with_media.json" parameters:md successBlock:^(NSDictionary *rateLimits, id response) {
return [self postAPIResource:@"statuses/update_with_media.json" parameters:md successBlock:^(NSDictionary *rateLimits, id response) {
successBlock(response);
} errorBlock:^(NSError *error) {
errorBlock(error);
Expand Down