diff --git a/Blog/BlogController.h b/Blog/BlogController.h index 31b4265..9d334d5 100644 --- a/Blog/BlogController.h +++ b/Blog/BlogController.h @@ -43,4 +43,7 @@ extern NSString *BlogPostDeletedNotification; - (PMKPromise *)requestUnpublishPostWithPath:(NSString *)path; - (PMKPromise *)requestDeletePostWithPath:(NSString *)path; +- (PMKPromise *)requestPublishToStagingEnvironment; +- (PMKPromise *)requestPublishToProductionEnvironment; + @end diff --git a/Blog/BlogController.m b/Blog/BlogController.m index b2b6190..503a2ac 100644 --- a/Blog/BlogController.m +++ b/Blog/BlogController.m @@ -137,4 +137,12 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification"; }); } +- (PMKPromise *)requestPublishToStagingEnvironment { + return [_service requestPublishEnvironment:@"staging"]; +} + +- (PMKPromise *)requestPublishToProductionEnvironment { + return [_service requestPublishEnvironment:@"production"]; +} + @end diff --git a/Blog/PostsViewController.m b/Blog/PostsViewController.m index 3c8e44a..bae7a8c 100644 --- a/Blog/PostsViewController.m +++ b/Blog/PostsViewController.m @@ -194,7 +194,19 @@ static const NSUInteger SectionPublished = 1; } - (IBAction)publish:(id)sender { - NSLog(@"publish"); + // TODO: activity indicator, maybe show an action sheet to select Staging or Production? + self.publishButton.enabled = NO; + [self.blogController requestPublishToStagingEnvironment].then(^{ + [self requestStatusWithoutCaching]; + }).catch(^(NSError *error) { + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert]; + [alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [self dismissViewControllerAnimated:YES completion:nil]; + }]]; + [self presentViewController:alertController animated:YES completion:nil]; + }).finally(^{ + self.publishButton.enabled = YES; + }); } #pragma mark - Segues