- iOS 9.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
- Xcode 8.0+
- Swift 3.0+
The recommended way to install this framework is via Carthage.
Add the following to your Cartfile:
github "ringcentral/ringcentral-swift-client"
Given any API endpoint, taking /restapi/v1.0/account/~/extension/~/call-log
for example.
You can build its url with code easily:
let restapiVersion = "v1.0"
let accountID = "~"
let extensionId = "~"
rc.restapi(restapiVersion).account(accountID).extension(extensionId).callLog()
"/restapi" + restapiVersion + "/account/" + accountID + "/extension/" + extensionId + "/call-log"
let rc = RestClient(appKey: "", appSecret: "", production: false)
rc.authorize("username", ext: "", password: "password") { token, error in
if error == nil {
print("Authorized!")
}
}
By default, there is a background timer calling rc.refresh()
periodically, so the authorization never expires.
But if you would like to call refresh manually: rc.autoRefreshToken = false
When you no longer need the token, don't forget to revoke it: rc.revoke()
.
// /restapi/v1.0/account/~/extension/~/address-book
let addressBook = rc.restapi("v1.0").account("~").extension("~").addressBook()
addressBook.contact().list() { list, error in
print(list!.paging!.page) // 1
}
addressBook.contact().post(parameters: [ "firstName": "Tyler", "lastName": "Long", "homePhone": phoneNumber ]) { contact, error in
print(contact!.lastName) // Long
}
addressBook.contact("\(contact.id!)").get(){ contact, error in
print(contact.lastName) // Long
}
contact.lastName = "Liu"
addressBook.contact("\(contact.id!)").put(parameters: contact.toParameters()) { contact2, error in
print(contact2.lastName) // Liu
}
addressBook.contact("\(item.id!)").delete() { error in
print(error == nil) // true
}
let parameters = SmsPath.PostParameters(
from: CallerInfo(phoneNumber: "123456789"),
to: [CallerInfo(phoneNumber: "123456789")],
text: "hello world"
)
rc.restapi().account().extension().sms().post(parameters: parameters) { messageInfo, error in
if error == nil {
print("SMS sent!")
}
}
let subscription = rc.restapi().subscription().new()
subscription.eventFilters.append("/restapi/v1.0/account/~/extension/~/message-store")
subscription.eventFilters.append("/restapi/v1.0/account/~/extension/~/presence?detailedTelephonyState=true")
subscription.listeners.append { notification in
print(notification.json!)
switch notification.type! {
case .Message:
let messageNotification: MessageNotification = notification.downcast()!
print(messageNotification.body!.extensionId!)
break
case .DetailedPresence:
let detailedPresenceNotification: DetailedPresenceNotification = notification.downcast()!
print(detailedPresenceNotification.body!.extensionId!)
break
default:
break
}
}
When you no longer need a subscription, don't forget to remove it:
subscription.remove()
let parameters = FaxPath.PostParameters(to: [CallerInfo(phoneNumber: "1234567890")])
var attachments: [Attachment] = []
attachments.append(Attachment(fileName: "test.pdf", contentType: "application/pdf", data: pdfData))
rc.restapi().account().extension().fax().post(parameters: parameters, attachments: attachments) { messageInfo, error in
if error == nil {
print("fax sent")
}
}
rc.restapi().account().extension().profileImage().put(imageData: imageData, imageFileName: "test.png") { error in
if error == nil {
print("Profile image updated")
}
}
The test cases contain lots of sample code.
This project is released under the MIT license.