implement sync (git push)

This commit is contained in:
Sami Samhuri 2015-05-08 19:50:01 -07:00
parent 3b597a5c86
commit a02874d82d
5 changed files with 17 additions and 2 deletions

View file

@ -33,6 +33,7 @@
- (PMKPromise *)requestUnpublishPost:(Post *)post; - (PMKPromise *)requestUnpublishPost:(Post *)post;
- (PMKPromise *)requestDeletePost:(Post *)post; - (PMKPromise *)requestDeletePost:(Post *)post;
- (PMKPromise *)requestSync;
- (PMKPromise *)requestPublishToStagingEnvironment; - (PMKPromise *)requestPublishToStagingEnvironment;
- (PMKPromise *)requestPublishToProductionEnvironment; - (PMKPromise *)requestPublishToProductionEnvironment;

View file

@ -127,6 +127,10 @@
}); });
} }
- (PMKPromise *)requestSync {
return [_service requestSync];
}
- (PMKPromise *)requestPublishToStagingEnvironment { - (PMKPromise *)requestPublishToStagingEnvironment {
return [_service requestPublishEnvironment:@"staging"]; return [_service requestPublishEnvironment:@"staging"];
} }

View file

@ -26,6 +26,7 @@ typedef NS_ENUM(NSUInteger, BlogServiceErrorCode) {
- (PMKPromise *)requestBlogStatus; - (PMKPromise *)requestBlogStatus;
- (PMKPromise *)requestPublishEnvironment:(NSString *)environment; - (PMKPromise *)requestPublishEnvironment:(NSString *)environment;
- (PMKPromise *)requestSync;
- (PMKPromise *)requestDrafts; - (PMKPromise *)requestDrafts;
- (PMKPromise *)requestPublishedPosts; - (PMKPromise *)requestPublishedPosts;

View file

@ -77,6 +77,10 @@ NSString *const BlogServiceErrorDomain = @"BlogServiceErrorDomain";
return [self.client postJSON:[self urlFor:@"/publish"] headers:nil fields:fields]; return [self.client postJSON:[self urlFor:@"/publish"] headers:nil fields:fields];
} }
- (PMKPromise *)requestSync {
return [self.client post:[self urlFor:@"/sync"] headers:nil];
}
- (PMKPromise *)requestDrafts { - (PMKPromise *)requestDrafts {
return [self.client get:[self urlFor:@"/posts/drafts"] headers:nil].then([self decodePostsBlock]); return [self.client get:[self urlFor:@"/posts/drafts"] headers:nil].then([self decodePostsBlock]);
} }

View file

@ -273,16 +273,21 @@ static const NSUInteger SectionPublished = 1;
}); });
}; };
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Publish" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Publish" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alertController addAction:[UIAlertAction actionWithTitle:@"Production" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [alertController addAction:[UIAlertAction actionWithTitle:@"samhuri.net" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
__typeof__(self) self = welf; __typeof__(self) self = welf;
[self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];
publish([self.blogController requestPublishToProductionEnvironment]); publish([self.blogController requestPublishToProductionEnvironment]);
}]]; }]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Staging" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [alertController addAction:[UIAlertAction actionWithTitle:@"beta.samhuri.net" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
__typeof__(self) self = welf; __typeof__(self) self = welf;
[self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];
publish([self.blogController requestPublishToStagingEnvironment]); publish([self.blogController requestPublishToStagingEnvironment]);
}]]; }]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Push to GitHub" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
__typeof__(self) self = welf;
[self dismissViewControllerAnimated:YES completion:nil];
publish([self.blogController requestSync]);
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
__typeof__(self) self = welf; __typeof__(self) self = welf;
[self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];