Ospry 1.0.0

Ospry 1.0.0

测试已测试
语种语言 Obj-CObjective C
许可证 MIT
发布时间上次发布2014年12月

Ryan Brown维护。



Ospry 1.0.0

  • Ryan Brown

iOS 对 Ospry 图像托管 API 的绑定。在 ospry.io 上了解更多关于 Ospry 的信息。

关于

Ospry 允许开发者使用 Ospry 的图像托管服务上传、下载、删除和更改图像的权限。

使用您的公开 API 密钥上传和下载图像。

要求

要使用 Ospry,您必须有一个活跃的 Ospry 账户。在 ospry.io 上免费注册一个。

每个账户都包含一对开发用的公开/秘密密钥“沙盒”,当您准备上线时,还将有一组生产密钥。

安装

将以下内容添加到您的 Podfile

pod 'Ospry', '~> 1.0'

然后安装 Ospry 及其依赖项。

pod install

或者,您也可以将源文件复制到您的项目中,但请确保同时获取依赖项。

设置 API 密钥

您可以通过这种方式设置默认客户端使用 的 API 密钥

[Ospry setKey:@"YOUR-PUBLIC-KEY"];

图像上传

uploadAssetWithURL:isPrivate:complete

使用指定的资产和隐私设置将图像上传到 Ospry。

示例

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Assuming image is picked from photo library.
    NSURL *assetURL = [info valueForKey:UIImagePickerControllerReferenceURL];
    [Ospry uploadAssetWithURL:assetURL
                    isPrivate:false
                     complete:^(OSPMetadata *metadata, NSError *error) {
        if (error != nil) {
            NSLog(@"%@", error);
            return;
        }
        NSLog(@"received metadata: %@", metadata);
    }];
}

参数

  • url (NSURL*): 从 ALAssetsLibrary 或 UIImagePickerController 获得的资产 URL。
  • isPrivate (BOOL): 上传图像的隐私设置。
  • complete (OSPMetadataBlock): 在上传尝试完成后调用的回调。回调接收一个 OSPMetadata 和一个 NSError

uploadFileAtPath:isPrivate:complete

使用指定的文件和隐私设置将图像上传到 Ospry。

示例

[Ospry uploadFileAtPath:imageFilePath
              isPrivate:NO
               complete:^(OSPMetadata *metadata, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    NSLog(@"received metadata: %@", metadata);
}];

参数

  • path (NSString*): 文件路径。
  • isPrivate (BOOL): 上传图像的隐私设置。
  • complete (OSPMetadataBlock): 在上传尝试完成后调用的回调。回调接收一个 OSPMetadata 和一个 NSError

uploadUIImage:format:filename:isPrivate:complete

使用指定的格式、文件名和隐私设置将 UIImage 上传到 Ospry。

示例

[Ospry uploadUIImage:image
              format:kOSPUploadFormatJPEG
            filename:@"foo.jpg"
           isPrivate:NO
            complete:^(OSPMetadata *metadata, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    NSLog(@"received metadata: %@", metadata);
}];

参数

  • image (UIImage*): 图像。
  • format (OSPUploadFormat): 所需的图像格式(例如 jpeg)。
  • filename (NSString*): 所需的文件名。
  • isPrivate (BOOL): 上传图像的隐私设置。
  • complete (OSPMetadataBlock): 在上传尝试完成后调用的回调。回调接收一个 OSPMetadata 和一个 NSError

uploadCGImage:format:filename:isPrivate:complete

使用指定的格式、文件名和隐私设置,将CGImageRef上传到Ospry。

示例

[Ospry uploadCGImage:image
              format:kOSPUploadFormatJPEG
            filename:@"foo.jpg"
           isPrivate:NO
            complete:^(OSPMetadata *metadata, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    NSLog(@"received metadata: %@", metadata);
}];

