示例#1
0
        public async void SendFax2()
        {
            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 SendFaxMessageRequest
                {
                    to = new[]
                    {
                        new MessageStoreCallerInfoRequest
                        {
                            phoneNumber = Environment.GetEnvironmentVariable("RINGCENTRAL_RECEIVER")
                        }
                    }
                };
                var attachments = new[]
                {
                    new Attachment
                    {
                        fileName = "rc.png",
                        bytes    = File.ReadAllBytes("./rc.png")
                    },
                    new Attachment
                    {
                        fileName = "glip.png",
                        bytes    = File.ReadAllBytes("./glip.png")
                    },
                    new Attachment
                    {
                        fileName = "hello.txt",
                        bytes    = Encoding.UTF8.GetBytes("Hello 888")
                    }
                };
                var r = await rc.Restapi().Account().Extension().Fax().Post(sendFaxMessageRequest, attachments);

                Assert.Equal("High", r.faxResolution);
            }
        }
示例#2
0
        // Operation: Create Fax Message
        // Http Post /restapi/v1.0/account/{accountId}/extension/{extensionId}/fax
        public async Task <RingCentral.FaxResponse> Post(SendFaxMessageRequest sendFaxMessageRequest)
        {
            var multipartFormDataContent = Utils.GetMultipartFormDataContent(sendFaxMessageRequest);

            return(await rc.Post <RingCentral.FaxResponse>(this.Path(), multipartFormDataContent));
        }
示例#3
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 SendFaxMessageRequest
                {
                    to = new[]
                    {
                        new MessageStoreCallerInfoRequest
                        {
                            phoneNumber = Environment.GetEnvironmentVariable("RINGCENTRAL_RECEIVER")
                        }
                    },
                    faxResolution = "Low",
                    attachments   = new[]
                    {
                        new Attachment
                        {
                            fileName = "rc.png",
                            bytes    = File.ReadAllBytes("./rc.png")
                        },
                        new Attachment
                        {
                            fileName = "glip.png",
                            bytes    = File.ReadAllBytes("./glip.png")
                        },
                        new Attachment
                        {
                            fileName = "hello.txt",
                            bytes    = 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.bytes);
                        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);
            }
        }
示例#4
0
 public Task <FaxResponse> Post(SendFaxMessageRequest sendFaxMessageRequest, Attachment[] attachments)
 {
     sendFaxMessageRequest.attachments = attachments;
     return(Post(sendFaxMessageRequest));
 }