GTLRUploadParameters.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Copyright (c) 2011 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include <objc/runtime.h>
  16. //#import <GoogleAPIClientForREST/GTLRUploadParameters.h>
  17. #import "GTLRUploadParameters.h"
  18. @implementation GTLRUploadParameters
  19. @synthesize MIMEType = _MIMEType,
  20. data = _data,
  21. fileHandle = _fileHandle,
  22. uploadLocationURL = _uploadLocationURL,
  23. fileURL = _fileURL,
  24. shouldUploadWithSingleRequest = _shouldUploadWithSingleRequest,
  25. shouldSendUploadOnly = _shouldSendUploadOnly,
  26. useBackgroundSession = _useBackgroundSession;
  27. + (instancetype)uploadParametersWithData:(NSData *)data
  28. MIMEType:(NSString *)mimeType {
  29. GTLRUploadParameters *params = [[self alloc] init];
  30. params.data = data;
  31. params.MIMEType = mimeType;
  32. return params;
  33. }
  34. + (instancetype)uploadParametersWithFileHandle:(NSFileHandle *)fileHandle
  35. MIMEType:(NSString *)mimeType {
  36. GTLRUploadParameters *params = [[self alloc] init];
  37. params.fileHandle = fileHandle;
  38. params.MIMEType = mimeType;
  39. return params;
  40. }
  41. + (instancetype)uploadParametersWithFileURL:(NSURL *)fileURL
  42. MIMEType:(NSString *)mimeType {
  43. GTLRUploadParameters *params = [[self alloc] init];
  44. params.fileURL = fileURL;
  45. params.MIMEType = mimeType;
  46. return params;
  47. }
  48. - (id)copyWithZone:(NSZone *)zone {
  49. GTLRUploadParameters *newParams = [[[self class] allocWithZone:zone] init];
  50. newParams.MIMEType = self.MIMEType;
  51. newParams.data = self.data;
  52. newParams.fileHandle = self.fileHandle;
  53. newParams.fileURL = self.fileURL;
  54. newParams.uploadLocationURL = self.uploadLocationURL;
  55. newParams.shouldUploadWithSingleRequest = self.shouldUploadWithSingleRequest;
  56. newParams.shouldSendUploadOnly = self.shouldSendUploadOnly;
  57. newParams.useBackgroundSession = self.useBackgroundSession;
  58. return newParams;
  59. }
  60. #if DEBUG
  61. - (NSString *)description {
  62. NSMutableArray *array = [NSMutableArray array];
  63. NSString *str = [NSString stringWithFormat:@"MIMEType:%@", _MIMEType];
  64. [array addObject:str];
  65. if (_data) {
  66. str = [NSString stringWithFormat:@"data:%llu bytes",
  67. (unsigned long long)_data.length];
  68. [array addObject:str];
  69. }
  70. if (_fileHandle) {
  71. str = [NSString stringWithFormat:@"fileHandle:%@", _fileHandle];
  72. [array addObject:str];
  73. }
  74. if (_fileURL) {
  75. str = [NSString stringWithFormat:@"file:%@", [_fileURL path]];
  76. [array addObject:str];
  77. }
  78. if (_uploadLocationURL) {
  79. str = [NSString stringWithFormat:@"uploadLocation:%@",
  80. [_uploadLocationURL absoluteString]];
  81. [array addObject:str];
  82. }
  83. if (_shouldSendUploadOnly) {
  84. [array addObject:@"shouldSendUploadOnly"];
  85. }
  86. if (_shouldUploadWithSingleRequest) {
  87. [array addObject:@"uploadWithSingleRequest"];
  88. }
  89. if (_useBackgroundSession) {
  90. [array addObject:@"useBackgroundSession"];
  91. }
  92. NSString *descStr = [array componentsJoinedByString:@", "];
  93. str = [NSString stringWithFormat:@"%@ %p: {%@}",
  94. [self class], self, descStr];
  95. return str;
  96. }
  97. #endif // DEBUG
  98. @end