mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Nearly all ASIHttpRequest converted.
This commit is contained in:
parent
c06993920d
commit
3926ab07f0
7 changed files with 44 additions and 105 deletions
|
@ -1716,13 +1716,12 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
- (void)loadFavicons {
|
||||
NSString *urlString = [NSString stringWithFormat:@"%@/reader/favicons",
|
||||
self.appDelegate.url];
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
|
||||
|
||||
[request setDidFinishSelector:@selector(saveAndDrawFavicons:)];
|
||||
[request setDidFailSelector:@selector(requestFailed:)];
|
||||
[request setDelegate:self];
|
||||
[request startAsynchronous];
|
||||
|
||||
[appDelegate.networkManager GET:urlString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
[self saveAndDrawFavicons:responseObject];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[self requestFailed:error];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadAvatars {
|
||||
|
@ -1748,18 +1747,9 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
|
||||
|
||||
|
||||
- (void)saveAndDrawFavicons:(ASIHTTPRequest *)request {
|
||||
__block NSString *responseString = [request responseString];
|
||||
|
||||
- (void)saveAndDrawFavicons:(NSDictionary *)results {
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
|
||||
dispatch_async(queue, ^{
|
||||
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
NSDictionary *results = [NSJSONSerialization
|
||||
JSONObjectWithData:responseData
|
||||
options:kNilOptions
|
||||
error:&error];
|
||||
|
||||
for (id feed_id in results) {
|
||||
// NSMutableDictionary *feed = [[appDelegate.dictFeeds objectForKey:feed_id] mutableCopy];
|
||||
// [feed setValue:[results objectForKey:feed_id] forKey:@"favicon"];
|
||||
|
@ -1779,11 +1769,9 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
[self loadAvatars];
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
- (void)requestFailed:(ASIHTTPRequest *)request {
|
||||
NSError *error = [request error];
|
||||
- (void)requestFailed:(NSError *)error {
|
||||
NSLog(@"Error: %@", error);
|
||||
[appDelegate informError:error];
|
||||
}
|
||||
|
@ -1816,26 +1804,26 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
urlString = [NSString stringWithFormat:@"%@/reader/refresh_feeds",
|
||||
self.appDelegate.url];
|
||||
}
|
||||
NSURL *urlFeedList = [NSURL URLWithString:urlString];
|
||||
|
||||
if (!feedId) {
|
||||
[self.appDelegate cancelOfflineQueue];
|
||||
}
|
||||
|
||||
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlFeedList];
|
||||
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
|
||||
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
|
||||
[request setValidatesSecureCertificate:NO];
|
||||
[request setDelegate:self];
|
||||
[request setResponseEncoding:NSUTF8StringEncoding];
|
||||
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
||||
if (feedId) {
|
||||
[request setUserInfo:@{@"feedId": [NSString stringWithFormat:@"%@", feedId]}];
|
||||
}
|
||||
[request setDidFinishSelector:@selector(finishRefreshingFeedList:)];
|
||||
[request setDidFailSelector:@selector(requestFailed:)];
|
||||
[request setTimeOutSeconds:30];
|
||||
[request startAsynchronous];
|
||||
[appDelegate.networkManager GET:urlString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
[self finishRefreshingFeedList:responseObject feedId:feedId];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
|
||||
|
||||
if ([httpResponse statusCode] == 403) {
|
||||
NSLog(@"Showing login after refresh");
|
||||
return [appDelegate showLogin];
|
||||
} else if ([httpResponse statusCode] == 503) {
|
||||
return [self informError:@"In maintenance mode"];
|
||||
} else if ([httpResponse statusCode] >= 500) {
|
||||
return [self informError:@"The server barfed!"];
|
||||
}
|
||||
[self requestFailed:error];
|
||||
}];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!feedId) {
|
||||
|
@ -1845,26 +1833,9 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
|
||||
}
|
||||
|
||||
- (void)finishRefreshingFeedList:(ASIHTTPRequest *)request {
|
||||
if ([request responseStatusCode] == 403) {
|
||||
NSLog(@"Showing login after refresh");
|
||||
return [appDelegate showLogin];
|
||||
} else if ([request responseStatusCode] == 503) {
|
||||
return [self informError:@"In maintenance mode"];
|
||||
} else if ([request responseStatusCode] >= 500) {
|
||||
return [self informError:@"The server barfed!"];
|
||||
}
|
||||
|
||||
- (void)finishRefreshingFeedList:(NSDictionary *)results feedId:(NSString *)feedId {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
|
||||
(unsigned long)NULL), ^(void) {
|
||||
NSString *responseString = [request responseString];
|
||||
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
NSDictionary *results = [NSJSONSerialization
|
||||
JSONObjectWithData:responseData
|
||||
options:kNilOptions
|
||||
error:&error];
|
||||
|
||||
NSDictionary *newFeedCounts = [results objectForKey:@"feeds"];
|
||||
NSInteger intelligenceLevel = [appDelegate selectedIntelligence];
|
||||
for (id feed in newFeedCounts) {
|
||||
|
@ -1923,7 +1894,7 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
[appDelegate.folderCountCache removeAllObjects];
|
||||
[self.feedTitlesTable reloadData];
|
||||
[self refreshHeaderCounts];
|
||||
if (![request.userInfo objectForKey:@"feedId"]) {
|
||||
if (!feedId) {
|
||||
[self.appDelegate startOfflineQueue];
|
||||
}
|
||||
[self loadFavicons];
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class NewsBlurAppDelegate;
|
||||
@class ASIHTTPRequest;
|
||||
|
||||
@interface ProfileBadge : UITableViewCell {
|
||||
NewsBlurAppDelegate *appDelegate;
|
||||
|
@ -40,9 +39,6 @@
|
|||
- (void)refreshWithProfile:(NSDictionary *)profile showStats:(BOOL)showStats withWidth:(int)newWidth;
|
||||
|
||||
- (IBAction)doFollowButton:(id)sender;
|
||||
- (void)finishFollowing:(ASIHTTPRequest *)request;
|
||||
- (void)finishUnfollowing:(ASIHTTPRequest *)request;
|
||||
- (void)requestFailed:(ASIHTTPRequest *)request;
|
||||
- (void)initProfile;
|
||||
|
||||
@end
|
||||
|
|
|
@ -33,9 +33,6 @@
|
|||
- (IBAction)doToggleButton:(id)sender;
|
||||
- (IBAction)doShareThisStory:(id)sender;
|
||||
- (IBAction)doReplyToComment:(id)sender;
|
||||
- (void)finishShareThisStory:(ASIHTTPRequest *)request;
|
||||
- (void)finishAddReply:(ASIHTTPRequest *)request;
|
||||
- (void)requestFailed:(ASIHTTPRequest *)request;
|
||||
- (void)replaceStory:(NSDictionary *)newStory withReplyId:(NSString *)replyId;
|
||||
- (void)adjustShareButtons;
|
||||
- (void)adjustCommentField:(CGSize)kbSize;
|
||||
|
|
|
@ -423,8 +423,7 @@
|
|||
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
||||
NSString *storyIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]];
|
||||
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
[params setObject:feedIdStr forKey:@"story_feed_id"];
|
||||
[params setObject:storyIdStr forKey:@"story_id"];
|
||||
[params setObject:[appDelegate.activeComment objectForKey:@"user_id"] forKey:@"comment_user_id"];
|
||||
|
@ -434,27 +433,18 @@
|
|||
[params setObject:activeReplyId forKey:@"reply_id"];
|
||||
}
|
||||
|
||||
[request setDelegate:self];
|
||||
[request setDidFinishSelector:@selector(finishAddReply:)];
|
||||
[request setDidFailSelector:@selector(requestFailed:)];
|
||||
[request startAsynchronous];
|
||||
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
[self finishAddReply:responseObject];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[self requestFailed:error];
|
||||
}];
|
||||
|
||||
[appDelegate hideShareView:NO];
|
||||
}
|
||||
|
||||
- (void)finishAddReply:(ASIHTTPRequest *)request {
|
||||
- (void)finishAddReply:(NSDictionary *)results {
|
||||
NSLog(@"Successfully added.");
|
||||
NSString *responseString = [request responseString];
|
||||
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
NSDictionary *results = [NSJSONSerialization
|
||||
JSONObjectWithData:responseData
|
||||
options:kNilOptions
|
||||
error:&error];
|
||||
|
||||
if (request.responseStatusCode != 200) {
|
||||
return [self requestFailed:request];
|
||||
}
|
||||
|
||||
// add the comment into the activeStory dictionary
|
||||
NSDictionary *newStory = [DataUtilities updateComment:results for:appDelegate];
|
||||
[self replaceStory:newStory withReplyId:[results objectForKey:@"reply_id"]];
|
||||
|
@ -466,7 +456,7 @@
|
|||
[MBProgressHUD hideHUDForView:appDelegate.storyPageControl.view animated:NO];
|
||||
|
||||
if (error) {
|
||||
errorMessage = error.localizedDescription
|
||||
errorMessage = error.localizedDescription;
|
||||
} else {
|
||||
errorMessage = @"The server barfed!";
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#import "BaseViewController.h"
|
||||
|
||||
@class NewsBlurAppDelegate;
|
||||
@class ASIHTTPRequest;
|
||||
|
||||
@interface StoryDetailViewController : BaseViewController
|
||||
<UIScrollViewDelegate, UIGestureRecognizerDelegate,
|
||||
|
@ -80,9 +79,7 @@ UIActionSheetDelegate> {
|
|||
- (void)openShareDialog;
|
||||
- (void)openTrainingDialog:(int)x yCoordinate:(int)y width:(int)width height:(int)height;
|
||||
- (void)openUserTagsDialog:(int)x yCoordinate:(int)y width:(int)width height:(int)height;
|
||||
- (void)finishLikeComment:(ASIHTTPRequest *)request;
|
||||
- (void)subscribeToBlurblog;
|
||||
- (void)finishSubscribeToBlurblog:(ASIHTTPRequest *)request;
|
||||
- (void)setActiveStoryAtIndex:(NSInteger)activeStoryIndex;
|
||||
- (NSString *)getHeader;
|
||||
- (NSString *)getShareBar;
|
||||
|
@ -98,6 +95,5 @@ UIActionSheetDelegate> {
|
|||
- (void)showTextOrStoryView;
|
||||
- (void)showStoryView;
|
||||
- (void)fetchTextView;
|
||||
- (void)finishFetchTextView:(ASIHTTPRequest *)request;
|
||||
|
||||
@end
|
||||
|
|
|
@ -2272,14 +2272,15 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
|
|||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
[params setObject:[self.activeStory objectForKey:@"id"] forKey:@"story_id"];
|
||||
[params setObject:[self.activeStory objectForKey:@"story_feed_id"] forKey:@"feed_id"];
|
||||
[request setUserInfo:@{@"storyId": [self.activeStory objectForKey:@"id"]}];
|
||||
[request setDidFinishSelector:@selector(finishFetchTextView:)];
|
||||
[request setDidFailSelector:@selector(failedFetchText:)];
|
||||
[request setDelegate:self];
|
||||
[request startAsynchronous];
|
||||
NSString *storyId = [self.activeStory objectForKey:@"id"];
|
||||
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
[self finishFetchTextView:responseObject storyId:storyId];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[self failedFetchText:error];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)failedFetchText:(ASIHTTPRequest *)request {
|
||||
- (void)failedFetchText:(NSError *)error {
|
||||
[self.appDelegate.storyPageControl hideNotifier];
|
||||
[MBProgressHUD hideHUDForView:self.webView animated:YES];
|
||||
if (self.activeStory == appDelegate.storyPageControl.currentPage.activeStory) {
|
||||
|
@ -2289,22 +2290,13 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
|
|||
[appDelegate.storyPageControl setTextButton:self];
|
||||
}
|
||||
|
||||
- (void)finishFetchTextView:(ASIHTTPRequest *)request {
|
||||
NSString *responseString = [request responseString];
|
||||
NSData *responseData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
NSDictionary *results = [NSJSONSerialization
|
||||
JSONObjectWithData:responseData
|
||||
options:kNilOptions
|
||||
error:&error];
|
||||
|
||||
- (void)finishFetchTextView:(NSDictionary *)results storyId:(NSString *)storyId {
|
||||
if ([[results objectForKey:@"failed"] boolValue]) {
|
||||
[self failedFetchText:request];
|
||||
[self failedFetchText:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
if (![[request.userInfo objectForKey:@"storyId"]
|
||||
isEqualToString:[self.activeStory objectForKey:@"id"]]) {
|
||||
if (![storyId isEqualToString:[self.activeStory objectForKey:@"id"]]) {
|
||||
[self.appDelegate.storyPageControl hideNotifier];
|
||||
[MBProgressHUD hideHUDForView:self.webView animated:YES];
|
||||
self.inTextView = NO;
|
||||
|
|
|
@ -17,8 +17,5 @@
|
|||
|
||||
- (BOOL)fetchImages;
|
||||
- (NSArray *)uncachedImageUrls;
|
||||
- (void)storeCachedImage:(ASIHTTPRequest *)request;
|
||||
- (void)storeFailedImage:(ASIHTTPRequest *)request;
|
||||
- (void)cachedImageQueueFinished:(ASINetworkQueue *)queue;
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Reference in a new issue