Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added Commit model and parser

  • Loading branch information...
commit 92e377ca3ceb7c712df9c161d98b3a2271be7c2c 1 parent 9e5484e
OLD PROFILE! Go to /dennisreimann dbloete authored
4 Classes/FeedEntryDetailsController.m
@@ -27,7 +27,7 @@ - (void)viewDidLoad {
27 27 NSString *stylePath = [[NSBundle mainBundle] pathForResource:@"styles" ofType:@"html"];
28 28 NSString *style = [NSString stringWithContentsOfFile:stylePath encoding:NSUTF8StringEncoding error:nil];
29 29 NSString *html = [NSString stringWithFormat:@"%@%@", style, entry.content];
30   - [contentView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://github.com/"]];
  30 + [contentView loadHTMLString:html baseURL:nil];
31 31 // Date
32 32 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
33 33 [dateFormatter setDateStyle:NSDateFormatterFullStyle];
@@ -95,7 +95,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object change:change
95 95 #pragma mark UIWebView delegation methods
96 96
97 97 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
98   - return YES;
  98 + return [[[request URL] absoluteString] isEqualToString:@"about:blank"];
99 99 }
100 100
101 101 #pragma mark -
30 Classes/GHCommit.h
... ... @@ -0,0 +1,30 @@
  1 +#import <Foundation/Foundation.h>
  2 +
  3 +
  4 +@interface GHCommit : NSObject {
  5 + NSString *commitID;
  6 + NSString *tree;
  7 + NSString *message;
  8 + NSURL *commitURL;
  9 + NSString *authorName;
  10 + NSString *authorEmail;
  11 + NSString *committerName;
  12 + NSString *committerEmail;
  13 + NSDate *committedDate;
  14 + NSDate *authoredDate;
  15 +}
  16 +
  17 +@property (nonatomic, retain) NSString *commitID;
  18 +@property (nonatomic, retain) NSString *tree;
  19 +@property (nonatomic, retain) NSString *message;
  20 +@property (nonatomic, retain) NSURL *commitURL;
  21 +@property (nonatomic, retain) NSString *authorName;
  22 +@property (nonatomic, retain) NSString *authorEmail;
  23 +@property (nonatomic, retain) NSString *committerName;
  24 +@property (nonatomic, retain) NSString *committerEmail;
  25 +@property (nonatomic, retain) NSDate *committedDate;
  26 +@property (nonatomic, retain) NSDate *authoredDate;
  27 +
  28 +- (id)initWithCommitID:(NSString *)theCommitID;
  29 +
  30 +@end
32 Classes/GHCommit.m
... ... @@ -0,0 +1,32 @@
  1 +#import "GHCommit.h"
  2 +
  3 +
  4 +@implementation GHCommit
  5 +
  6 +@synthesize commitID, tree, message, commitURL, authorName, authorEmail, committerName, committerEmail, committedDate, authoredDate;
  7 +
  8 +- (id)initWithCommitID:(NSString *)theCommitID {
  9 + if (self = [super init]) {
  10 + self.commitID = theCommitID;
  11 + }
  12 + return self;
  13 +}
  14 +
  15 +#pragma mark -
  16 +#pragma mark Cleanup
  17 +
  18 +- (void)dealloc {
  19 + [commitID release];
  20 + [tree release];
  21 + [message release];
  22 + [commitURL release];
  23 + [authorName release];
  24 + [authorEmail release];
  25 + [committerName release];
  26 + [committerEmail release];
  27 + [committedDate release];
  28 + [authoredDate release];
  29 + [super dealloc];
  30 +}
  31 +
  32 +@end
17 Classes/GHCommitsParserDelegate.h
... ... @@ -0,0 +1,17 @@
  1 +#import <Foundation/Foundation.h>
  2 +
  3 +
  4 +@class GHCommit;
  5 +
  6 +@interface GHCommitsParserDelegate : NSObject {
  7 + @private
  8 + id target;
  9 + SEL selector;
  10 + NSMutableArray *commits;
  11 + NSMutableString *currentElementValue;
  12 + GHCommit *currentCommit;
  13 +}
  14 +
  15 +- (id)initWithTarget:(id)theTarget andSelector:(SEL)theSelector;
  16 +
  17 +@end
64 Classes/GHCommitsParserDelegate.m
... ... @@ -0,0 +1,64 @@
  1 +#import "GHCommitsParserDelegate.h"
  2 +#import "GHCommit.h"
  3 +
  4 +
  5 +@implementation GHCommitsParserDelegate
  6 +
  7 +- (id)initWithTarget:(id)theTarget andSelector:(SEL)theSelector {
  8 + if (self = [super init]) {
  9 + commits = [[NSMutableArray alloc] init];
  10 + target = theTarget;
  11 + selector = theSelector;
  12 + }
  13 + return self;
  14 +}
  15 +
  16 +#pragma mark -
  17 +#pragma mark NSXMLParser delegation methods
  18 +
  19 +- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
  20 + if ([elementName isEqualToString:@"commit"]) {
  21 + currentCommit = [[GHCommit alloc] init];
  22 + }
  23 +}
  24 +
  25 +- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
  26 + string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  27 + if (!currentElementValue) {
  28 + currentElementValue = [[NSMutableString alloc] initWithString:string];
  29 + } else {
  30 + [currentElementValue appendString:string];
  31 + }
  32 +}
  33 +
  34 +- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
  35 + if ([elementName isEqualToString:@"commit"]) {
  36 + [commits addObject:currentCommit];
  37 + [currentCommit release];
  38 + currentCommit = nil;
  39 + } else if ([elementName isEqualToString:@"message"] || [elementName isEqualToString:@"tree"]) {
  40 + [currentCommit setValue:currentElementValue forKey:elementName];
  41 + } else if ([elementName isEqualToString:@"id"]) {
  42 + currentCommit.commitID = currentElementValue;
  43 + } else if ([elementName isEqualToString:@"url"]) {
  44 + currentCommit.commitURL = ([currentElementValue isEqualToString:@""]) ? nil : [NSURL URLWithString:currentElementValue];
  45 + }
  46 + [currentElementValue release];
  47 + currentElementValue = nil;
  48 +}
  49 +
  50 +- (void)parserDidEndDocument:(NSXMLParser *)parser {
  51 + [target performSelectorOnMainThread:selector withObject:commits waitUntilDone:YES];
  52 +}
  53 +
  54 +#pragma mark -
  55 +#pragma mark Cleanup
  56 +
  57 +- (void)dealloc {
  58 + [commits release];
  59 + [currentElementValue release];
  60 + [currentCommit release];
  61 + [super dealloc];
  62 +}
  63 +
  64 +@end
