public void When_Request_Method_Is_POST_Then_Request_Body_Contains_Encoded_Parameters() { string body = "Foo=12345&Bar=abcde"; var sourcebytes = Encoding.UTF8.GetBytes(body); client = new RestClient(); client.BaseUrl = BASE_URL; var request = new RestRequest(); request.Method = "POST"; request.AddParameter("Foo", "12345"); request.AddParameter("Bar", "abcde"); var wrapper = new HttpWebRequestWrapper(); wrapper.Request = new FakeHttpWebRequest(); var webrequest = (FakeHttpWebRequest)wrapper.ConfigureRequest(client, request); var stream = webrequest.GetRequestStream(); stream.Position = 0; byte[] actualbytes = stream.ReadAsBytes(); Assert.AreEqual(sourcebytes.Length, webrequest.ContentLength); Assert.AreEqual(sourcebytes.Length, actualbytes.Length); CollectionAssert.AreEquivalent(sourcebytes, actualbytes); }
/// <summary> /// Returns a paged set of Transcriptions that includes paging information. /// Makes a GET request to the Transcriptions List resource. /// </summary> /// <param name="pageNumber">The page to start retrieving results from</param> /// <param name="count">The number of results to retrieve</param> public virtual TranscriptionResult ListTranscriptions(int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Transcriptions.json"; if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return Execute<TranscriptionResult>(request); }
/// <summary> /// Returns a paged set of Transcriptions that includes paging information, sorted by 'DateUpdated', with most recent transcripts first. /// </summary> /// <param name="pageNumber">The page to start retrieving results from</param> /// <param name="count">The number of results to retrieve</param> /// <param name="callback">The method to call upon the completion of the request</param> public virtual void ListTranscriptions(int? pageNumber, int? count, Action<TranscriptionResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Transcriptions.json"; if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<TranscriptionResult>(request, (response) => callback(response)); }
/// <summary> /// List ConnectApps on current account with filters /// </summary> /// <param name="pageNumber">Page number to start retrieving results from</param> /// <param name="count">How many results to return</param> public virtual ConnectAppResult ListConnectApps(int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/ConnectApps.json"; if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return Execute<ConnectAppResult>(request); }
/// <summary> /// List AuthorizedConnectApps on current account with filters /// </summary> /// <param name="pageNumber">Page number to start retrieving results from</param> /// <param name="count">How many results to return</param> public virtual async Task<AuthorizedConnectAppResult> ListAuthorizedConnectAppsAsync(int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/AuthorizedConnectApps.json"; if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return await Execute<AuthorizedConnectAppResult>(request); }
/// <summary> /// Creates a new Queue resource /// </summary> /// <param name="friendlyName">The name of the Queue</param> /// <param name="maxSize">The maximum number of calls allowed in the queue</param> /// <param name="callback">Method to call upon successful completion</param> /// <returns></returns> public virtual void CreateQueue(string friendlyName, int maxSize, Action<Queue> callback) { var request = new RestRequest(Method.POST); request.Resource = "Accounts/{AccountSid}/Queues.json"; request.AddParameter("FriendlyName", friendlyName); request.AddParameter("MaxSize", maxSize); ExecuteAsync<Queue>(request, (response) => callback(response)); }
/// <summary> /// List AuthorizedConnectApps on current account with filters /// </summary> /// <param name="pageNumber">Page number to start retrieving results from</param> /// <param name="count">How many results to return</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void ListAuthorizedConnectApps(int? pageNumber, int? count, Action<AuthorizedConnectAppResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/AuthorizedConnectApps.json"; if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<AuthorizedConnectAppResult>(request, (response) => { callback(response); }); }
/// <summary> /// Creates a new Queue resource /// </summary> /// <param name="friendlyName">The name of the Queue</param> /// <param name="maxSize">The maximum number of calls allowed in the queue</param> /// <returns></returns> public virtual async Task<Queue> CreateQueueAsync(string friendlyName, int maxSize) { var request = new RestRequest(Method.POST); request.Resource = "Accounts/{AccountSid}/Queues.json"; request.AddParameter("FriendlyName", friendlyName); request.AddParameter("MaxSize", maxSize); return await Execute<Queue>(request); }
/// <summary> /// Delete the specified media instance. Makes a DELETE request to a /// Media Instance resource. /// </summary> /// <param name="mediaSid">The Sid of the media to delete</param> public virtual async Task<DeleteStatus> DeleteMessageMediaAsync(string messageSid, string mediaSid) { var request = new RestRequest(Method.DELETE); request.Resource = "Accounts/{AccountSid}/Messages/{MessageSid}/Media/{MediaSid}.json"; request.AddParameter("MediaSid", mediaSid, ParameterType.UrlSegment); request.AddParameter("MessageSid", messageSid, ParameterType.UrlSegment); var response = await Execute(request); return response.StatusCode == System.Net.HttpStatusCode.NoContent ? DeleteStatus.Success : DeleteStatus.Failed; }
public void When_Request_Method_Is_GET_Then_Request_Body_Does_Not_Contain_Encoded_Parameters() { var request = new RestRequest(); request.Method = "GET"; request.AddParameter("Foo", "12345"); request.AddParameter("Bar", "abcde"); var requestmessage = client.ConfigureRequestMessage(request); Assert.IsNull(requestmessage.Content); }
/// <summary> /// Returns a set of Transcriptions for a specific recording that includes paging information. /// Makes a GET request to a Recording Transcriptions List resource. /// </summary> /// <param name="recordingSid">The Sid of the recording to retrieve transcriptions for</param> /// <param name="pageNumber">The page to start retrieving results from</param> /// <param name="count">The number of results to retrieve</param> public virtual TranscriptionResult ListTranscriptions(string recordingSid, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json"; request.AddUrlSegment("RecordingSid", recordingSid); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return Execute<TranscriptionResult>(request); }
public void When_Request_Method_Is_POST_Then_ContentType_Is_FormEncoded() { var request = new RestRequest(); request.Method = "POST"; request.AddParameter("Foo", "12345"); request.AddParameter("Bar", "abcde"); var requestmessage = client.ConfigureRequestMessage(request); Assert.AreEqual("application/x-www-form-urlencoded", requestmessage.Content.Headers.ContentType.MediaType); }
/// <summary> /// List applications on current account with filters /// </summary> /// <param name="friendlyName">Optional friendly name to match</param> /// <param name="pageNumber">Page number to start retrieving results from</param> /// <param name="count">How many results to return</param> public virtual async Task<ApplicationResult> ListApplicationsAsync(string friendlyName, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Applications.json"; if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return await Execute<ApplicationResult>(request); }
/// <summary> /// List applications on current account with filters /// </summary> /// <param name="friendlyName">Optional friendly name to match</param> /// <param name="pageNumber">Page number to start retrieving results from</param> /// <param name="count">How many results to return</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void ListApplications(string friendlyName, int? pageNumber, int? count, Action<ApplicationResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Applications.json"; if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<ApplicationResult>(request, callback); }
public void When_Request_Method_Is_POST_Then_ContentType_Is_FormEncoded() { var request = new RestRequest(); request.Method = "POST"; request.AddParameter("Foo", "12345"); request.AddParameter("Bar", "abcde"); var wrapper = new HttpWebRequestWrapper(); var webrequest = wrapper.ConfigureRequest(client, request); Assert.AreEqual("application/x-www-form-urlencoded", webrequest.ContentType); }
/// <summary> /// Returns a filtered list of validated outgoing caller IDs. The list includes paging information. /// Makes a GET request to an OutgoingCallerIds List resource. /// </summary> /// <param name="phoneNumber">If present, filter the list by the value provided</param> /// <param name="friendlyName">If present, filter the list by the value provided</param> /// <param name="pageNumber">If present, start the results from the specified page</param> /// <param name="count">If present, return the specified number of results, up to 1000</param> /// <returns></returns> public virtual OutgoingCallerIdResult ListOutgoingCallerIds(string phoneNumber, string friendlyName, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/OutgoingCallerIds.json"; if (phoneNumber.HasValue()) request.AddParameter("PhoneNumber", phoneNumber); if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return Execute<OutgoingCallerIdResult>(request); }
/// <summary> /// Returns a filtered list of notifications generated for an account. The list includes paging information and is sorted by DateUpdated, with most recent notifications first. /// </summary> /// <param name="log">Only show notifications for this log, using the integer log values: 0 is ERROR, 1 is WARNING</param> /// <param name="messageDate">Only show notifications for this date (in GMT)</param> /// <param name="pageNumber">The page number to start retrieving results from</param> /// <param name="count">How many notifications to return</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void ListNotifications(int? log, DateTime? messageDate, int? pageNumber, int? count, Action<NotificationResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Notifications.json"; if (log.HasValue) request.AddParameter("Log", log); if (messageDate.HasValue) request.AddParameter("MessageDate", messageDate.Value.ToString("yyyy-MM-dd")); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<NotificationResult>(request, (response) => callback(response)); }
/// <summary> /// Update the TwiML voice and SMS URLs associated with the sandbox number /// </summary> /// <param name="voiceUrl">The URL to use for incoming calls to your sandbox number.</param> /// <param name="voiceMethod">The HTTP method to use for incoming calls to your sandbox number.</param> /// <param name="smsUrl">The URL to use for incoming SMS text messages sent to your sandbox number.</param> /// <param name="smsMethod">The HTTP method to use for incoming text messages sent to your sandbox number.</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void UpdateSandbox(string voiceUrl, string voiceMethod, string smsUrl, string smsMethod, Action<Sandbox> callback) { var request = new RestRequest(Method.POST); request.Resource = "Accounts/{AccountSid}/Sandbox.json"; request.AddParameter("VoiceUrl", voiceUrl); request.AddParameter("VoiceMethod", voiceMethod); request.AddParameter("SmsUrl", smsUrl); request.AddParameter("SmsMethod", smsMethod); ExecuteAsync<Sandbox>(request, callback); }
/// <summary> /// Returns a filtered list of validated outgoing caller IDs. The list includes paging information. /// </summary> /// <param name="phoneNumber">If present, filter the list by the value provided</param> /// <param name="friendlyName">If present, filter the list by the value provided</param> /// <param name="pageNumber">If present, start the results from the specified page</param> /// <param name="count">If present, return the specified number of results, up to 1000</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void ListOutgoingCallerIds(string phoneNumber, string friendlyName, int? pageNumber, int? count, Action<OutgoingCallerIdResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/OutgoingCallerIds.json"; // if (phoneNumber.HasValue()) request.AddParameter("PhoneNumber", phoneNumber); if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<OutgoingCallerIdResult>(request, (response) => callback(response)); }
/// <summary> /// Returns a filtered list of Recordings, each representing a recording generated during the course of a phone call. The list includes paging information. /// </summary> /// <param name="callSid">(Optional) The CallSid to retrieve recordings for</param> /// <param name="dateCreated">(Optional) The date the recording was created (GMT)</param> /// <param name="pageNumber">The page to start retrieving results from</param> /// <param name="count">How many results to retrieve</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void ListRecordings(string callSid, DateTime? dateCreated, int? pageNumber, int? count, Action<RecordingResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Recordings.json"; if (callSid.HasValue()) request.AddParameter("CallSid", callSid); if (dateCreated.HasValue) request.AddParameter("DateCreated", dateCreated.Value.ToString("yyyy-MM-dd")); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<RecordingResult>(request, (response) => callback(response)); }
/// <summary> /// Returns a filtered list of notifications generated for an account. /// The list includes paging information. /// Makes a GET request to a Notifications List resource. /// </summary> /// <param name="log">Only show notifications for this log, using the integer log values: 0 is ERROR, 1 is WARNING</param> /// <param name="messageDate">Only show notifications for this date (in GMT)</param> /// <param name="pageNumber">The page number to start retrieving results from</param> /// <param name="count">How many notifications to return</param> public virtual async Task<NotificationResult> ListNotificationsAsync(int? log, DateTime? messageDate, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Notifications.json"; if (log.HasValue) request.AddParameter("Log", log); if (messageDate.HasValue) request.AddParameter("MessageDate", messageDate.Value.ToString("yyyy-MM-dd")); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return await Execute<NotificationResult>(request); }
/// <summary> /// Update the TwiML voice and SMS URLs associated with the sandbox number. /// Makes a POST request to the Sandbox Instance resource. /// </summary> /// <param name="voiceUrl">The URL to use for incoming calls to your sandbox number.</param> /// <param name="voiceMethod">The HTTP method to use for incoming calls to your sandbox number.</param> /// <param name="smsUrl">The URL to use for incoming SMS text messages sent to your sandbox number.</param> /// <param name="smsMethod">The HTTP method to use for incoming text messages sent to your sandbox number.</param> public virtual Sandbox UpdateSandbox(string voiceUrl, string voiceMethod, string smsUrl, string smsMethod) { var request = new RestRequest(Method.POST); request.Resource = "Accounts/{AccountSid}/Sandbox.json"; request.AddParameter("VoiceUrl", voiceUrl); request.AddParameter("VoiceMethod", voiceMethod); request.AddParameter("SmsUrl", smsUrl); request.AddParameter("SmsMethod", smsMethod); return Execute<Sandbox>(request); }
/// <summary> /// Returns a filtered list of Recordings, each representing a recording generated during the course of a phone call. /// The list includes paging information. /// Makes a GET request to the Recordings List resource. /// </summary> /// <param name="callSid">(Optional) The CallSid to retrieve recordings for</param> /// <param name="dateCreated">(Optional) The date the recording was created (GMT)</param> /// <param name="pageNumber">The page to start retrieving results from</param> /// <param name="count">How many results to retrieve</param> public virtual RecordingResult ListRecordings(string callSid, DateTime? dateCreated, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Recordings.json"; if (callSid.HasValue()) request.AddParameter("CallSid", callSid); if (dateCreated.HasValue) request.AddParameter("DateCreated", dateCreated.Value.ToString("yyyy-MM-dd")); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return Execute<RecordingResult>(request); }
/// <summary> /// Returns a filtered list of SMS messages. The list includes paging information and is sorted by DateSent, with most recent messages first. /// </summary> /// <param name="to">(Optional) The phone number of the message recipient</param> /// <param name="from">(Optional) The phone number of the message sender</param> /// <param name="dateSent">(Optional) The date the message was sent (GMT)</param> /// <param name="pageNumber">(Optional) The page to start retrieving results from</param> /// <param name="count">(Optional) The number of results to retrieve</param> /// <param name="callback">Method to call upon successful completion</param> public virtual void ListSmsMessages(string to, string from, DateTime? dateSent, int? pageNumber, int? count, Action<SmsMessageResult> callback) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/SMS/Messages.json"; if (to.HasValue()) request.AddParameter("To", to); if (from.HasValue()) request.AddParameter("From", from); if (dateSent.HasValue) request.AddParameter("DateSent", dateSent.Value.ToString("yyyy-MM-dd")); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); ExecuteAsync<SmsMessageResult>(request, (response) => callback(response)); }
/// <summary> /// Returns a filtered list of SMS messages. The list includes paging information. /// Makes a GET request to the SMSMessages List resource. /// </summary> /// <param name="to">(Optional) The phone number of the message recipient</param> /// <param name="from">(Optional) The phone number of the message sender</param> /// <param name="dateSent">(Optional) The date the message was sent (GMT)</param> /// <param name="pageNumber">(Optional) The page to start retrieving results from</param> /// <param name="count">(Optional) The number of results to retrieve</param> public virtual async Task<SmsMessageResult> ListSmsMessagesAsync(string to, string from, DateTime? dateSent, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/SMS/Messages.json"; if (to.HasValue()) request.AddParameter("To", to); if (from.HasValue()) request.AddParameter("From", from); if (dateSent.HasValue) request.AddParameter("DateSent", dateSent.Value.ToString("yyyy-MM-dd")); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return await Execute<SmsMessageResult>(request); }
/// <summary> /// Updates a specific Queue resource /// </summary> /// <param name="queueSid">The Sid of the Queue to update</param> /// <param name="friendlyName">The name of the Queue</param> /// <param name="maxSize">The maximum number of calls allowed in the queue</param> /// <returns></returns> public virtual async Task<Queue> UpdateQueueAsync(string queueSid, string friendlyName, int maxSize) { Require.Argument("QueueSid", queueSid); var request = new RestRequest(Method.POST); request.Resource = "Accounts/{AccountSid}/Queues/{QueueSid}.json"; request.AddParameter("QueueSid", queueSid, ParameterType.UrlSegment); if (!string.IsNullOrEmpty(friendlyName)) request.AddParameter("FriendlyName", friendlyName); request.AddParameter("MaxSize", maxSize); return await Execute<Queue>(request); }
/// <summary> /// Retrieve a list of conference participants. Makes a GET request to a Conference Participants List resource. /// </summary> /// <param name="conferenceSid">The Sid of the conference</param> /// <param name="muted">Set to null to retrieve all, true to retrieve muted, false to retrieve unmuted</param> /// <param name="pageNumber">Which page number to start retrieving from</param> /// <param name="count">How many participants to retrieve</param> public virtual async Task<ParticipantResult> ListConferenceParticipantsAsync(string conferenceSid, bool? muted, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; request.AddUrlSegment("ConferenceSid", conferenceSid); if (muted.HasValue) request.AddParameter("Muted", muted.Value); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return await Execute<ParticipantResult>(request); }
/// <summary> /// List incoming local phone numbers on current account with filters /// </summary> /// <param name="phoneNumber">Optional phone number to match</param> /// <param name="friendlyName">Optional friendly name to match</param> /// <param name="pageNumber">Page number to start retrieving results from</param> /// <param name="count">How many results to return</param> public virtual IncomingPhoneNumberResult ListIncomingLocalPhoneNumbers(string phoneNumber, string friendlyName, int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; if (phoneNumber.HasValue()) request.AddParameter("PhoneNumber", phoneNumber); if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return Execute<IncomingPhoneNumberResult>(request); }
/// <summary> /// Return a list of all SIP Domain resources /// </summary> /// <param name="pageNumber"></param> /// <param name="count"></param> /// <returns></returns> public virtual async Task<DomainResult> ListDomainsAsync(int? pageNumber, int? count) { var request = new RestRequest(); request.Resource = "Accounts/{AccountSid}/SIP/Domains.json"; if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); if (count.HasValue) request.AddParameter("PageSize", count.Value); return await Execute<DomainResult>(request); }
/// <summary> /// Delete the specified media instance. Makes a DELETE request to a /// Media Instance resource. /// </summary> /// <param name="messageSid"></param> /// <param name="mediaSid">The Sid of the media to delete</param> /// <param name="callback"></param> public virtual void DeleteMessageMedia(string messageSid, string mediaSid, Action<DeleteStatus> callback) { var request = new RestRequest(Method.DELETE); request.Resource = "Accounts/{AccountSid}/Messages/{MessageSid}/Media/{MediaSid}.json"; request.AddParameter("MediaSid", mediaSid, ParameterType.UrlSegment); request.AddParameter("MessageSid", messageSid, ParameterType.UrlSegment); ExecuteAsync(request, (response) => { callback(response.StatusCode == System.Net.HttpStatusCode.NoContent ? DeleteStatus.Success : DeleteStatus.Failed); }); }