ringcentral-sdk-go

RingCentral SDK in Go (https://developers.ringcentral.com). Need help? Post your questions to http://stackoverflow.com/ or send email to [email protected].

MIT License

Stars
3

RingCentral SDK in Go

⚠️ Please use grokify/go-ringcentral instead ⚠️

Table of contents

  1. Overview
  2. Included
  3. To Do
  4. Installation
  5. Usage
  6. Instantiation
  7. Authorization
  8. API Requests
    1. SMS Example
    2. Fax Example
  9. Links
  10. Contributions
  11. License

Overview

This is an unofficial Go SDK for the RingCentral for Developers Platform REST API (https://developers.ringcentral.com).

The core SDK objects follow the general design of the official RingCentral SDKs. Additional functionality is provided for ease of use including request helpers.

This SDK is an early stage library and subject to breaking changes.

Examples using *http.Client and the oauth2 package can be found here:

Included

  • OAuth2 authorization
  • Generic API requests
  • Fax request helper to create multipart/mixed messages

To Do

The following are not yet included in this SDK:

  • OAuth2 token refresh
  • Subscriptions
  • Tests

This SDK is an experimental SDK and will likely see a major rewrite to be more idiomatic Go. Recent work has been in using http.Client with oauth2 directly (which does handle token refresh) and with Swagger Codegen project (with autogenerated model classes). Information on these efforts can be found here:

Installation

$ go get github.com/grokify/ringcentral-sdk-go

Usage

Instantation

The SDK is represented by the global RCSDK constructor. Your application must create an instance of this object.

import(
	"github.com/grokify/ringcentral-sdk-go/rcsdk"
)

// For Production use: rcsdk.RC_SERVER_PRODUCTION or "https://platform.ringcentral.com"
// For Sandbox use: rcsdk.RC_SERVER_SANDBOX or "https://platform.devtest.ringcentral.com"

sdk := rcsdk.NewSdk("yourAppKey", "yourAppSecret", rcsdk.RC_SERVER_SANDBOX)

// Get the Platform Singleton

platform := sdk.GetPlatform();

Authorization

Login is accomplished by calling the platform.Authorize() method of the Platform singleton with username, extension (optional), and password as parameters. A Promise instance is returned, resolved with an AJAX Response object.

The username should be a phone number in E.164 format without the leading +.

platform.Authorize("16505551212", "101", "yourPassword")

API Requests

General API requests can be made via the platform object's Get, Post, Put, and Delete methods. Individual API calls are documented on the API Developer and Reference Guide.

The below SMS example shows how this can be used.

SMS Example

In order to send an SMS using the API, make a POST request to /account/~/extension/~/sms:

import(
	"net/http"
	"net/url"
)

resp, err := platform.Post("/account/~/extension/~/sms", url.Values{}, []byte(`{ 
	"to"   : [{"phoneNumber": "14155551212"}],
	"from" :  {"phoneNumber": "16505551212"}, 
	"text" : "Test from Go"
}`), http.Header{})

Fax Example

Request helpers are provided for more complicated requests. The below shows usage of the fax request helper which is used to help create the multipart/mixed HTTP request.

More information on usage is available in ./rcsdk/helpers/faxrequest/README.md.

import(
	"github.com/grokify/ringcentral-sdk-go/rcsdk/helpers/faxrequest"
	"github.com/grokify/ringcentral-sdk-go/rcsdk/helpers/info"
)

fax, err := faxrequest.NewRequestHelper(faxrequest.Metadata{
	To:            []info.Caller{info.Caller{PhoneNumber: "+16505626570"}},
	CoverPageText: "RingCentral fax example in Go!"})
err = fax.AddText([]byte("Hello World!"), "text/plain")
err = fax.AddFile("/path/to/myfile1.pdf")
err = fax.AddFile("/path/to/myfile2.tif")
err = fax.Finalize()

resp, err := platform.Post("/account/~/extension/~/fax", url.Values{}, fax.GetBody(), fax.GetHeaders())

Links

Project Repo

RingCentral API Docs

RingCentral API Explorer

RingCentral Official SDKs

Contributions

Any reports of problems, comments or suggestions are most welcome.

Please report these on Github

License

RingCentral SDK is available under an MIT-style license. See {file:LICENSE.txt} for details.

RingCentral SDK © 2015 by John Wang

Package Rankings
Top 8.7% on Proxy.golang.org
Badges
Extracted from project README
Build Status Go Report Card Docs SLOC License Docs License