Inheritance: HttpHeaders
コード例 #1
0
 public void BaseURL()
 {
     var request = new Request("/restapi/");
     var response = sdk.Platform.Get(request);
     var uriString = (string)response.Json.SelectToken("apiVersions").First().SelectToken("uriString");
     Assert.AreEqual("v1.0", uriString);
 }
コード例 #2
0
        public static void Main(string[] args)
        {
            var appKey = "MyAppKey";
            var appSecret = "MyAppSecret";
            var serverUrl = "https://platform.devtest.ringcentral.com";
            var username = "******";
            var extension = "101";
            var password = "******";

            var sdk = new SDK(appKey, appSecret, serverUrl, "appName", "appVersion");
            ApiResponse response = sdk.Platform.Authorize(username, extension, password, true);

            String jsonSmsString = "{\"from\":{\"phoneNumber\":\"1650111222\"},\"to\":[{\"phoneNumber\":\"+1650111333\"}],\"text\":\"Hello Mac\"}";
            Request request = new Request("/restapi/v1.0/account/~/extension/~/sms", jsonSmsString);
            ApiResponse response2 = sdk.Platform.Post(request);

            var subscription = new RingCentral.Subscription.SubscriptionServiceImplementation(){ _platform = sdk.Platform};
            subscription.AddEvent("/restapi/v1.0/account/~/extension/~/presence");
            subscription.AddEvent("/restapi/v1.0/account/~/extension/~/message-store");
            ApiResponse response3 = subscription.Subscribe(Action, Action, Action);

            var wait = Console.ReadLine ();

            Console.WriteLine ("DONE!");
        }
コード例 #3
0
        public void GetBatchMessage()
        {
            var messages = new List<string> { "1", "2" };
            string batchMessages = messages.Aggregate("", (current, message) => current + (message + ","));

            Request request = new Request(ExtensionMessageEndPoint + "/" + batchMessages);
            ApiResponse response = sdk.Platform.Get(request);
            Assert.IsTrue(response.IsMultiPart());
            List<string> multiPartResult = response.GetMultiPartResponses();

            //We're interested in the response statuses and making sure the result was ok for each of the message id's sent.
            JToken responseStatuses = JObject.Parse(multiPartResult[0]);
            for (int i = 0; i < messages.Count; i++)
            {
                var status = (string)responseStatuses.SelectToken("response")[i].SelectToken("status");
                Assert.AreEqual(status, "200");
            }

            foreach (string res in multiPartResult.Skip(1))
            {
                JToken token = JObject.Parse(res);
                var id = (string)token.SelectToken("id");
                Assert.IsNotNull(id);
            }
        }
コード例 #4
0
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            /* Demo
             *
             * Send SMS and Subscribe
             *
             */
            var appKey = "MyAppKey";
            var appSecret = "MyAppSecret";
            var serverUrl = "https://platform.devtest.ringcentral.com";
            var username = "******";
            var extension = "101";
            var password = "******";

            var sdk = new SDK(appKey, appSecret, serverUrl, "appName", "appVersion");
            ApiResponse response = sdk.Platform.Authorize(username, extension, password, true);

            String jsonSmsString = "{\"from\":{\"phoneNumber\":\"1650111222\"},\"to\":[{\"phoneNumber\":\"+1650111333\"}],\"text\":\"Hello iOS\"}";
            Request request = new Request("/restapi/v1.0/account/~/extension/~/sms", jsonSmsString);
            ApiResponse response2 = sdk.Platform.Post(request);

            var subscription = new RingCentral.Subscription.SubscriptionServiceImplementation(){ _platform = sdk.Platform};
            subscription.AddEvent("/restapi/v1.0/account/~/extension/~/presence");
            subscription.AddEvent("/restapi/v1.0/account/~/extension/~/message-store");
            ApiResponse response3 = subscription.Subscribe(ios100.Application.Action, Action, Action);

            Console.WriteLine (response3.ToString ());

            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main (args, null, "AppDelegate");
        }
