Giter Club home page Giter Club logo

webexteamsapiclient's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

webexteamsapiclient's Issues

More easy way to list result by paging.

For now paging feature is supported by enumerating TeamsListResult:

// Gets Enumerator to list all the Group spaces.
var e = (await teams.ListSpacesAsync(
                       type: SpaceType.Group,
                       max: 50)
        ).GetListResultEnumerator();

// Iterates until getting all the spaces.
while (await e.MoveNextAsync())
{
  var r = e.CurrentResult;

  if (r.IsSuccessStatus && r.Data.HasItems)
  {
    // Each result has space list.
    foreach (var space in r.Data.Items)
    {
      // Say "Hello" to the specific named space.
      if (space.Title == "Demo space for Webex Teams API Client(Thrzn41.WebexTeams)")
      {
        await teams.CreateMessageAsync(space, "Hello, Webex Teams!!");
      }
    }

  }
}

To avoid nested while of for/foreach loop, it will be better there is enumeration feature of TeamsResult:

// Gets Enumerator to list all the Group spaces.
var e = (await teams.ListSpacesAsync(
                       type: SpaceType.Group,
                       max: 50)
        ).GetResultEnumerator();

// Iterates until getting all the spaces.
while (await e.MoveNextAsync())
{
  var r = e.CurrentResult;

  if (r.IsSuccessStatus)
  {
      var space = r.Data;

      // Say "Hello" to the specific named space.
      if (space.Title == "Demo space for Webex Teams API Client(Thrzn41.WebexTeams)")
      {
        await teams.CreateMessageAsync(space, "Hello, Webex Teams!!");
      }
    }
}

TeamsDataProtect to encrypt and/or decrypt TeamsData.

Features to encrypt and/or decrypt TeamsData again and again.
Especially for token related data.

Code sinipped(may be changed):

using(var ltdp = TeamsLocalDataProtect.Create())
{
    var encrypted = ltdp.Encrypt(teamsdata);

    // some stream ops.
    await ltdp.WriteToStreamAsync(stream);
}

using(var ptdp = TeamsPBEDataProtect.Create())
{
    var encrypted = ptdp.Encrypt(teamsdata);

    // some stream ops.
    await ptdp.WriteToStreamAsync(stream);
}

Retrieve resource and operation enum feature

Enums for Resources or Operations.

For examples:

TeamsResource.Message;
TeamsResource.Space;
TeamsOperation.List;
TeamsOperation.Get;
TeamsOperation.Create;

In addition, this resource and operation can be retrieved from result.

Code snippet for this enhancement:

var r = await teams.ListSpaces();

// For example, "Operation: ListSpace" is output to log.
Log.Info("Operation: {0}", r.ResourceOperation);

Retrieve request line feature

This is mainly for logging.

Code snippet for this enhancement:

var r = await teams.ListSpaces();

// For example, "GET /v1/rooms HTTP/1.1 - OK" is output to log.
Log.Info("{0} - {1}", r.RequestLine, r.HttpStatusCode);

GetFileInfoAsync returns Unauthorzied - Webex API URI changed

The URI https://api.ciscospark.com has changed to https://webexapis.com. The code still calls the old API-URI api.ciscospark.com as stated in TeamsAPIClient.cs:

protected const string TEAMS_API_PATH = "https://api.ciscospark.com/v1/";

While this is still working for most of the scenarios, the File-URI's in messages return the new URI. Subsequent calls to GetFileInfoAsync with the new URI returned fail with 401 "Unauthorized", because the Authentication header will not be passed to the API due to this check in TeamsHttpClient.cs:

if (this.teamsAuthentication != null && !reusableRequest.HasAuthentication && this.teamsAPIUriPattern != null && this.teamsAPIUriPattern.IsMatch(reusableRequest.Uri.AbsoluteUri)) // <-- no Match!
{
     reusableRequest.Authentication = this.teamsAuthentication;
}

avoid unnecessary await Task

There are some unnecessary await Tasks.

For example:
some await Stream.CopyToAsync() can be replaced with simply Stream.CopyTo().

For some methods, it will be better:

Stream.CopyTo();
return Task.CompletedTask;

CopyFileDataToStreamAsync() throws OutOfMemoryException when the file is too large.

If a large file(example, 2 GB or 4 GB) will be downloaded, CopyFileDataToStreamAsync() throws OutOfMemoryException.

In this issue,
HttpClient.SendAsync(request) throws OutOfMemoryException after retrieving large Content-Length header value.
To use HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) and stream download will avoid the exception.

Examples for oAuth

Do you have any example on how to use this API with the Cisco oAuth workflow?

Guid(Transaction Id) per request even there are retries

For logging in apps,
it is better that there are consistent Guid per request even there are retries.

Code snippet for this enhancement:

// RetryExecutor.One requests with 1 time retry at most.
var result = await RetryExecutor.One.ListAsync(
  () =>
  {
      // This function will be executed again if needed.
      return teams.ListSpacesAsync();
  },

  (r, retryCount) =>
  {
      // This function will be executed before evry retry request.

      // You can output logs or other things at this point.
      Log.Info("Retry is required: delta = {0}, counter = {1}, guid = {2}", r.RetryAfter.Delta, retryCount, r.Guid);

      // Return 'true' when you want to proceed retry.
      return true;
  }
);
  
  // the Guid is the same as logging on a retry.
  Log.Info("guid = {0}",result.Guid);

Improve retry feature

Currently, retry feature works per request.
For easy use, it is better that the feature works per Teams API Client.

Code snippet for this enhancement:

var teams = TeamsAPI.CreateVersion1Client(token, RetryExecutor.One);

// This request will be invoked with retry option.
var r = await teams.ListSpaces();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.