cloudrail-si-ios-sdk 5.13.0

cloudrail-si-ios-sdk 5.13.0

许可证 未知
发布最新发布2018年9月

Felipe Cesar AssisPatrick StoklasaMujtaba Alam 维护。



CloudRail SI for iOS

通过一个 API 集成多种服务

CloudRail 是一个 API 集成解决方案,它将多个提供商的多个 API 抽象为单一通用接口。

当前接口

--- ---

CocoaPods CocoaPods

完整的文档可以在我们的 网站 上找到。

https://cloudrail.com 上了解更多关于 CloudRail 的信息



使用 CloudRail,您可以轻松地将外部 API 集成到应用程序中。CloudRail 提供了抽象的接口,它将多个服务和暴露一个开发者友好的 API,该 API 使用所有提供商之间的常见功能。这意味着例如,upload() 在 Dropbox 和 Google Drive、OneDrive 及其他云存储服务上以完全相同的方式工作,而 getEmail() 在所有社交网络上也以类似的方式工作。

CocoaPods

将 pod 添加到您的 podfile

pod 'cloudrail-si-ios-sdk'

运行

pod install

基本设置

在 Project Navigator 中,打开您的应用程序代理的源文件。在文件顶部添加导入语句,然后在您的应用程序代理的 didFinishLaunching 或 didFinishLaunchingWithOptions 方法中添加以下调用 CloudRail 的调用。

Objective-C

#import <CloudRailSI/CloudRailSI.h>

[CRCloudRail setAppKey:@"{Your_License_Key}"];

Swift

import CloudrailSI

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
SMS Twilio、Nexmo
兴趣点 Google 地点、Foursquare、Yelp
视频 YouTube、Twitch、Vimeo
消息 Facebook Messenger、Telegram、Line、Viber

云存储接口

  • Dropbox
  • Box
  • Google Drive
  • Microsoft OneDrive
  • PCloud
  • Egnyte
  • OneDrive Business

功能

  • 从云存储下载文件。
  • 将文件上传到云存储。
  • 获取文件和文件夹的元数据,并对它们执行所有标准操作(复制、移动等)。
  • 检索用户和配额信息。
  • 生成文件和文件夹的分享链接。

代码示例 - Objective-C

完整文档

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

代码示例 - Swift

完整文档

//let cloudStorage : CloudStorageProtocol = Box.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = GoogleDrive.init(clientId: "ClientID", clientSecret: "", redirectUri: "[redirectUri]", state: "[state]")
//let cloudStorage : CloudStorageProtocol = OneDrive.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = PCloud.init(clientId: "ClientID", clientSecret: "ClientSecret")

let cloudStorage : CloudStorageProtocol = Dropbox.init(clientId: "ClientID", clientSecret: "ClientSecret")
do {
  let inputStream = try cloudStorage.downloadFileWithPath("/TestFolder/Data.csv")
} catch let error{
  print("An error: \(error)")
}
//READ FROM STREAM

商业/桶云存储接口

  • 亚马逊网络服务S3
  • 微软Azure
  • Rackspace
  • Backblaze

特性

  • 创建、删除和列出存储桶
  • 上传文件
  • 下载文件
  • 列出桶中的文件并删除文件
  • 获取文件元数据(最后修改时间、大小等)

代码示例 - Objective-C

完整文档

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
}

代码示例 - Swift

完整文档

//let cloudStorage : BusinessCloudStorageProtocol = Backblaze.init(accountID: "[account_id]", appKey: "[app_key]")
//let cloudStorage : BusinessCloudStorageProtocol = Rackspace.init(username: "[username]", apiKey: "[api_key]", region: "[region]")
//let cloudStorage : BusinessCloudStorageProtocol = MicrosoftAzure.init(accountName: "[account_name]", accessKey: "access_key")
let cloudStorage : BusinessCloudStorageProtocol = AmazonS3.init(accessKeyId: "[access_key]", secretAccessKey: "[secret_key]", region: "[region]")

let bucket : CRBucket = CRBucket.init()
bucket.name = "[bucketName]";
bucket.identifier = "[identifier]"

let path = Bundle.main.path(forResource: "UserData", ofType: "csv")!
let fileAttributes = try! FileManager.default.attributesOfItem(atPath: path)
let fileSize: UInt64 = fileAttributes[FileAttributeKey.size] as! UInt64
let stream = InputStream.init(fileAtPath: path)!

do {
  try cloudStorage.uploadFileToBucket(bucket, name: "[fileName]", stream: stream, size:fileSize)
} catch let error{
  print("An error: \(error)")
}

社交媒体资料界面

  • Facebook
  • Github
  • Google Plus
  • LinkedIn
  • Slack
  • Twitter
  • Windows Live
  • Yahoo
  • Instagram
  • Heroku

功能

  • 获取资料信息,包括全名、电子邮件、性别、出生日期和地区。
  • 检索资料照片。
  • 使用社交网络登录。

