Ejemplo n.º 1
0
        /// <summary>
        ///     Creates and sends/resends a fax message. Resend can be implemented if sending has failed. Fax attachment size (both
        ///     single and total) is limited to 50Mb.
        ///     HTTP Method: post
        ///     Endpoint: /restapi/{apiVersion}/account/{accountId}/extension/{extensionId}/fax
        ///     Rate Limit Group: Heavy
        ///     App Permission: Faxes
        ///     User Permission: OutboundFaxes
        /// </summary>
        public async Task <FaxResponse> Post(CreateFaxMessageRequest createFaxMessageRequest,
                                             RestRequestConfig restRequestConfig = null)
        {
            var multipartFormDataContent = Utils.GetMultipartFormDataContent(createFaxMessageRequest);

            return(await rc.Post <FaxResponse>(Path(), multipartFormDataContent, null, restRequestConfig));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Operation: Create Fax Message
        /// HTTP Method: POST
        /// Endpoint: /restapi/v1.0/account/{accountId}/extension/{extensionId}/fax
        /// Rate Limit Group: Heavy
        /// App Permission: Faxes
        /// User Permission: OutboundFaxes
        /// </summary>
        public async Task <RingCentral.FaxResponse> Post(CreateFaxMessageRequest createFaxMessageRequest,
                                                         CancellationToken?cancellationToken = null)
        {
            var multipartFormDataContent = Utils.GetMultipartFormDataContent(createFaxMessageRequest);

            return(await rc.Post <RingCentral.FaxResponse>(this.Path(), multipartFormDataContent, null,
                                                           cancellationToken));
        }
Ejemplo n.º 3
0
        public async void SendFax()
        {
            using (var rc = new RestClient(
                       Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
                       Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
                       Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
                       ))
            {
                await rc.Authorize(
                    Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
                    Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
                    Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
                    );

                var sendFaxMessageRequest = new CreateFaxMessageRequest
                {
                    to = new[]
                    {
                        new MessageStoreCalleeInfoRequest
                        {
                            phoneNumber = Environment.GetEnvironmentVariable("RINGCENTRAL_RECEIVER"),
                            name        = "The Receiver"
                        }
                    },
                    attachments = new[]
                    {
                        new Attachment
                        {
                            filename = "rc.png",
                            content  = File.ReadAllBytes("./rc.png")
                        },
                        new Attachment
                        {
                            filename = "glip.png",
                            content  = File.ReadAllBytes("./glip.png")
                        },
                        new Attachment
                        {
                            filename = "hello.txt",
                            content  = Encoding.UTF8.GetBytes("Hello 888")
                        }
                    }
                };
                var r = await rc.Restapi().Account().Extension().Fax().Post(sendFaxMessageRequest);

                Assert.Equal("High", r.faxResolution);
            }
        }
        public async void CancelAfter()
        {
            using (var rc = new RestClient(
                       Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
                       Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
                       Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
                       ))
            {
                await rc.Authorize(
                    Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
                    Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
                    Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
                    );

                var sendFaxMessageRequest = new CreateFaxMessageRequest
                {
                    to = new[]
                    {
                        new MessageStoreCalleeInfoRequest
                        {
                            phoneNumber = Environment.GetEnvironmentVariable("RINGCENTRAL_RECEIVER"),
                            name        = "The Receiver"
                        }
                    },
                    attachments = new[]
                    {
                        new Attachment
                        {
                            filename = "rc.png",
                            content  = File.ReadAllBytes("./rc.png")
                        },
                        new Attachment
                        {
                            filename = "glip.png",
                            content  = File.ReadAllBytes("./glip.png")
                        },
                        new Attachment
                        {
                            filename = "hello.txt",
                            content  = Encoding.UTF8.GetBytes("Hello 888")
                        }
                    }
                };
                var source = new CancellationTokenSource();
                var token  = source.Token;
                source.CancelAfter(10); // impossible to send a fax within 10ms
                var taskCanceledException = false;
                try
                {
                    await rc.Restapi().Account().Extension().Fax().Post(sendFaxMessageRequest, new RestRequestConfig
                    {
                        cancellationToken = token
                    });
                }
                catch (TaskCanceledException)
                {
                    taskCanceledException = true;
                }
                finally
                {
                    Assert.True(taskCanceledException);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Operation: Create Fax Message
        /// Http Post /restapi/v1.0/account/{accountId}/extension/{extensionId}/fax
        /// </summary>
        public async Task <RingCentral.FaxResponse> Post(CreateFaxMessageRequest createFaxMessageRequest)
        {
            var multipartFormDataContent = Utils.GetMultipartFormDataContent(createFaxMessageRequest);

            return(await rc.Post <RingCentral.FaxResponse>(this.Path(), multipartFormDataContent));
        }
Ejemplo n.º 6
0
        public async void SendFaxComplicated()
        {
            using (var rc = new RestClient(
                       Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
                       Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
                       Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
                       ))
            {
                await rc.Authorize(
                    Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
                    Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
                    Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
                    );

                var requestObj = new CreateFaxMessageRequest
                {
                    to = new[]
                    {
                        new MessageStoreCalleeInfoRequest
                        {
                            phoneNumber = Environment.GetEnvironmentVariable("RINGCENTRAL_RECEIVER")
                        }
                    },
                    faxResolution = "Low",
                    attachments   = new[]
                    {
                        new Attachment
                        {
                            filename = "rc.png",
                            content  = File.ReadAllBytes("./rc.png")
                        },
                        new Attachment
                        {
                            filename = "glip.png",
                            content  = File.ReadAllBytes("./glip.png")
                        },
                        new Attachment
                        {
                            filename = "hello.txt",
                            content  = Encoding.UTF8.GetBytes("Hello 888")
                        }
                    }
                };
                var multipartFormDataContent = new MultipartFormDataContent();
                var pairs = Utils.GetPairs(requestObj);
                var dict  = pairs.Where(p => !(p.value is Attachment || p.value is IEnumerable <Attachment>))
                            .ToDictionary(p => p.name, p => p.value);
                var stringContent =
                    new StringContent(JsonConvert.SerializeObject(dict), Encoding.UTF8, "application/json");
                multipartFormDataContent.Add(stringContent, "request.json");
                pairs.Where(p => p.value is Attachment || p.value is IEnumerable <Attachment>).ToList().ForEach(p =>
                {
                    var attachments = p.value;
                    if (!(attachments is IEnumerable <Attachment>))
                    {
                        attachments = new[] { attachments }
                    }
                    ;

                    (attachments as IEnumerable <Attachment>).ToList().ForEach(attachment =>
                    {
                        var content = new ByteArrayContent(attachment.content);
                        multipartFormDataContent.Add(content, attachment.filename, attachment.filename);
                    });
                });

                var responseMessage =
                    await rc.Post("/restapi/v1.0/account/~/extension/~/fax", multipartFormDataContent);

                Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode);
                var responseString = await responseMessage.Content.ReadAsStringAsync();

                Assert.Contains("Fax", responseString);
                Assert.Contains("Outbound", responseString);
                Assert.Contains("faxResolution", responseString);
            }
        }
Ejemplo n.º 7
0
 public Task <FaxResponse> Post(CreateFaxMessageRequest createFaxMessageRequest, Attachment[] attachments)
 {
     createFaxMessageRequest.attachments = attachments;
     return(Post(createFaxMessageRequest));
 }