コード例 #5
0
 public void GetResponseNonJson()
 {
     var request = new Request(AccountExtensionInformationEndPoint + "/6");
     var result = sdk.Platform.Get(request);
     var jsonResult = result.Json;
     Assert.IsNull(jsonResult);
 }
コード例 #6
0
 public void GetHeaders()
 {
     Request request = new Request(AccountInformationEndPoint);
     ApiResponse response = sdk.Platform.Get(request);
     Assert.IsNotNull(response.Headers);
     Assert.AreEqual("application/json; charset=utf-8", response.Headers.ContentType.ToString());
 }
コード例 #7
0
 public void DeleteContactFromAddressBook()
 {
     Request request = new Request(AddressBookEndPoint + "/3");
     ApiResponse response = sdk.Platform.Delete(request);
     JToken token = response.Json;
     var message = (string)token.SelectToken("message");
     Assert.AreEqual("Deleted", message);
 }
コード例 #8
0
        public void GetContactFromAddressBook()
        {
            Request request = new Request(AddressBookEndPoint + "/1");
            ApiResponse response = sdk.Platform.Get(request);
            JToken token = response.Json;
            var firstNameResponse = (string)token.SelectToken("firstName");

            Assert.AreEqual(firstNameResponse, "Delete");
        }
コード例 #9
0
        public void GetAttachmentFromExtension()
        {
            const string expectedMessage = "This is a test from the the NUnit Test Suite of the RingCentral C# SDK";

            Request request = new Request(ExtensionMessageEndPoint + "/1/content/1");
            ApiResponse response = sdk.Platform.Get(request);

            Assert.AreEqual(response.Body, expectedMessage);
        }
コード例 #10
0
        public void GetCallLogById()
        {
            Request request = new Request(CallLogEndPoint + "/call-log/Abcdefgh");
            ApiResponse response = sdk.Platform.Get(request);
            JToken token = response.Json;

            var id = (string)token.SelectToken("id");

            Assert.AreEqual("Abcdefgh", id);
        }
コード例 #11
0
        public void GetCallLogByExtension()
        {
            Request request = new Request(CallLogEndPoint + "/extension/~/call-log");
            ApiResponse result = sdk.Platform.Get(request);
            JToken token = JObject.Parse(result.Body);

            var uri = (string)token.SelectToken("uri");

            Assert.NotNull(uri);
        }
コード例 #12
0
        public void GetActiveCalls()
        {
            Request request = new Request(CallLogEndPoint + "/active-calls");
            ApiResponse result = sdk.Platform.Get(request);
            JToken token = JObject.Parse(result.Body);

            var uri = (string)token.SelectToken("uri");

            Assert.NotNull(uri);
        }
コード例 #13
0
        public void GetMessagesFromExtension()
        {
            Request request = new Request(ExtensionMessageEndPoint);
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;
            var phoneNumber = (string)token.SelectToken("records")[0].SelectToken("from").SelectToken("phoneNumber");

            Assert.AreEqual("+19999999999", phoneNumber);
        }
コード例 #14
0
 public void HttpMethodTunneling()
 {
     var request = new Request(AddressBookContactEndPoint);
     var response = sdk.Platform.Delete(request);
     Assert.AreEqual(HttpMethod.Delete, response.Request.Method);
     request.HttpMethodTunneling = true;
     response = sdk.Platform.Delete(request);
     Assert.AreEqual(HttpMethod.Post, response.Request.Method);
     Assert.AreEqual("DELETE", response.Request.Headers.GetValues("X-HTTP-Method-Override").FirstOrDefault());
 }
コード例 #15
0
        public void GetPresence()
        {
            Request request = new Request(PresenceEndPoint);
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var presenceStatus = (string)token.SelectToken("presenceStatus");

            Assert.AreEqual(presenceStatus, "Available");
        }
コード例 #16
0
        public void GetLanguage()
        {
            Request request = new Request(LanguageEndPoint);
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var languageName = (string)token.SelectToken("records")[0].SelectToken("name");

            Assert.AreEqual(languageName, "English (United States)");
        }