代码示例 - Objective-C

完整文档

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];

代码示例 - Swift

完整文档

// let profile = GitHub(clientID: "[clientID]", clientSecret: "[clientSecret]")
// let profile = GooglePlus(clientID: "[clientID]", clientSecret: "[clientSecret]")
// let profile = Instagram(clientID: "[clientID]", clientSecret: "[clientSecret]")
// let profile = Slack(clientID: "[clientID]", clientSecret: "[clientSecret]")

let profile = Facebook(clientID: "[clientID]", clientSecret: "[clientSecret]")
do {
  let fullName = try profile.fullName()
} catch let error{
  print("An error: \(error)")
}

社交媒体互动接口

  • Facebook
  • Twitter

功能

  • 获取联系人列表。
  • 为用户发表帖子。

代码示例 - Objective-C

完整文档

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!"];

代码示例 - Swift

完整文档

// let social = Twitter(clientID: "[clientID]", clientSecret: "[clientSecret]")

let social = Facebook(clientID: "[clientID]", clientSecret: "[clientSecret]")
do {
  try social.postUpdateWithContent("CloudRail is awesome!!!")
} catch let error{
  print("An error: \(error)")
}

支付接口

  • PayPal
  • Stripe

功能界面

  • 执行交易
  • 退款已完成的交易
  • 管理订阅

代码示例 - Objective-C

完整文档

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);

代码示例 - Swift

完整文档

let payment = PayPal(useSandbox: [true/false], clientId: "[clientID]")
do {
  let subscriptionPlan : CRSubscriptionPlan = try payment.createSubscriptionPlanWithName("My subscription", amount: 500, currency: "USD", description: "myDescription", interval: "week", intervalCount: 2)
} catch let error{
  print("An error: \(error)")
}

电子邮箱界面

  • Mailjet
  • Sendgrid
  • Gmail

功能

  • 发送电子邮件

代码示例 - Objective-C

完整文档

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];

代码示例 - Swift

完整文档

var service: EmailProtocol;

// service = SendGrid(apiKey: "[SendGrid API Key]")
// service = GMail(clientID: "[GMail Client Identifier]",clientSecret: "",redirectUri: "com.cloudrail.example:/auth",state: "someState")
// service.useAdvancedAuthentication() //required for Gmail

service = MailJet(clientID: "[clientID]", clientSecret:"[accountSid]")

let attachImage = CRAttachment()
attachImage.content = InputStream
attachImage.mimeType = "image/jpg"
attachImage.filename = "File.jpg"

var attachments = [CRAttachment]()
attachments.append(attachImage)


do {
  try service.sendEmailFromAddress("[email protected]", fromName: "CloudRail", toAddresses:NSMutableArray(array:  ["[email protected]","[email protected]"]), subject: "my subject", textBody: "text body", htmlBody: "Html body", ccAddresses: NSMutableArray(array:  ["[email protected]","[email protected]"]), bccAddresses: NSMutableArray(array:  ["[email protected]","[email protected]"])  attachments: attachments)
} catch let error{
  print("An error: \(error)")
}

SMS接口

  • Twilio
  • Nexmo
  • Twizo

功能

  • 发送短信

代码示例 - Objective-C

完整文档

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"];

代码示例 - Swift

完整文档

// let sms = Nexmo(accountSid: "[clientID]", authToken: "[authToken]")

let sms = Twilio(accountSid: "[clientID]", authToken: "[authToken]")
do {
  try sms.sendSmsFromName("CloudRail", toNumber: "+491234567890", content: "Hello from CloudRail")
} catch let error{
  print("An error: \(error)")
}

兴趣点界面

  • 谷歌地点
  • 四方形
  • 必应

功能

  • 获取附近POI列表
  • 按类别或搜索词过滤

代码示例 - Objective-C

完整文档

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 =  [service nearbyPoisWithLatitude:@49.483927 longitude:@8.473272 radius:@300 searchTerm:[NSNull null] categories:[NSNull null]];

NSLog(@"%@", pois);

代码示例 - Swift

完整文档

// let points = GooglePlaces(apiKey: "[secretKey]")

let points = Foursquare(clientID: "[cientID]", clientSecret: "[clientSecret]")
do {
  //Mannheim : 49.483927, 8.473272
  var points = try places.nearbyPoisWithLatitude(49.483927, longitude: 8.473272, radius: 3000, searchTerm: "Restaurant", categories: [])
} catch let error{
  print("An error: \(error)")
}

视频界面

  • 油管
  • 暴雪
  • 维珍妮

功能

  • 搜索视频
  • 上传视频
  • 获取频道视频列表
  • 获取频道详情
  • 获取您的频道详情
  • 获取视频详情

代码示例 - 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);

代码示例 - Swift

完整文档

var service: VideoProtocol

