CloudRail SI for iOS
通过一个 API 集成多个服务
CloudRail 是一个 API 集成解决方案,它将来自不同提供商的多个 API 抽象成一个单一且通用的接口。
当前接口
---有关完整文档,请访问我们的 网站。
在 https://cloudrail.com 了解更多关于 CloudRail 的信息
使用 CloudRail,您可以将外部 API 简单地集成到您的应用程序中。CloudRail 提供了抽象化的接口,这些接口可以处理多台服务,然后暴露一个面向开发的 API,该 API 使用所有提供商之间的公共功能。这意味着例如,upload() 函数在 Dropbox 和 Google Drive、OneDrive 以及其他云存储服务中的工作方式完全相同,同样,getEmail() 在所有社交网络中的工作方式也相似。
CocoaPods
将 pod 添加到 Podfile 中
pod 'cloudrail-si-objc-sdk'
运行
pod install
基本设置
在项目导航器中打开您的应用程序代理源文件。在文件顶部添加导入语句,然后在应用程序代理的 didFinishLaunching 或 didFinishLaunchingWithOptions 方法中调用以下 CloudRail
#import <CloudRailSI/CloudRailSI.h>
[CRCloudRail setAppKey:@"{Your_License_Key}"];
当前接口
接口 | 包含的服务 |
---|---|
云存储 | Dropbox、Google Drive、OneDrive、Box、PCloud、Egnyte、OneDrive Business |
企业云存储 | Amazon S3、Microsoft Azure、Rackspace、Backblaze |
社交媒体个人资料 | Facebook、GitHub、Google+、LinkedIn、Slack、Twitter、Windows Live、Yahoo、Instagram、Heroku |
社交互动 | Facebook、Twitter |
支付 | PayPal、Stripe |
电子邮件 | Maljet、Sendgrid、Gmail |
短信 | Twilio、Nexmo |
兴趣点 | Google Places、Foursquare、Yelp |
视频 | YouTube、Twitch、Vimeo |
消息 | Facebook Messenger、Telegram、Line、Viber |
云存储接口
- Dropbox
- Box
- Google Drive
- Microsoft OneDrive
- PCloud
- Egnyte
- OneDrive Business
功能
- 从云存储下载文件。
- 上传文件到云存储。
- 获取文件的元数据,文件夹的信息,并执行所有标准操作(复制、移动等)。
- 检索用户配额信息。
- 为文件和文件夹生成共享链接。
代码示例
id<CRCloudStorageProtocol> service;
// service = [[CROneDrive alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
// service = [[CRGoogleDrive alloc] initWithClientId:@"clientIdentifier" clientSecret:@"" redirectUri:@"REDIRURL" state:@"CRSTATE"];
// service = [[CRBox alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
// service = [[CRPCloud alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
service = [[CRDropbox alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
NSInputStream * object = [service downloadFileWithPath:@"/mudkip.jpg"];
//READ FROM STREAM
企业/桶云存储接口
- Amazon Web Services S3
- Microsoft Azure
- Rackspace
- Backblaze
功能
- 创建、删除和列出存储桶
- 上传文件
- 下载文件
- 列出存储桶中的文件和删除文件
- 获取文件元数据(最后修改时间、大小等)
代码示例
id<CRBusinessCloudStorageProtocol> service;
// service = [[CRMicrosoftAzure alloc] initWithAccountName:@"[account_name]" accessKey:@"[access_key]"];
// service = [[CRAmazonS3 alloc] initWithAccessKeyId:@"[clientID]" secretAccessKey:@"[client_Secret]" region:@"[region]"];
// service = [[CRRackspace alloc] initWithUsername:@"[username]" apiKey:@"[api_key]" region:@"[region]"];
service = [[CRBackblaze alloc] initWithAccountID:@"[account_init]" appKey:@"[app_key]"];
CRBucket * bucket = [[CRBucket alloc] init];
bucket.name = @"[bucket_name]";
bucket.identifier = @"[bucket_id]";
NSData * data = //data source;
NSInputStream * inputStream = [NSInputStream inputStreamWithData:data];
@try {
[service uploadFileToBucket:bucket name:@"[file_name]" withStream:inputStream size:data.length];
} @catch (NSException *exception) {
//handle exception
}
社交媒体个人资料界面
- Github
- Google Plus
- Slack
- Windows Live
- Yahoo
- Heroku
功能
- 获取个人资料信息,包括全名、电子邮件、性别、出生日期和地区。
- 检索个人资料图片。
- 使用社交媒体进行登录。
代码示例
id<CRProfileProtocol> service;
// service = [[CRGitHub alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
// service = [[CRInstagram alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
// service = [[CRSlack alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
// service = [[CRGooglePlus alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
service = [[CRFacebook alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
NSString * fullName = [service fullName];
社交媒体交互界面
功能
- 获取连接列表。
- 为用户发表帖子。
代码示例
id<CRSocialProtocol> service;
// service = [[CRTwitter alloc] initWithClientIdentifier:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL"];
service = [[CRFacebook alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"REDIRURL" state:@"CRSTATE"];
[service postUpdateWithContent:@"Using Cloudrail sdk!"];
支付接口
- PayPal
- Stripe
功能接口
- 执行费用
- 退款之前的费用
- 管理订阅
代码示例
id<CRPaymentProtocol> service;
// service = [[CRPayPal alloc] initWithUseSandbox:YES clientId:@"key" clientSecret:@"secret"];
service = [[CRStripe alloc] initWithSecretKey:@"key"];
SubscriptionPlan * subPlan = [service createSubscriptionPlanWithName:@"Plan name" amount:@2000 currency:@"USD" description:@"description" Longerval:@"day" Longerval_count:@7];
NSLog(@"Sub plan %@", subPlan);
邮件接口
- Mailjet
- Sendgrid
- Gmail
功能
- 发送电子邮件
代码示例
id<CREmailProtocol> service;
// service = [[CRMailJet alloc] initWithClientId:@"key" clientSecret:@"secret"];
// service = [[CRGMail alloc] initWithClientID:@"[GMail Client Identifier]" clientSecret:@"" redirectUri:@"com.cloudrail.example:/auth" state:@"someState"];
//[service useAdvancedAuthentication]; //required for Gmail
service = [[CRSendGrid alloc]initWithUsername:@"key" password:@"secret"];
CRAttachment *attachImage = [[CRAttachment alloc] initWithContent:NSInputStream type:"image/jpg" name:"fileName"];
NSMutableArray *attachments = [[NSMutableArray alloc] init];
[attachments addObject:attachImage];
[service sendEmailFromAddress:@"[email protected]" fromName:@"Bob" toAddresses:[@[@"[email protected]",@"[email protected]"] mutableCopy] subject:@"Mailjet and SendGrid" textBody:@"The Mailjet and Sendgrid is on cloudrail now!!!" htmlBody:@"" ccAddresses:[@[]mutableCopy] bccAddresses:[@[] mutableCopy], attachments:attachments];
SMS接口
- Twilio
- Nexmo
- Twizo
功能
- 发送短信
代码示例
id<CRSMSProtocol> service;
//service = [[CRNexmo alloc] initWithClientId:@"key" clientSecret:@"secret"];
service = [[CRTwilio alloc] initWithAccountSid:@"key" authToken:@"secret"];
[service sendSmsFromName:@"from Code" toNumber:@"+12323423423" content:@"Testing message"];
兴趣点接口
- Google 地点
- Foursquare
- Yelp
功能
- 获取附近的POI列表
- 按照分类或搜索词筛选
代码示例
id<CRPointsOfInterestProtocol> service;
// service = [[CRYelp alloc] initWithConsumerKey:@"key" consumerSecret:@"secret" token:@"token" tokenSecret:@"tokensecret"];
// service = [[CRGooglePlaces alloc] initWithApiKey:@"apiKey"];
service = [[CRFoursquare alloc] initWithClientId:key clientSecret:secret];
NSMutableArray<POI*>* pois = [self.service nearbyPoisWithLatitude:@49.483927 longitude:@8.473272 radius:@300 searchTerm:[NSNull null] categories:[NSNull null]];
NSLog(@"%@", pois);
视频界面
- YouTube
- Twitch
- Vimeo
功能
- 搜索视频
- 上传视频
- 获取频道的视频列表
- 获取频道详情
- 获取您的频道详情
- 获取视频详情
代码示例 - Objective-C
id<CRVideoProtocol> service;
// service = [[CRTwitch alloc] initWithClientId:@"[Twitch Client Identifier]" clientSecret:@"[Twitch Client Secret]"];
// service = [[CRVimeo alloc] initWithClientId:@"[Vimeo Client Identifier]" clientSecret:@"[Vimeo Client Secret]"];
service = [[CRYouTube alloc] initWithClientId:@"[YouTube Client Identifier]" clientSecret:@"" redirectUri:@"com.cloudrail.example:/auth" state:@"someState"];
[service useAdvancedAuthentication]; //required for Youtube
NSMutableArray<CRVideoMetaData *> * searchResult = [service searchVideosWithQueryQuery:@"CloudRail" offset:[NSNumber numberWithInt: 0] limit:[NSNumber numberWithInt: 12]];
NSLog(@"%@", searchResult);
CRVideoMetaData * uploadResult = [service uploadVideoWithTitleTitle:@"HowTo: Setup CloudRail"
description:@"Video about Setting up CloudRail"
stream:NSInputStream
size:[NSNumber numberWithInt: 1448576]
channelId:@"70207321"
mimeType:@"video/mp4"
]; //ChannelId optional for youtube
NSLog(@"%@", uploadResult);
消息界面
- Facebook Messenger
- Telegram
- Line
- Viber
功能
- 发送文本消息
- 发送文件、图片、视频和音频
- 解析在您的webhook上接收到的消息
- 下载发送到您的webhook的附件内容
代码示例 - Objective-C
id<CRMessagingProtocol> service;
// service = [[CRViber alloc] initWithBotToken:@"[Bot Token]" webhook:@"[Webhook URL]" botName:@"[Bot Name]"];
// service = [[CRTelegram alloc] initWithBotToken:@"[Bot Token]" webhook:@"[Webhook URL]"];
// service = [[CRLine alloc] initWithBotToken:@"[Bot Token]"];
service = [[CRFacebookMessenger alloc] initWithBotToken:@"[Bot Token]"];
CRMessage * result = [service sendMessageWithReceiverIdReceiverId:@"12123242"
message:@"It's so easy to send message via CloudRail"
];
NSLog(@"%@", result);
即将推出更多接口。
使用CloudRail的优点
-
统一的接口:由于功能在所有服务中工作方式相同,您可以在服务之间简单地执行任务。
-
易于认证:CloudRail包括简单的认证方式,这可以减少为外部API编写代码时最大的烦恼之一。
-
即时切换服务:只需一行代码即可设置您正在使用的服务。更改服务就像更改想要使用的服务的名称一样简单。
-
简单的文档:无需在Stack Overflow上四处寻找答案。CloudRail在https://cloudrail.com/integrations的文档定期更新,清洁且易于使用。
-
无需维护时间:当提供商更改其API时,CloudRail库会自动更新。
-
直接数据:所有操作都在库中直接发生。从不会有任何数据通过CloudRail服务器传输。
通过Cocoapods整合
通过Cocoapods提供的CloudRail-SI-iOS。要安装,只需在Podfile中添加以下行(请记住在Podfile中设置use_frameworks!标志):
pod 'cloudrail-si-objc-sdk'
再次运行Pod install
。
Objective-C
- 使用
#import <CloudRailSI/CloudRailSI.h>
将框架导入所需类中。
在没有Cocoapods的项目中整合
只需将框架文件拖放到iOS项目的"Embedded Binaries"中,如果需要,请勾选"copy files"。使用#import <CloudRailSI/CloudRailSI.h>
将框架导入所需类中,享受乐趣吧!
开始实施
现在您已经设置完毕,您可以前往 [[用法]] 了解如何使用 CloudRail。
其他代码示例
#import <CloudRailSI/CloudRailSI.h>
@interface CRViewController ()
@property (strong, nonatomic) CRDropbox * dropbox;
@property (strong, nonatomic) CRGoogleDrive * googleDrive;
//@property (strong, nonatomic) CROneDrive * oneDrive;
//@property (strong, nonatomic) CRBox * box;
@end
@implementation CRViewController
- (void)viewDidLoad {
[super viewDidLoad];
[CRCloudRail setAppKey:@"CLOUDRAIL_API_KEY"];
self.dropbox = [[CRDropbox alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"https://www.cloudrailauth.com/auth" state:@"CRSTATE"];
self.googleDrive = [[CRGoogleDrive alloc] initWithClientId:@"clientIdentifier" clientSecret:@"clientSecret" redirectUri:@"https://www.cloudrailauth.com/auth" state:@"CRSTATE"];
[self.googleDrive useAdvancedAuthentication]; //Required for Google Login
}
- (void)downloadAndUpload {
//Download File from Dropbox
NSInputStream * streamToDownloadedFile = [self.dropbox downloadFileWithPath:@"/mudkip.jpg"];
//Upload the downloaded file to Googledrive
[self.googleDrive uploadFileToPath:@"/mudkip.jpg" withStream:streamToDownloadedFile size:size overwrite:YES];
}
@end
许可证密钥
CloudRail 提供了开发者门户,提供 SDK 的使用洞察,并允许您生成许可证密钥。
注册并生成密钥都是免费的。
请访问 https://cloudrail.com/signup
价格
了解更多关于我们价格的信息,请访问 https://cloudrail.com/pricing
其他平台
CloudRail 还支持其他平台,如 Node.js、Java 和 Android。您可以在https://cloudrail.com找到所有库
有疑问?
您可以选择在任意时间通过给我们发送电子邮件来联系: [email protected]
或者
在适当的 StackOverflow 上标签为 cloudrail 的问题 StackOverflow