コード例 #17
0
        public void GetRingOutStatus()
        {
            Request request = new Request(RingOutEndPoint + "/1");
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var message = (string)token.SelectToken("status").SelectToken("callStatus");

            Assert.AreEqual(message, "InProgress");
        }
コード例 #18
0
        public void GetCountryById()
        {
            Request request = new Request(CountryEndPoint + "/3");
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var countryName = (string)token.SelectToken("name");

            Assert.AreEqual(countryName, "Albania");
        }
コード例 #19
0
        public void GetCountries()
        {
            Request request = new Request(CountryEndPoint);
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var countryName = (string)token.SelectToken("records")[0].SelectToken("name");

            Assert.AreEqual(countryName, "Afghanistan");
        }
コード例 #20
0
        public void GetAddressBook()
        {
            Request request = new Request(AddressBookEndPoint);
            ApiResponse response = sdk.Platform.Get(request);
            JToken token = response.Json;
            var firstName = (string)token.SelectToken("records")[0].SelectToken("firstName");

            Assert.AreEqual("Delete", firstName);

            firstName = (string)token.SelectToken("records")[1].SelectToken("firstName");

            Assert.AreEqual("Vanessa", firstName);
        }
コード例 #21
0
        public void GetLanguagesById()
        {
            const string languageId = "1033";

            Request request = new Request(LanguageEndPoint + "/" + languageId);
            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var timeZoneName = (string)token.SelectToken("name");

            Assert.AreEqual(timeZoneName, "English (United States)");
        }
コード例 #22
0
 public void SMS()
 {
     var subject = "hello world";
     var requestBody = new {
         text = subject,
         from = new { phoneNumber = Config.Instance.Username },
         to = new object[] { new { phoneNumber = Config.Instance.Receiver } }
     };
     var request = new Request("/restapi/v1.0/account/~/extension/~/sms", JsonConvert.SerializeObject(requestBody));
     var response = sdk.Platform.Post(request);
     StringAssert.EndsWith(subject, response.Json["subject"].ToString());
     Assert.AreEqual("Outbound", response.Json["direction"].ToString());
     Assert.AreEqual("Sent", response.Json["messageStatus"].ToString());
 }
コード例 #23
0
        public void RingOut()
        {
            var jsonData = "{\"to\": {\"phoneNumber\": \"19999999999\"}," +
                                    "\"from\": {\"phoneNumber\": \"19999999999\"}," +
                                    "\"callerId\": {\"phoneNumber\": \"19999999999\"},\"playPrompt\": true}\"";
            Request request = new Request(RingOutEndPoint, jsonData);

            ApiResponse result = sdk.Platform.Post(request);

            JToken token = JObject.Parse(result.Body);

            var callStatus = (string)token.SelectToken("status").SelectToken("callStatus");

            Assert.AreEqual(callStatus, "InProgress");
        }
コード例 #24
0
        public void Fax()
        {
            var requestBody = JsonConvert.SerializeObject(new
            {
                faxResolution = "High",
                coverIndex = 0,
                to = new object[] { new { phoneNumber = Config.Instance.Receiver } }
            });

            var attachments = new List<Attachment>();
            var textBytes = System.Text.Encoding.UTF8.GetBytes("hello fax");
            var attachment = new Attachment(@"test.txt", "application/octet-stream", textBytes);
            attachments.Add(attachment);
            var request = new Request("/restapi/v1.0/account/~/extension/~/fax", requestBody, attachments);
            var body = request.HttpContent;
            Assert.NotNull(body);
            var response = sdk.Platform.Post(request);
            Assert.AreEqual(true, response.OK);
        }
コード例 #25
0
        // Send the fax and return the ApiResponse object
        public static ApiResponse SendFax(SDK sdk)
        {
            // Get Cover Page
            var coverPage = GetCoverPage ();

            // Get Fax Body
            var attachmentBytes = File.ReadAllBytes (Environment.GetEnvironmentVariable ("RC_DEMO_FAX_FILEPATH"));
            var attachment = new Attachment ("example.pdf", "application/pdf", attachmentBytes);

            var attachments = new List<Attachment> {coverPage, attachment};

            var to = Environment.GetEnvironmentVariable ("RC_DEMO_FAX_TO");
            var json = "{\"to\":[{\"phoneNumber\":\"" + to + "\"}],\"coverIndex\":\"0\"}";

            Request request = new Request ("/restapi/v1.0/account/~/extension/~/fax", json, attachments);

            ApiResponse response = sdk.Platform.Post(request);
            return response;
        }
