/// <summary> /// Register Register for an event /// </summary> /// <exception cref="com.telstra.eventdetection.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body">Subscribe with a list of phone numbers, push notification URL (optional) and the event type.</param> /// <returns>Task of ApiResponse (ResisterPhoneNumberList)</returns> public async System.Threading.Tasks.Task <ApiResponse <ResisterPhoneNumberList> > RegisterAsyncWithHttpInfo(SubscriptionObj body) { // verify the required parameter 'body' is set if (body == null) { throw new ApiException(400, "Missing required parameter 'body' when calling RegistrationApi->Register"); } var localVarPath = "/v1/eventdetection/events"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (body != null && body.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // authentication (auth) required // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("Register", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <ResisterPhoneNumberList>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (ResisterPhoneNumberList)Configuration.ApiClient.Deserialize(localVarResponse, typeof(ResisterPhoneNumberList)))); }
/// <summary> /// Register Register for an event /// </summary> /// <exception cref="com.telstra.eventdetection.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body">Subscribe with a list of phone numbers, push notification URL (optional) and the event type.</param> /// <returns>Task of ResisterPhoneNumberList</returns> public async System.Threading.Tasks.Task <ResisterPhoneNumberList> RegisterAsync(SubscriptionObj body) { ApiResponse <ResisterPhoneNumberList> localVarResponse = await RegisterAsyncWithHttpInfo(body); return(localVarResponse.Data); }
private void updateSubscriptionEx(string accTok, string endP, string subscriptionId, string textFlag, string mmsFlag, string callbackData) { try { Session["cs_rest_SubscriptionId"] = this.RetrieveSubscriptionIdFromFile(accTok, this.webHookSubscriptionIdFile); if (Session["cs_rest_SubscriptionId"] != null) { subscriptionId = Session["cs_rest_SubscriptionId"].ToString(); } else { updateSubscriptionErrorResponse = "Create the Subscription before using this operation"; return; } string contextURL = string.Empty; contextURL = string.Empty + endP + "/notification/v1/channels/" + notificationChannel.channelId + "/subscriptions/" + subscriptionId; HttpWebRequest updateSubscriptionWebRequest = (HttpWebRequest)WebRequest.Create(contextURL); updateSubscriptionWebRequest.Headers.Add("Authorization", "Bearer " + accTok); updateSubscriptionWebRequest.Method = "PUT"; updateSubscriptionWebRequest.KeepAlive = true; updateSubscriptionWebRequest.Accept = "application/json"; updateSubscriptionWebRequest.ContentType = "application/json"; string events = string.Empty; if (mmsFlag == "true" && textFlag == "false") { events += "\"MMS\""; } else if (mmsFlag == "false" && textFlag == "true") { events += "\"TEXT\""; } else { events = "\"MMS\", \"TEXT\""; } string payLoadString = "{\"subscription\":{\"events\": [ " + events + "]"; if (!string.IsNullOrEmpty(callbackData)) { payLoadString += ", \"callbackData\" : \"" + callbackData + "\""; } payLoadString += ", \"expiresIn\": 16836 } }"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postBytes = encoding.GetBytes(payLoadString); updateSubscriptionWebRequest.ContentLength = postBytes.Length; Stream postStream = updateSubscriptionWebRequest.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); WebResponse updateSubscriptionWebResponse = updateSubscriptionWebRequest.GetResponse(); using (StreamReader stream = new StreamReader(updateSubscriptionWebResponse.GetResponseStream())) { string updateSubscriptionData = stream.ReadToEnd(); JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); csUpdateSubscriptionDetails deserializedJsonObj = (csUpdateSubscriptionDetails)deserializeJsonObject.Deserialize(updateSubscriptionData, typeof(csUpdateSubscriptionDetails)); if (null != deserializedJsonObj) { updateSubscriptionSuccessResponse = updateSubscriptionData + ":Success"; updateSubscriptionResponse = deserializedJsonObj.subscription; } else { updateSubscriptionErrorResponse = "No response from server"; } stream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } updateSubscriptionErrorResponse = errorResponse; } catch { errorResponse = "Unable to get response"; updateSubscriptionErrorResponse = errorResponse; } } catch (Exception ex) { updateSubscriptionErrorResponse = ex.Message; return; } }
/// <summary> /// Register Register for an event /// </summary> /// <exception cref="com.telstra.eventdetection.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body">Subscribe with a list of phone numbers, push notification URL (optional) and the event type.</param> /// <returns>ResisterPhoneNumberList</returns> public ResisterPhoneNumberList Register(SubscriptionObj body) { ApiResponse <ResisterPhoneNumberList> localVarResponse = RegisterWithHttpInfo(body); return(localVarResponse.Data); }
private void createSubscriptionEx(string accTok, string endP, string textFlag, string mmsFlag, string callbackData) { try { string contextURL = string.Empty; contextURL = string.Empty + endP + "/notification/v1/channels/" + this.notificationChannel.channelId + "/subscriptions"; HttpWebRequest createSubscriptionWebRequest = (HttpWebRequest)WebRequest.Create(contextURL); createSubscriptionWebRequest.Headers.Add("Authorization", "Bearer " + accTok); createSubscriptionWebRequest.Method = "POST"; createSubscriptionWebRequest.KeepAlive = true; createSubscriptionWebRequest.Accept = "application/json"; createSubscriptionWebRequest.ContentType = "application/json"; string events = string.Empty; if (mmsFlag == "true" && textFlag == "false") { events += "\"MMS\"" ; } else if (mmsFlag == "false" && textFlag == "true") { events += "\"TEXT\""; } else { events = "\"MMS\", \"TEXT\""; } string payLoadString = "{\"subscription\":{\"events\": [ " + events + "]"; if (!string.IsNullOrEmpty(callbackText.Text)) { payLoadString += ", \"callbackData\" : \"" + callbackText.Text + "\""; } payLoadString += ", \"expiresIn\": 16836 } }"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postBytes = encoding.GetBytes(payLoadString); createSubscriptionWebRequest.ContentLength = postBytes.Length; Stream postStream = createSubscriptionWebRequest.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); WebResponse createSubscriptionWebResponse = createSubscriptionWebRequest.GetResponse(); using (StreamReader stream = new StreamReader(createSubscriptionWebResponse.GetResponseStream())) { string createSubscriptionData = stream.ReadToEnd(); JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); csCreateSubscriptionDetails deserializedJsonObj = (csCreateSubscriptionDetails)deserializeJsonObject.Deserialize(createSubscriptionData, typeof(csCreateSubscriptionDetails)); if (null != deserializedJsonObj) { createSubscriptionSuccessResponse = "Success : " + createSubscriptionData; createSubscriptionResponse = deserializedJsonObj.subscription; Session["cs_rest_SubscriptionId"] = createSubscriptionResponse.subscriptionId; if (this.CheckItemInFile(createSubscriptionResponse.subscriptionId, this.webHookSubscriptionIdFile) == false) { updateListsForWebHookSubscriptionId(); string tempString = accTok + " " + createSubscriptionResponse.subscriptionId; this.webHookSubscriptionIdList.Add(tempString); this.WriteListToFile(ref webHookSubscriptionIdList, this.webHookSubscriptionIdFile); //updateListsForWebHookSubscriptionId(); } } else { createSubscriptionErrorResponse = "No response from server"; } stream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } createSubscriptionErrorResponse = errorResponse; } catch { errorResponse = "Unable to get response"; createSubscriptionErrorResponse = errorResponse; } } catch (Exception ex) { createSubscriptionErrorResponse = ex.Message; return; } }