Skip to content

grokify/ringcentral-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RingCentral Swift SDK ( Beta )

Build Status codecov.io MIT licensed Gem Version Version Platform Code Climate


  1. Getting Started
  2. Initialization
  3. Authorization
  4. Performing API Call
  5. Performing RingOut
  6. Sending SMS
  7. Subscription
  8. SDK Demos


Requirements

  • iOS 8.0+
  • Xcode 6.3+
  • Swift 1.2

Getting Started

CocoaPods (recommended)

The RingCentral Swift SDK is a CocoaPod written in Swift. CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate RingCentral Swift SDK into your Xcode project, navigate to the directory that contains your project and create a new Podfile with pod init or open an existing one, then add the following line:

platform :ios, '8.0'
use_frameworks!

pod 'ringcentral'

Then, run the following command to install the dependency:

$ pod install

If you do not Use CocoaPods, manually Add Subprojects

You can integrate RingCentral Swift SDK into your project manually without using a dependency manager.

Drag the src project into your own and add the resource as an Embedded Binary, as well as a Target Dependency and Linked Framework (under Build Phases) in order to build on the simulator and on a device.

Manually Install Framework

Initialization

The RingCentral SDK is initiated in the following ways.

Sandbox:

    var rcsdk = SDK(appKey: app_key, appSecret: app_secret, server: SDK.RC_SERVER_SANDBOX)

Production:

    var rcsdk = SDK(appKey: app_key, appSecret: app_secret, server: SDK.RC_SERVER_PRODUCTION)

The 'app_key' and 'app_secret' should be read from a configuration file.

Depending on the stage of production, either
SDK.RC_SERVER_SANDBOX or SDK.RC_SERVER_PRODUCTION
will be used as the 'server' parameter.

Authorization

To authorize the platform, extract the 'Platform' object:

var platform = rcsdk.platform()

Once the platform is extracted, call:

platform.login(username, password: password)

or (to authorize with extension):

platform.login(username, ext: ext, password: password)

The SDK will automatically refresh the token so long the refresh token lives.

Caution: If no extension is specified, platform automitically refers extension 101 (default).


Performing API Call

Currently all requests can be made through the following:

platform.get('/account/~/extension/~')
platform.post('/account/~/extension/~', body: [])
platform.put('/account/~/extension/~', body: [])
platform.delete('/account/~/extension/~', query: [])

Attach the following code as a completion handler (always) :

    {
      (transaction) in
        if (error) {
            // do something for error
        } else {
            // continue with code
        }
    }

Returning 'data' into a Dictionary (JSON): This is handled by the ApiResponse class within the SDK. we can retrieve the dictionary as shown below

NSJSON Serialization handled by ApiResponse class :

  NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: &errors) as! NSDictionary  

Retrieve the dictionary in your application as shown below :

  transaction.getDict()

For readability of the data

    println(transaction.getDict())

Performing RingOut

RingOut follows a two-legged style telecommunication protocol. The following method call is used to send a Ring Out.

    platform.post("/account/~/extension/~/ringout", body :
    [ "to": ["phoneNumber": "ToNumber"],
        "from": ["phoneNumber": "FromNumber"],
        "callerId": ["phoneNumber": "CallerId"],
        "playPrompt": "true"
    ])
    {
      (completition handler)
    }

Sending SMS

The follow method call is used to send a SMS.

platform.post("/account/~/extension/~/sms", body :
    [ "to": [["phoneNumber": "18315941779"]],
        "from": ["phoneNumber": "15856234190"],
        "text": "Test"
    ])
    {
      (completition handler)
    }

Subscription

Create a subscription using the createSubscription method

var subscription = rcsdk.createSubscription()

To add Events to the Subscription Object:

  subscription.addEvents(
    [
        "/restapi/v1.0/account/~/extension/~/presence",
        "/restapi/v1.0/account/~/extension/~/message-store"
    ])

Register a Subscription:

subscription.register()
    {
      (completition handler)
    }

Please keep in mind that due to limitations of PUBNUB library, which is synchronous, subscriptions may expire and must be re-created manually.


SDK Demo 1

Login page: Insert app_key, app_secret, username, password in order to log in. This is generally done through a configuration file.

Alt text

Phone page: Use the number pad to type the numbers you need. The Status Bar (initially shown as a red rectangle 'No Call') changes color accordingly. Allows the sending of SMS and Fax, along with the ability to make calls.

Alt text

Log page: Shows implementation of the 'Call Log' along with the 'Message Log'.

Alt text

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published