コード例 #26
0
        public void CreateAddressBookContact()
        {
            string jsonData = "{\"firstName\": \"Vanessa\", " +
                             "\"lastName\": \"May\", " +
                             "\"businessAddress\": " +
                             "{ " +
                             "\"street\": \"2 Marina Blvd\", " +
                             "\"city\": \"San-Francisco\", " +
                             "\"state\": \"CA\", " +
                             "\"zip\": \"94123\"}" +
                             "}";

            Request request = new Request(AddressBookEndPoint, jsonData);

            ApiResponse response = sdk.Platform.Post(request);
            JToken token = response.Json;

            var firstName = (string)token.SelectToken("firstName");
            Assert.AreEqual("Jim", firstName);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            /* Demo
             *
             * Send SMS and Subscribe
             *
             */
            var appKey = "MyAppKey";
            var appSecret = "MyAppSecret";
            var serverUrl = "https://platform.devtest.ringcentral.com";
            var username = "******";
            var extension = "101";
            var password = "******";

            var sdk = new SDK(appKey, appSecret, serverUrl, "appName", "appVersion");
            ApiResponse response = sdk.Platform.Authorize(username, extension, password, true);

            String jsonSmsString = "{\"from\":{\"phoneNumber\":\"1650111222\"},\"to\":[{\"phoneNumber\":\"+1650111333\"}],\"text\":\"Hello Android\"}";
            Request request = new Request("/restapi/v1.0/account/~/extension/~/sms", jsonSmsString);
            ApiResponse response2 = sdk.Platform.Post(request);

            var subscription = new RingCentral.Subscription.SubscriptionServiceImplementation(){ _platform = sdk.Platform};
            subscription.AddEvent("/restapi/v1.0/account/~/extension/~/presence");
            subscription.AddEvent("/restapi/v1.0/account/~/extension/~/message-store");
            ApiResponse response3 = subscription.Subscribe(Action, Action, Action);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.myButton);

            button.Click += delegate {
                button.Text = string.Format ("{0} clicks!", count++);
            };
        }
コード例 #28
0
 public void Remove()
 {
     if (!Alive())
     { // has been removed
         return;
     }
     var request = new Request("/restapi/v1.0/subscription/" + subscriptionInfo.Id);
     var response = platform.Delete(request);
     subscriptionInfo = null;
     pubnub = null;
 }
コード例 #29
0
        public void UpdateContactInAddressbook()
        {
            string jsonData = "{\"firstName\": \"Vanessa\", " +
                              "\"lastName\": \"May\", " +
                              "\"businessAddress\": " +
                              "{ " +
                              "\"street\": \"3 Marina Blvd\", " +
                              "\"city\": \"San-Francisco\", " +
                              "\"state\": \"CA\", " +
                              "\"zip\": \"94123\"}" +
                              "}";
            Request request = new Request(AddressBookEndPoint + "/5", jsonData);

            ApiResponse response = sdk.Platform.Put(request);

            JToken token = response.Json;
            var street = (string)token.SelectToken("businessAddress").SelectToken("street");

            Assert.AreEqual(street, "3 Marina Blvd");
        }
コード例 #30
0
        public void GetLocation()
        {
            var queryParameters = new List<KeyValuePair<string, string>>
                                  {
                                      new KeyValuePair<string, string>(
                                          "stateId", "13")
                                  };

            Request request = new Request(LocationEndPoint, queryParameters);

            ApiResponse response = sdk.Platform.Get(request);

            JToken token = response.Json;

            var city = (string)token.SelectToken("records")[0].SelectToken("city");

            Assert.AreEqual(city, "Anchorage");
        }