diff --git a/Trovebox.xcodeproj/project.pbxproj b/Trovebox.xcodeproj/project.pbxproj index 7a287b6..353122f 100644 --- a/Trovebox.xcodeproj/project.pbxproj +++ b/Trovebox.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ CD63EE7E191065C300153F49 /* OARequestParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = CD63EE5E191065C300153F49 /* OARequestParameter.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; CD63EE80191065C300153F49 /* OAServiceTicket.m in Sources */ = {isa = PBXBuildFile; fileRef = CD63EE62191065C300153F49 /* OAServiceTicket.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; CD63EE82191065C300153F49 /* OAToken.m in Sources */ = {isa = PBXBuildFile; fileRef = CD63EE67191065C300153F49 /* OAToken.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + CDBE75A519196F50004710F2 /* Timeline.m in Sources */ = {isa = PBXBuildFile; fileRef = CDBE75A419196F50004710F2 /* Timeline.m */; }; + CDBE75A81919706D004710F2 /* PhotoFriendUploader.m in Sources */ = {isa = PBXBuildFile; fileRef = CDBE75A71919706D004710F2 /* PhotoFriendUploader.m */; }; CDD9E4F818A144E4006EEC0D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD9E4F718A144E4006EEC0D /* Foundation.framework */; }; CDD9E4FA18A144E4006EEC0D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD9E4F918A144E4006EEC0D /* CoreGraphics.framework */; }; CDD9E4FC18A144E4006EEC0D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD9E4FB18A144E4006EEC0D /* UIKit.framework */; }; @@ -41,7 +43,6 @@ CDD9E52318A144E4006EEC0D /* TroveboxTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E52218A144E4006EEC0D /* TroveboxTests.m */; }; CDD9E56018A1467F006EEC0D /* Synced+Methods.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E55418A1467F006EEC0D /* Synced+Methods.m */; }; CDD9E56118A1467F006EEC0D /* Timeline+Methods.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E55618A1467F006EEC0D /* Timeline+Methods.m */; }; - CDD9E56218A1467F006EEC0D /* Timeline.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E55818A1467F006EEC0D /* Timeline.m */; }; CDD9E56318A1467F006EEC0D /* Photo.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E55918A1467F006EEC0D /* Photo.xcdatamodel */; }; CDD9E56418A1467F006EEC0D /* Photo.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E55B18A1467F006EEC0D /* Photo.m */; }; CDD9E56518A1467F006EEC0D /* Synced.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD9E55D18A1467F006EEC0D /* Synced.m */; }; @@ -207,6 +208,10 @@ CD63EE66191065C300153F49 /* OAToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OAToken.h; sourceTree = ""; }; CD63EE67191065C300153F49 /* OAToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OAToken.m; sourceTree = ""; }; CD63EE6A191065C300153F49 /* OAuthConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OAuthConsumer.h; sourceTree = ""; }; + CDBE75A319196F50004710F2 /* Timeline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Timeline.h; sourceTree = ""; }; + CDBE75A419196F50004710F2 /* Timeline.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Timeline.m; sourceTree = ""; }; + CDBE75A61919706D004710F2 /* PhotoFriendUploader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PhotoFriendUploader.h; sourceTree = ""; }; + CDBE75A71919706D004710F2 /* PhotoFriendUploader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhotoFriendUploader.m; sourceTree = ""; }; CDD9E4F418A144E4006EEC0D /* Trovebox.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Trovebox.app; sourceTree = BUILT_PRODUCTS_DIR; }; CDD9E4F718A144E4006EEC0D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; CDD9E4F918A144E4006EEC0D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -228,8 +233,6 @@ CDD9E55418A1467F006EEC0D /* Synced+Methods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Synced+Methods.m"; sourceTree = ""; }; CDD9E55518A1467F006EEC0D /* Timeline+Methods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Timeline+Methods.h"; sourceTree = ""; }; CDD9E55618A1467F006EEC0D /* Timeline+Methods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Timeline+Methods.m"; sourceTree = ""; }; - CDD9E55718A1467F006EEC0D /* Timeline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Timeline.h; sourceTree = ""; }; - CDD9E55818A1467F006EEC0D /* Timeline.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Timeline.m; sourceTree = ""; }; CDD9E55918A1467F006EEC0D /* Photo.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Photo.xcdatamodel; sourceTree = ""; }; CDD9E55A18A1467F006EEC0D /* Photo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Photo.h; sourceTree = ""; }; CDD9E55B18A1467F006EEC0D /* Photo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Photo.m; sourceTree = ""; }; @@ -651,9 +654,9 @@ CDD9E55418A1467F006EEC0D /* Synced+Methods.m */, CDD9E55518A1467F006EEC0D /* Timeline+Methods.h */, CDD9E55618A1467F006EEC0D /* Timeline+Methods.m */, - CDD9E55718A1467F006EEC0D /* Timeline.h */, - CDD9E55818A1467F006EEC0D /* Timeline.m */, CDD9E55918A1467F006EEC0D /* Photo.xcdatamodel */, + CDBE75A319196F50004710F2 /* Timeline.h */, + CDBE75A419196F50004710F2 /* Timeline.m */, CDD9E55A18A1467F006EEC0D /* Photo.h */, CDD9E55B18A1467F006EEC0D /* Photo.m */, CDD9E55C18A1467F006EEC0D /* Synced.h */, @@ -906,6 +909,8 @@ CD3DA77C19143FE200C4B5C9 /* FriendDetailsViewController.m */, CD3DA77E19143FE200C4B5C9 /* FriendDetailsViewControlleriPad.xib */, CD3DA77F19143FE200C4B5C9 /* FriendDetailsViewController.xib */, + CDBE75A61919706D004710F2 /* PhotoFriendUploader.h */, + CDBE75A71919706D004710F2 /* PhotoFriendUploader.m */, ); name = Friends; sourceTree = ""; @@ -1077,7 +1082,6 @@ CDD9E65918A147A7006EEC0D /* CoreDataTableViewController.m in Sources */, CDD9E62A18A1478F006EEC0D /* WebService.m in Sources */, CDD9E60218A14754006EEC0D /* MWCaptionView.m in Sources */, - CDD9E56218A1467F006EEC0D /* Timeline.m in Sources */, CDD9E59A18A146CC006EEC0D /* MenuTableViewSectionCell.m in Sources */, CDD9E57E18A1469E006EEC0D /* LoginConnectViewController.m in Sources */, CD63EE7A191065C300153F49 /* OAMutableURLRequest.m in Sources */, @@ -1129,6 +1133,7 @@ CDD9E65B18A147A7006EEC0D /* Constants.m in Sources */, CDD9E5D218A1472A006EEC0D /* JobUploaderController.m in Sources */, CDD9E65E18A147A7006EEC0D /* NSDictionarySerializer.m in Sources */, + CDBE75A81919706D004710F2 /* PhotoFriendUploader.m in Sources */, CDD9E5BE18A14707006EEC0D /* OpenPhotoIASKAppSettingsViewController.m in Sources */, CDD9E5B218A146EB006EEC0D /* UploadCell.m in Sources */, CDD9E60918A14754006EEC0D /* TMPhotoQuiltViewCell.m in Sources */, @@ -1158,6 +1163,7 @@ CDD9E56418A1467F006EEC0D /* Photo.m in Sources */, CDD9E61018A14769006EEC0D /* AlbumViewController.m in Sources */, CDD9E5E418A1473B006EEC0D /* ELCAssetCell.m in Sources */, + CDBE75A519196F50004710F2 /* Timeline.m in Sources */, CDD9E50618A144E4006EEC0D /* main.m in Sources */, CD63EE6D191065C300153F49 /* NSMutableURLRequest+Parameters.m in Sources */, CDD9E56118A1467F006EEC0D /* Timeline+Methods.m in Sources */, diff --git a/Trovebox/HomeTableViewController.m b/Trovebox/HomeTableViewController.m index dbda8b7..1aadd45 100644 --- a/Trovebox/HomeTableViewController.m +++ b/Trovebox/HomeTableViewController.m @@ -199,8 +199,13 @@ // set the upload photo object in the cell for restart or cancel uploadCell.originalObject = photo; - // set thumb - uploadCell.thumb.image = [UIImage imageWithData:photo.photoDataThumb]; + if ([photo.copyFromFriend boolValue]){ + // show default thumb + uploadCell.thumb.image = [UIImage imageNamed:@"Icon.png"]; + }else{ + // set thumb + uploadCell.thumb.image = [UIImage imageWithData:photo.photoDataThumb]; + } [uploadCell.thumb.superview.layer setCornerRadius:3.0f]; [uploadCell.thumb.superview.layer setShadowColor:[UIColor blackColor].CGColor]; [uploadCell.thumb.superview.layer setShadowOpacity:0.25]; @@ -212,18 +217,32 @@ uploadCell.progressBar.hidden=YES; if ( [photo.status isEqualToString:kUploadStatusTypeCreated]){ - uploadCell.status.text=NSLocalizedString(@"Waiting ...",@"Status upload - waiting"); + if ([photo.copyFromFriend boolValue]){ + uploadCell.status.text=NSLocalizedString(@"Waiting to copy",@"Waiting to copy"); + }else{ + uploadCell.status.text=NSLocalizedString(@"Waiting ...",@"Status upload - waiting"); + } + + [uploadCell.imageStatus setImage:[UIImage imageNamed:@"home-waiting.png"]]; uploadCell.imageStatus.hidden=NO; uploadCell.status.textColor=UIColorFromRGB(0x3B2414); }else if ( [photo.status isEqualToString:kUploadStatusTypeUploading]){ - uploadCell.status.text=@""; - uploadCell.status.textColor=UIColorFromRGB(0x3B2414); - uploadCell.progressBar.hidden=NO; + if ([photo.copyFromFriend boolValue]){ + uploadCell.status.text=@"Copying ..."; + }else{ + uploadCell.status.text=@""; + [uploadCell.progressBar setProgress:[photo.photoUploadProgress floatValue]]; + uploadCell.progressBar.hidden=NO; + } - [uploadCell.progressBar setProgress:[photo.photoUploadProgress floatValue]]; + uploadCell.status.textColor=UIColorFromRGB(0x3B2414); }else if ( [photo.status isEqualToString:kUploadStatusTypeUploadFinished]){ - uploadCell.status.text=NSLocalizedString(@"Upload finished!",@"Status upload - Upload finished!"); + if ([photo.copyFromFriend boolValue]){ + uploadCell.status.text=NSLocalizedString(@"Copy finished!",@"Status copy - copy finished!"); + }else{ + uploadCell.status.text=NSLocalizedString(@"Upload finished!",@"Status upload - Upload finished!"); + } uploadCell.status.textColor=UIColorFromRGB(0x3B2414); [uploadCell.imageStatus setImage:[UIImage imageNamed:@"home-finished.png"]]; uploadCell.imageStatus.hidden=NO; @@ -251,7 +270,11 @@ // delete this object after 2 seconds [self performSelector:@selector(deleteTimeline:) withObject:photo afterDelay:2.0]; }else if ( [photo.status isEqualToString:kUploadStatusTypeFailed]){ - uploadCell.status.text=NSLocalizedString(@"Retry uploading",@"Status upload - Retry uploading!"); + if ([photo.copyFromFriend boolValue]){ + uploadCell.status.text=NSLocalizedString(@"Retry copying",@"Status upload - Retry copying!"); + }else{ + uploadCell.status.text=NSLocalizedString(@"Retry uploading",@"Status upload - Retry uploading!"); + } uploadCell.status.textColor=UIColorFromRGB(0x3B2414); }else if ( [photo.status isEqualToString:kUploadStatusTypeDuplicated]){ uploadCell.status.text=NSLocalizedString(@"Already in your account",@"Status upload - Already in your account"); @@ -425,7 +448,7 @@ self.mwphoto.permission = photo.permission; MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; - + // check if user is type GROUP // if yes, he should not have access to actions NSString *type = [[NSUserDefaults standardUserDefaults] objectForKey:kTroveboxTypeUser]; @@ -434,7 +457,7 @@ }else{ browser.displayActionButton = YES; } - + UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:browser]; // Present diff --git a/Trovebox/JobUploaderController.m b/Trovebox/JobUploaderController.m index 85bdfbd..85a2ef1 100644 --- a/Trovebox/JobUploaderController.m +++ b/Trovebox/JobUploaderController.m @@ -176,14 +176,14 @@ #endif NSURL *url = [[result valueForProperty:ALAssetPropertyURLs] valueForKey:[[[result valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]]; [uploader loadDataAndSaveEntityUploadDate:[NSDate date] - shareFacebook:[NSNumber numberWithBool:NO] - shareTwitter:[NSNumber numberWithBool:NO] - permission:[NSNumber numberWithBool:NO] - tags:@"" - albums:@"" - title:@"" - url:url - groupUrl:nil]; + shareFacebook:[NSNumber numberWithBool:NO] + shareTwitter:[NSNumber numberWithBool:NO] + permission:[NSNumber numberWithBool:NO] + tags:@"" + albums:@"" + title:@"" + url:url + groupUrl:nil]; } }else{ // stop the enumeration @@ -253,17 +253,27 @@ // prepare the data to upload NSString *filename = photo.fileName; - // set size - delegate.totalSize = [NSNumber numberWithInteger:data.length]; - + if (![photo.copyFromFriend boolValue]){ + // on upload, not copying + // set size + delegate.totalSize = [NSNumber numberWithInteger:data.length]; + } // create the service, check photo exists and send the request WebService *service = [[WebService alloc] init]; // before check if the photo already exist - if ([service isPhotoAlreadyOnServer:[SHA1 sha1File:data]]){ + if (![photo.copyFromFriend boolValue] &&[service isPhotoAlreadyOnServer:[SHA1 sha1File:data]]){ @throw [NSException exceptionWithName:@"Failed to upload" reason:@"409" userInfo: nil]; }else{ - NSDictionary *response = [service uploadPicture:data metadata:dictionary fileName:filename delegate:delegate]; + NSDictionary *response; + + if ([photo.copyFromFriend boolValue]){ + // copy + response= [service copyPictureWithUrl:photo.photoUrl]; + }else{ + response= [service uploadPicture:data metadata:dictionary fileName:filename delegate:delegate]; + } + #ifdef DEVELOPMENT_ENABLED NSLog(@"Photo uploaded correctly"); #endif diff --git a/Trovebox/MWPhotoBrowser.h b/Trovebox/MWPhotoBrowser.h index fdb8877..8226315 100644 --- a/Trovebox/MWPhotoBrowser.h +++ b/Trovebox/MWPhotoBrowser.h @@ -11,6 +11,7 @@ #import "MWPhoto.h" #import "MWPhotoProtocol.h" #import "MWCaptionView.h" +#import "PhotoFriendUploader.h" // Debug Logging #if 0 // Set to 1 to enable debug logging diff --git a/Trovebox/MWPhotoBrowser.m b/Trovebox/MWPhotoBrowser.m index c99291c..a566980 100644 --- a/Trovebox/MWPhotoBrowser.m +++ b/Trovebox/MWPhotoBrowser.m @@ -1242,51 +1242,20 @@ #ifdef DEVELOPMENT_ENABLED NSLog(@"Download image"); #endif - - - /* - // Only react when image has loaded id photo = [self photoAtIndex:_currentPageIndex]; - // get factory for Service - TroveboxServerAPI *service = [[TroveboxServerAPI alloc] init]; + PhotoFriendUploader *upload = [[PhotoFriendUploader alloc]init]; + [upload loadDataAndSaveEntityUrl:photo.url]; - // progress - [MBProgressHUD showHUDAddedTo:self.view animated:YES]; - - [service inappropriatePhoto:photo.identification success:^(id response) { - [MBProgressHUD hideHUDForView:self.view animated:YES]; - // get default answer - TroveboxAnswerAPI *api = [[TroveboxAnswerAPI alloc] initWithAnswer:response]; -#ifdef DEVELOPMENT_ENABLED - NSLog(@"Answer %@",api); -#endif - - UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Message received" - message:@"Thanks for reporting this photo." + UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Copying" + message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [message show]; - - } failure:^(NSError *error) { - [MBProgressHUD hideHUDForView:self.view animated:YES]; -#ifdef DEVELOPMENT_ENABLED - NSLog(@"Error %@", error.description); -#endif - UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Error" - message:@"Error to send your request. Try again later, please." - delegate:nil - cancelButtonTitle:@"OK" - otherButtonTitles:nil]; - [message show]; - }]; - */ } - } - #pragma mark - Actions - (void)actionButtonPressed:(id)sender { diff --git a/Trovebox/MWPhotoProtocol.h b/Trovebox/MWPhotoProtocol.h index f1c48ee..a0faf4a 100644 --- a/Trovebox/MWPhotoProtocol.h +++ b/Trovebox/MWPhotoProtocol.h @@ -61,4 +61,7 @@ // in the server - (NSString *)identification; +// photo url to upload to server in the case of friends +- (NSString *)url; + @end \ No newline at end of file diff --git a/Trovebox/Photo.xcdatamodel/contents b/Trovebox/Photo.xcdatamodel/contents index 1f81d3f..b66eea5 100644 --- a/Trovebox/Photo.xcdatamodel/contents +++ b/Trovebox/Photo.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -20,6 +20,7 @@ + @@ -47,6 +48,6 @@ - + \ No newline at end of file diff --git a/Trovebox/PhotoFriendUploader.h b/Trovebox/PhotoFriendUploader.h new file mode 100644 index 0000000..853fa54 --- /dev/null +++ b/Trovebox/PhotoFriendUploader.h @@ -0,0 +1,16 @@ +// +// PhotoFriendUploader.h +// Trovebox +// +// Created by Patrick Santana on 06/05/14. +// Copyright (c) 2014 Trovebox. All rights reserved. +// + +#import + +@interface PhotoFriendUploader : NSObject + + +- (void) loadDataAndSaveEntityUrl:(NSString *) url; + +@end diff --git a/Trovebox/PhotoFriendUploader.m b/Trovebox/PhotoFriendUploader.m new file mode 100644 index 0000000..d1b1191 --- /dev/null +++ b/Trovebox/PhotoFriendUploader.m @@ -0,0 +1,43 @@ +// +// PhotoFriendUploader.m +// Trovebox +// +// Created by Patrick Santana on 06/05/14. +// Copyright (c) 2014 Trovebox. All rights reserved. +// + +#import "PhotoFriendUploader.h" + +@implementation PhotoFriendUploader + + +- (void) loadDataAndSaveEntityUrl:(NSString *) url +{ + //in the main queue, generate TimelinePhotos + dispatch_async(dispatch_get_main_queue(), ^{ + @autoreleasepool{ + + // data to be saved in the database + Timeline *uploadInfo = [NSEntityDescription insertNewObjectForEntityForName:@"Timeline" + inManagedObjectContext:[SharedAppDelegate managedObjectContext]]; + + // details form this upload + uploadInfo.date = [NSDate date]; + uploadInfo.dateUploaded = [NSDate date]; + uploadInfo.facebook = [NSNumber numberWithBool:NO]; + uploadInfo.twitter = [NSNumber numberWithBool:NO]; + uploadInfo.permission = [NSNumber numberWithBool:NO]; + uploadInfo.title = @""; + uploadInfo.tags=@""; + uploadInfo.albums=@""; + uploadInfo.status=kUploadStatusTypeCreated; + uploadInfo.userUrl = [SharedAppDelegate userHost]; + uploadInfo.photoToUpload = [NSNumber numberWithBool:YES]; + uploadInfo.photoUrl = url; + uploadInfo.copyFromFriend = [NSNumber numberWithBool:YES]; + uploadInfo.photoDataTempUrl=@""; + uploadInfo.fileName=@""; + } + }); +} +@end diff --git a/Trovebox/Timeline.h b/Trovebox/Timeline.h index a69ac1f..eae4b91 100644 --- a/Trovebox/Timeline.h +++ b/Trovebox/Timeline.h @@ -2,20 +2,8 @@ // Timeline.h // Trovebox // -// Created by Patrick Santana on 17/04/13. -// Copyright 2013 Trovebox -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Created by Patrick Santana on 06/05/14. +// Copyright (c) 2014 Trovebox. All rights reserved. // #import @@ -24,6 +12,7 @@ @interface Timeline : NSManagedObject +@property (nonatomic, retain) NSString * albums; @property (nonatomic, retain) NSDate * date; @property (nonatomic, retain) NSDate * dateUploaded; @property (nonatomic, retain) NSNumber * facebook; @@ -47,6 +36,6 @@ @property (nonatomic, retain) NSString * title; @property (nonatomic, retain) NSNumber * twitter; @property (nonatomic, retain) NSString * userUrl; -@property (nonatomic, retain) NSString * albums; +@property (nonatomic, retain) NSNumber * copyFromFriend; @end diff --git a/Trovebox/Timeline.m b/Trovebox/Timeline.m index 0c805f7..6bb3b5e 100644 --- a/Trovebox/Timeline.m +++ b/Trovebox/Timeline.m @@ -2,20 +2,8 @@ // Timeline.m // Trovebox // -// Created by Patrick Santana on 17/04/13. -// Copyright 2013 Trovebox -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Created by Patrick Santana on 06/05/14. +// Copyright (c) 2014 Trovebox. All rights reserved. // #import "Timeline.h" @@ -23,6 +11,7 @@ @implementation Timeline +@dynamic albums; @dynamic date; @dynamic dateUploaded; @dynamic facebook; @@ -46,6 +35,6 @@ @dynamic title; @dynamic twitter; @dynamic userUrl; -@dynamic albums; +@dynamic copyFromFriend; @end diff --git a/Trovebox/WebService.h b/Trovebox/WebService.h index fb08392..dbf771c 100644 --- a/Trovebox/WebService.h +++ b/Trovebox/WebService.h @@ -8,9 +8,9 @@ // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,10 +33,10 @@ } -- (id)initForServer:(NSString *) server - oAuthKey:(NSString *) oAuthKey - oAuthSecret:(NSString *) oAuthSecret - consumerKey:(NSString *) consumerKey +- (id)initForServer:(NSString *) server + oAuthKey:(NSString *) oAuthKey + oAuthSecret:(NSString *) oAuthSecret + consumerKey:(NSString *) consumerKey consumerSecret:(NSString *) consumerSecret; - (NSArray *) fetchNewestPhotosMaxResult:(int) maxResult; @@ -85,4 +85,5 @@ - (NSArray *) loadGallery:(int) pageSize onPage:(int) page forSite:(NSString*) site; - (NSArray *) loadGallery:(int) pageSize onPage:(int) page album:(Album*) album forSite:(NSString*) site; - (NSArray *) loadAlbums:(int) pageSize onPage:(int) page version:(NSString *) serverVersion forSite:(NSString*) site; +- (NSDictionary *) copyPictureWithUrl:(NSString*) photoUrl; @end diff --git a/Trovebox/WebService.m b/Trovebox/WebService.m index e677eac..efa54c6 100644 --- a/Trovebox/WebService.m +++ b/Trovebox/WebService.m @@ -172,6 +172,47 @@ [asiRequest setTimeOutSeconds:240]; [asiRequest startSynchronous]; + return [self parseResponseAsNSDictionary:asiRequest]; +}; + +- (NSDictionary *) copyPictureWithUrl:(NSString*) photoUrl +{ + [self validateCredentials]; + + NSMutableString *urlString = [NSMutableString stringWithFormat: @"%@/v1/photo/upload.json", self.server]; + NSURL *url = [NSURL URLWithString:urlString]; + + OAMutableURLRequest *oaUrlRequest = [self getUrlRequest:url]; + [oaUrlRequest setHTTPMethod:@"POST"]; + + // set the parameter to copy + NSArray *params = [NSArray arrayWithObjects:[[OARequestParameter alloc] initWithName:@"photo" + value:photoUrl], nil]; + [oaUrlRequest setParameters:params]; + + // prepare the request. This will be used to get the Authorization header and add in the multipart component + [oaUrlRequest prepare]; + + /* + * + * Using ASIHTTPRequest for Multipart. The authentication come from the OAMutableURLRequest + * + */ + ASIFormDataRequest *asiRequest = [ASIFormDataRequest requestWithURL:url]; + asiRequest.userAgentString=@"Trovebox iOS"; + + + // set the authorization header to be used in the OAuth + NSDictionary *dictionary = [oaUrlRequest allHTTPHeaderFields]; + [asiRequest addRequestHeader:@"Authorization" value:[dictionary objectForKey:@"Authorization"]]; + + // set the parameter already added in the signature + [asiRequest addPostValue:photoUrl forKey:@"photo"]; + + // timeout 4 minutes. TODO. Needs improvements. + [asiRequest setTimeOutSeconds:240]; + [asiRequest startSynchronous]; + return [self parseResponseAsNSDictionary:asiRequest]; }