// service = Twitch(clientId: "[Twitch Client Identifier]",clientSecret: "[Twitch Client Secret]")
// service = Vimeo(clientId: "[Vimeo Client Identifier]",clientSecret: "[Vimeo Client Secret]")

service = YouTube(clientId: "[YouTube Client Identifier]",clientSecret: "",redirectUri: "com.cloudrail.example:/auth",state: "someState")
service.useAdvancedAuthentication(); //required for Youtube

do {
   
   let searchResult = service.searchVideos(query: "CloudRail",offset: 0,limit: 12)
   print(searchResult)
   
   let uploadResult = service.uploadVideo(title: "HowTo: Setup CloudRail", description: "Video about Setting up CloudRail", stream: InputStream, size: 1448576, channelId: "70207321", mimeType: "video/mp4") //Channel id optional for youtube
   
   print(uploadResult)
   
} catch let error{
  print("An error: \(error)")
}

消息接口

  • FacebookMessenger
  • 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);

代码示例 - Swift

完整文档

var service: MessagingProtocol

// service = Viber(botToken: "[Bot Token]",webhook: "[Webhook URL]",botName: "[Bot Name]")
// service = Telegram(botToken: "[Bot Token]",webhook: "[Webhook URL]")
// service = Line(botToken: "[Bot Token]")

service = FacebookMessenger(botToken: "[Bot Token]")

do {
   
   var result = service.sendMessageWithReceiverId(
    receiverId: "12123242",
    message: "It's so easy to send message via CloudRail")
   
   print(result)
   
} catch let error{
  print("An error: \(error)")
}

更多接口即将推出。

使用 CloudRail 的优势

  • 一致的接口:由于函数在所有服务上工作方式一致,因此您可以直接在服务之间执行任务。

  • 简单认证:CloudRail 包括简单的认证方式,以解决编码外部 API 时的最大烦恼之一。

  • 立即切换服务:只需一行代码即可设置您正在使用的服务。更改服务与更改您想要使用的服务名称一样简单。

  • 简洁的文档:无需在 Stack Overflow 上四处搜寻答案。CloudRail 文档位于 https://cloudrail.com/integrations,定期更新,且易于使用。

  • 无需维护时间:当提供商更改其 API 时,CloudRail 库会自动更新。

  • 直接数据:所有操作都在库中直接进行。数据永远不会通过 CloudRail 服务器传递。

与 Cocoapods(Swift & Objective-C)集成

CloudRail-SI-iOS 通过 CocoaPods 提供。要安装它,请简单地将以下行添加到您的 Podfile 中(请记住在 Podfile 的顶部放置 use_frameworks! 标志)

pod "cloudrail-si-ios-sdk"

再次运行 Pod install

Swift

  • 在 swift 文件(类、协议等)中使用 import CloudrailSI 导入模块。

Objective-C

  • 使用 #import <CloudRailSI/CloudRailSI.h> 在所需的类中导入框架。

在不使用 Cocoapods 的情况下集成到项目中

Swift (使用 Swift 接口)

  1. 将框架文件拖放到 iOS 项目的“嵌入式二进制文件”中,如果需要,请勾选“复制文件”。
  2. 您可以在 Swift 文件(类、协议等)中使用 import CloudrailSI 导入模块。

Swift (使用 Objective-C 接口)

  1. 向您的项目中添加一个新的 Objective-C 文件(任何文件都行),Xcode 会提示是否要使用桥接头配置您的项目(PROJECTNAME-Bridging-Header.h),在提示时请按 。(如果您无法添加桥接头,请使用此指南
  2. 将框架文件拖放到 iOS 项目的“嵌入式二进制文件”中,如果需要,请勾选“复制文件”。
  3. Xcode 将为您生成并配置文件,在文件中您需要使用(在 Objective-C 方式)导入 <#import “CloudRailSI/CloudRailSI.h”

Objective-C

只需将框架文件拖放到 iOS 项目的“嵌入式二进制文件”中,如果需要,请勾选“复制文件”。使用 <#import “CloudRailSI/CloudRailSI.h” 在所需类中导入框架,然后开始享受编程之趣!

开始实现

现在您已经设置好了一切,您可以通过查看 [[用法]] 或 [[Swift 用法]] 来了解如何使用 CloudRail。

其他代码示例

Swift

//let cloudStorage : CloudStorageProtocol = Box.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = GoogleDrive.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = OneDrive.init(clientId: "ClientID", clientSecret: "ClientSecret")
let cloudStorage : CloudStorageProtocol = Dropbox.init(clientId: "ClientID", clientSecret: "ClientSecret")
CRCloudRail.setAppKey("CLOUDRAIL_API_KEY")

do {
  let inputStream = try cloudStorage.downloadFileWithPath("/TestFolder/Data.csv")
} catch let error{
  print("An error: \(error)")
}

Objective C

#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"];

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问题