Skip to content

ringcentral/RingCentral.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RingCentral.Net

Build Status Code Document

Getting help and support

If you are having difficulty using this SDK, or working with the RingCentral API, please visit our developer community forums for help and to get quick answers to your questions. If you wish to contact the RingCentral Developer Support team directly, please submit a help ticket from our developer website.

Additional resources

  • RingCentral API Reference - an interactive reference for the RingCentral API that allows developers to make API calls with no code.
  • Document - an interactive reference for the SDK code documentation.

Installation

Packages are available on NuGet. You can install them just like you install any other NuGet packages.

This package is compatible with .NET Standard 2.0, which means, it is compatible with all modern .NET platforms including .NET Core, .NET Framework, and Mono.

Extensions

Since version 5.0.0, this project has been changed to an extension-based architecture.

You need to install extensions if you need extra features:

Code samples

You can find sample code for all the endpoints.

There is also lots of useful code for your reference in our test cases.

Logging

The SDK takes advantage of System .Diagnostics.Trace](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.trace?view=net-6.0) to provide logs.

To enable logging, you need to either add #define TRACE to your source or specify the option /d:TRACE when compiling.

To specify an output channel, you need to specify a listener:

Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

Code about will print logs to the console. For more detail please refer to Trace.Listeners Property.

Demo project.

C# using statement

Please note that if you use the using statement to initialize a RestClient:

using (var rc = new RestClient("clientID", "clientSecret", "serverURL"))
{
    await rc.Authorize("username", "extension", "password");
    ...
}

rc.Dispose() will be automatically invoked after the code block above and the token will be revoked.

If you want to retain the token, do NOT use using and do not rc.Revoke().

Binary content downloading

Some sample code for binary content downloading may not work.

Because RingCentral is gradually migrating binary content to CDN such as media.ringcentral.com.

For example, to download the attachment of a fax:

// `message` is the fax message object
var content = await rc.Get<byte[]>(message.attachments[0].uri);

The following does NOT work:

// `message` is the fax message object
var content = await rc.Restapi().Account().Extension().MessageStore(message.id).Content(message.attachments[0].id).Get();

Rule of thumb

But not all binary content has been migrated to CDN. If the resource to download provides you with a CDN URI, use that CDN URI. If there is no CDN URI provided, construct the URI as the sample code shows.

How to access headers

By default, the SDK doesn't return headers:

var extInfo = await rc.Restapi().Account("~").Extension("~").Get();

If you need headers:

var httpResponseMessage = await rc.Get(rc.Restapi().Account("~").Extension("~").Path(true));
var headers = httpResponseMessage.Headers;
var responseBodyStr = await httpResponseMessage.Content.ReadAsStringAsync();
var extInfo = JsonConvert.DeserializeObject<GetExtensionInfoResponse>(responseBodyStr);

Release Notes

6.0.0

We have renamed all "glip" to "team-messaging". For example:

rc.Restapi().Glip().Chats().List();

Becomes:

rc.TeamMessaging().Chats().List();

For maintainers

Release

Update the version number in RingCentral.Net/RestClient.cs.

Update version number in <ProjectName>/<ProjectName>.csproj

cd <ProjectName>
dotnet pack

Todo

  • Add batch get to auto-generated sample code
  • Add icons to NuGet packages

Development Notes

I tried to migrate from Newtonsoft.Json to System.Text.Json, but it's not easy. Especially System.Text.Json doesn't automatically convert string to number. It doesn't even automatically convert double to int64. Considering the complexity and benefits of the migration, I decided to keep using Newtonsoft.Json for now. Ref: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft

Code coverage

Install the following globally if you haven't done so:

dotnet tool install -g dotnet-reportgenerator-globaltool

Collect code coverage data

dotnet test -settings RingCentral.Tests/coverlet.runsettings.xml

The result is located in RingCentral.Tests/TestResults/

Generate report

~/.dotnet/tools/reportgenerator -reports:"RingCentral.Tests/TestResults/239bdb87–151b-42ac-acec-1f604f8c02c5/coverage.cobertura.xml" -targetdir:RingCentral.Tests/CoverageReport -reporttypes:Html

Open RingCentral.Tests/CoverageReport/index.html in a browser.