参数

  • image (CGImageRef):图像。
  • format (OSPUploadFormat): 所需的图像格式(例如 jpeg)。
  • filename (NSString*): 所需的文件名。
  • isPrivate (BOOL): 上传图像的隐私设置。
  • complete (OSPMetadataBlock): 在上传尝试完成后调用的回调。回调接收一个 OSPMetadata 和一个 NSError

uploadData:filename:isPrivate:complete

使用指定的文件名和隐私设置,将NSData上传到Ospry。

示例

[Ospry uploadData:data
         filename:@"foo.jpg"
        isPrivate:NO
         complete:^(OSPMetadata *metadata, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    NSLog(@"received metadata: %@", metadata);
}];

参数

  • data (NSData *):作为NSData的图像。
  • filename (NSString*): 所需的文件名。
  • isPrivate (BOOL): 上传图像的隐私设置。
  • complete (OSPMetadataBlock): 在上传尝试完成后调用的回调。回调接收一个 OSPMetadata 和一个 NSError

图像下载

downloadToFileAtPath:url:opts:complete

将图像下载到文件。

示例

NSDictionary *opts = @{@"maxWidth": @(400)};
[Ospry downloadToFileAtPath:dst
                        url:metadata.url
                       opts:opts
                   complete:^(NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    // Do something with the file.
}];

参数

  • path (NSString *):存储图像的文件路径。
  • url (NSString *):图像URL。
  • opts (NSDictionary *):下载选项,参考formatURL:opts
  • complete (OSPCompleteBlock):上传尝试完成后调用的回调。回调接收一个NSError

downloadUIImageWithURL:opts:complete

将图像下载到UIImage。

示例

NSDictionary *opts = @{@"maxWidth": @(400)};
[Ospry downloadUIImageWithURL:metadata.url
                         opts:opts
                     complete:^(UIImage *image, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    // Do something with the UIImage.
}];

参数

  • url (NSString *):图像URL。
  • opts (NSDictionary *):下载选项,参考formatURL:opts
  • complete (OSPUIImageBlock):上传尝试完成后调用的回调。回调接收一个UIImage和一个NSError

downloadCGImageWithURL:opts:complete

将图像下载到CGImageRef。

示例

NSDictionary *opts = @{@"maxWidth": @(400)};
[Ospry downloadCGImageWithURL:metadata.url
                         opts:opts
                     complete:^(CGImageRef image, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    // Do something with the CGImageRef.
}];

参数

  • url (NSString *):图像URL。
  • opts (NSDictionary *):下载选项,参考formatURL:opts
  • complete (OSPCGImageBlock):上传尝试完成后调用的回调。回调接收一个CGImageRef和一个NSError

downloadDataWithURL:opts:complete

将图像下载到NSData。

示例

NSDictionary *opts = @{@"maxWidth": @(400)};
[Ospry downloadDataWithURL:metadata.url
                      opts:opts
                  complete:^(NSData *data, NSString *contentType, NSError *error) {
    if (error != nil) {
        NSLog(@"%@", error);
        return;
    }
    // Do something with the NSData.
}];

参数

  • url (NSString *):图像URL。
  • opts (NSDictionary *):下载选项,参考formatURL:opts
  • complete (OSPDataBlock):上传尝试完成后调用的回调。回调接收一个NSData、一个NSString mime 类型和一个NSError

引用

图像元数据

在回调中接收metadata对象的回调可以期望以下格式

@interface OSPMetadata : NSObject

@property (nonatomic) NSString *identifier;     // image ID
@property (nonatomic) NSString *url;            // download URL
@property (nonatomic) NSString *httpsURL;       // https download url
@property (nonatomic) NSDate   *timeCreated;    // upload time
@property (nonatomic) BOOL     isClaimed;       // whether the image has been claimed
@property (nonatomic) BOOL     isPrivate;       // whether the image is private
@property (nonatomic) NSString *filename;       // image's filename
@property (nonatomic) NSString *format;         // e.g. "jpeg"
@property (nonatomic) int64_t  size;            // file size in bytes
@property (nonatomic) int      height;          // height in pixels
@property (nonatomic) int      width;           // width in pixels

@end