Skip to content

Commit

Permalink
Move request methods into messageHandler #14
Browse files Browse the repository at this point in the history
  • Loading branch information
akervern committed Nov 18, 2011
1 parent bb779f3 commit 2c55fbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion iOS/sosmessage/sosmessage/SMDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ - (void)renderTitle {
}

-(void)fetchAMessage {
[self.messageHandler requestUrl:[NSString stringWithFormat:@"%@/api/v1/category/%@/message",SM_URL,[self.category objectForKey:@"id"]]];
[self.messageHandler requestRandomMessageForCategory:[self.category objectForKey:@"id"]];
}

#pragma mark NSMessageHandlerDelegate
Expand Down
3 changes: 3 additions & 0 deletions iOS/sosmessage/sosmessage/SMMessagesHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
- (id)initWithDelegate:(id)delegate;
- (void)requestUrl:(NSString*)url;

- (void)requestCategories;
- (void)requestRandomMessageForCategory:(NSString*)aCategoryId;

@end

@protocol SMMessageDelegate
Expand Down
11 changes: 11 additions & 0 deletions iOS/sosmessage/sosmessage/SMMessagesHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ -(void)resetData {
}
}

#pragma mark Requesting ....

- (void)requestUrl:(NSString*)url {
if (receiving && currentConnection) {
[currentConnection cancel];
Expand All @@ -80,6 +82,15 @@ - (void)requestUrl:(NSString*)url {
[nsUrl release];
}

- (void)requestCategories {
[self requestUrl:[NSString stringWithFormat:@"%@/api/v1/categories", SM_URL]];
}

- (void)requestRandomMessageForCategory:(NSString*)aCategoryId {
[self requestUrl:[NSString stringWithFormat:@"%@/api/v1/category/%@/message", SM_URL, aCategoryId]];
}

#pragma mark -
#pragma mark NSURLConnection methods
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[self resetData];
Expand Down
2 changes: 1 addition & 1 deletion iOS/sosmessage/sosmessage/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void)viewDidLoad
self.messageHandler = iMessageHandler;
[iMessageHandler release];

[self.messageHandler requestUrl:[NSString stringWithFormat:@"%@/api/v1/categories", SM_URL]];
[self.messageHandler requestCategories];
}

- (void)viewDidUnload
Expand Down

0 comments on commit 2c55fbe

Please sign in to comment.