12 iOctocat.xcodeproj/project.pbxproj
@@ -56,6 +56,8 @@
56 56 6FB7FEAB0F7E2C8700E8D702 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6FB7FEA90F7E2C8700E8D702 /* MainWindow.xib */; };
57 57 6FB7FEEC0F7E31AC00E8D702 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 6FB7FEEA0F7E31AC00E8D702 /* Default.png */; };
58 58 6FB7FEED0F7E31AC00E8D702 /* NoConnection.png in Resources */ = {isa = PBXBuildFile; fileRef = 6FB7FEEB0F7E31AC00E8D702 /* NoConnection.png */; };
  59 + 6FC465120F9D141D003A8E7B /* GHCommitsParserDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC465110F9D141D003A8E7B /* GHCommitsParserDelegate.m */; };
  60 + 6FC465170F9D1445003A8E7B /* GHCommit.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC465160F9D1445003A8E7B /* GHCommit.m */; };
59 61 6FC647290F9B165E00FE39F6 /* GHReposParserDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC647280F9B165E00FE39F6 /* GHReposParserDelegate.m */; };
60 62 6FC95F1F0F8905F500FC0968 /* UserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC95F1E0F8905F500FC0968 /* UserViewController.m */; };
61 63 6FC95F280F8908ED00FC0968 /* UserTableHeadBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = 6FC95F270F8908ED00FC0968 /* UserTableHeadBackground.png */; };
@@ -135,6 +137,10 @@
135 137 6FB7FEA90F7E2C8700E8D702 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = MainWindow.xib; path = IBFiles/MainWindow.xib; sourceTree = "<group>"; };
136 138 6FB7FEEA0F7E31AC00E8D702 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = Images/Default.png; sourceTree = "<group>"; };
137 139 6FB7FEEB0F7E31AC00E8D702 /* NoConnection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = NoConnection.png; path = Images/NoConnection.png; sourceTree = "<group>"; };
  140 + 6FC465100F9D141D003A8E7B /* GHCommitsParserDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHCommitsParserDelegate.h; sourceTree = "<group>"; };
  141 + 6FC465110F9D141D003A8E7B /* GHCommitsParserDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHCommitsParserDelegate.m; sourceTree = "<group>"; };
  142 + 6FC465150F9D1445003A8E7B /* GHCommit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHCommit.h; sourceTree = "<group>"; };
  143 + 6FC465160F9D1445003A8E7B /* GHCommit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHCommit.m; sourceTree = "<group>"; };
138 144 6FC647270F9B165E00FE39F6 /* GHReposParserDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHReposParserDelegate.h; sourceTree = "<group>"; };
139 145 6FC647280F9B165E00FE39F6 /* GHReposParserDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHReposParserDelegate.m; sourceTree = "<group>"; };
140 146 6FC95F1D0F8905F500FC0968 /* UserViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserViewController.h; sourceTree = "<group>"; };
@@ -248,8 +254,12 @@
248 254 6F35BD380F88B01900E978CD /* GHUser.m */,
249 255 6F35BD520F88B06200E978CD /* GHRepository.h */,
250 256 6F35BD530F88B06200E978CD /* GHRepository.m */,
  257 + 6FC465150F9D1445003A8E7B /* GHCommit.h */,
  258 + 6FC465160F9D1445003A8E7B /* GHCommit.m */,
251 259 6FC647270F9B165E00FE39F6 /* GHReposParserDelegate.h */,
252 260 6FC647280F9B165E00FE39F6 /* GHReposParserDelegate.m */,
  261 + 6FC465100F9D141D003A8E7B /* GHCommitsParserDelegate.h */,
  262 + 6FC465110F9D141D003A8E7B /* GHCommitsParserDelegate.m */,
253 263 6FCAF1640F895756005E1173 /* GravatarLoader.h */,
254 264 6FCAF1650F895756005E1173 /* GravatarLoader.m */,
255 265 );
@@ -464,6 +474,8 @@
464 474 6F72FA880F9B3D750069F092 /* DebugLog.m in Sources */,
465 475 6F72FAE80F9B47730069F092 /* FeedEntryDetailsController.m in Sources */,
466 476 6F72FB2F0F9B53810069F092 /* GHFeedEntryCell.m in Sources */,
  477 + 6FC465120F9D141D003A8E7B /* GHCommitsParserDelegate.m in Sources */,
  478 + 6FC465170F9D1445003A8E7B /* GHCommit.m in Sources */,
467 479 );
468 480 runOnlyForDeploymentPostprocessing = 0;
469 481 };

0 comments on commit 92e377c

Please sign in to comment.
Something went wrong with that request. Please try again.