Beispiel #1
0
        static void Main(string[] args)
        {
            var config = new Configuration();

            config.BasePath = "https://tapi.telstra.com/v2";
            var apiInstance  = new AuthenticationApi(config);
            var clientId     = Environment.GetEnvironmentVariable("CLIENT_ID");     // string |
            var clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET"); // string |
            var grantType    = "client_credentials";                                // string |  (default to "client_credentials")
            var scope        = "NSMS";                                              // string | NSMS (optional)

            try
            {
                // Generate OAuth2 token
                OAuthResponse result = apiInstance.AuthToken(clientId, clientSecret, grantType, scope);
                Console.WriteLine("Token acquired!");
                config.AccessToken = result.AccessToken;

                var provisioningInstance = new ProvisioningApi(config);
                var body = new ProvisionNumberRequest(30);
                ProvisionNumberResponse provisioningResult = provisioningInstance.CreateSubscription(body);
                Console.WriteLine("Number provisioned!");

                var smsApiInstance = new MessagingApi(config);
                var payload        = new SendSMSRequest(
                    Environment.GetEnvironmentVariable("PHONE_NO"),
                    "Test C# SDK",
                    Environment.GetEnvironmentVariable("FROM_ALIAS"));

                MessageSentResponseSms smsResult = smsApiInstance.SendSMS(payload);
                Console.WriteLine("Message sent");
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling AuthenticationApi.AuthToken: " + e.Message);
                Console.WriteLine("Status Code: " + e.ErrorCode);
                Console.WriteLine(e.StackTrace);
                throw;
            }
        }
        /// <summary>
        /// Create Subscription Invoke the provisioning API to get a dedicated mobile number for an account or application.  Note that Free Trial apps will have a 30-Day Limit for their provisioned number. If the Provisioning call is made several times within that 30-Day period, it will return the &#x60;expiryDate&#x60; in the Unix format and will not add any activeDays until after that &#x60;expiryDate&#x60;. After the &#x60;expiryDate&#x60;, you may make another Provisioning call to extend the activeDays by another 30-Days.  For paid apps, a provisioned number can be allotted for a maximum of 5 years. If a Provisioning call is made which will result to activeDays &gt; 1825, a 409 &#x60;Active Days Max&#x60; response will be returned to indicate that the provisioned number is already valid for more than 5 years and that no update to activeDays has been made.
        /// </summary>
        /// <exception cref="Telstra.Messaging.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">A JSON payload containing the required attributes</param>
        /// <returns>Task of ApiResponse (ProvisionNumberResponse)</returns>
        public async System.Threading.Tasks.Task <Telstra.Messaging.Client.ApiResponse <ProvisionNumberResponse> > CreateSubscriptionAsyncWithHttpInfo(ProvisionNumberRequest body)
        {
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new Telstra.Messaging.Client.ApiException(400, "Missing required parameter 'body' when calling ProvisioningApi->CreateSubscription");
            }


            Telstra.Messaging.Client.RequestOptions localVarRequestOptions = new Telstra.Messaging.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "application/json"
            };

            foreach (var _contentType in _contentTypes)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", _contentType);
            }

            foreach (var _accept in _accepts)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", _accept);
            }

            localVarRequestOptions.Data = body;

            // authentication (auth) required
            // oauth required
            if (!String.IsNullOrEmpty(this.Configuration.AccessToken))
            {
                localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
            }

            // make the HTTP request

            var localVarResponse = await this.AsynchronousClient.PostAsync <ProvisionNumberResponse>("/messages/provisioning/subscriptions", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("CreateSubscription", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
        /// <summary>
        /// Create Subscription Invoke the provisioning API to get a dedicated mobile number for an account or application.  Note that Free Trial apps will have a 30-Day Limit for their provisioned number. If the Provisioning call is made several times within that 30-Day period, it will return the &#x60;expiryDate&#x60; in the Unix format and will not add any activeDays until after that &#x60;expiryDate&#x60;. After the &#x60;expiryDate&#x60;, you may make another Provisioning call to extend the activeDays by another 30-Days.  For paid apps, a provisioned number can be allotted for a maximum of 5 years. If a Provisioning call is made which will result to activeDays &gt; 1825, a 409 &#x60;Active Days Max&#x60; response will be returned to indicate that the provisioned number is already valid for more than 5 years and that no update to activeDays has been made.
        /// </summary>
        /// <exception cref="Telstra.Messaging.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">A JSON payload containing the required attributes</param>
        /// <returns>Task of ProvisionNumberResponse</returns>
        public async System.Threading.Tasks.Task <ProvisionNumberResponse> CreateSubscriptionAsync(ProvisionNumberRequest body)
        {
            Telstra.Messaging.Client.ApiResponse <ProvisionNumberResponse> localVarResponse = await CreateSubscriptionAsyncWithHttpInfo(body);

            return(localVarResponse.Data);
        }
        /// <summary>
        /// Create Subscription Invoke the provisioning API to get a dedicated mobile number for an account or application.  Note that Free Trial apps will have a 30-Day Limit for their provisioned number. If the Provisioning call is made several times within that 30-Day period, it will return the &#x60;expiryDate&#x60; in the Unix format and will not add any activeDays until after that &#x60;expiryDate&#x60;. After the &#x60;expiryDate&#x60;, you may make another Provisioning call to extend the activeDays by another 30-Days.  For paid apps, a provisioned number can be allotted for a maximum of 5 years. If a Provisioning call is made which will result to activeDays &gt; 1825, a 409 &#x60;Active Days Max&#x60; response will be returned to indicate that the provisioned number is already valid for more than 5 years and that no update to activeDays has been made.
        /// </summary>
        /// <exception cref="Telstra.Messaging.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">A JSON payload containing the required attributes</param>
        /// <returns>ApiResponse of ProvisionNumberResponse</returns>
        public Telstra.Messaging.Client.ApiResponse <ProvisionNumberResponse> CreateSubscriptionWithHttpInfo(ProvisionNumberRequest body)
        {
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new Telstra.Messaging.Client.ApiException(400, "Missing required parameter 'body' when calling ProvisioningApi->CreateSubscription");
            }

            Telstra.Messaging.Client.RequestOptions localVarRequestOptions = new Telstra.Messaging.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "application/json"
            };

            var localVarContentType = Telstra.Messaging.Client.ClientUtils.SelectHeaderContentType(_contentTypes);

            if (localVarContentType != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
            }

            var localVarAccept = Telstra.Messaging.Client.ClientUtils.SelectHeaderAccept(_accepts);

            if (localVarAccept != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
            }

            localVarRequestOptions.Data = body;

            // authentication (auth) required
            // oauth required
            if (!String.IsNullOrEmpty(this.Configuration.AccessToken))
            {
                localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
            }

            // make the HTTP request
            var localVarResponse = this.Client.Post <ProvisionNumberResponse>("/messages/provisioning/subscriptions", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("CreateSubscription", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
 /// <summary>
 /// Create Subscription Invoke the provisioning API to get a dedicated mobile number for an account or application.  Note that Free Trial apps will have a 30-Day Limit for their provisioned number. If the Provisioning call is made several times within that 30-Day period, it will return the &#x60;expiryDate&#x60; in the Unix format and will not add any activeDays until after that &#x60;expiryDate&#x60;. After the &#x60;expiryDate&#x60;, you may make another Provisioning call to extend the activeDays by another 30-Days.  For paid apps, a provisioned number can be allotted for a maximum of 5 years. If a Provisioning call is made which will result to activeDays &gt; 1825, a 409 &#x60;Active Days Max&#x60; response will be returned to indicate that the provisioned number is already valid for more than 5 years and that no update to activeDays has been made.
 /// </summary>
 /// <exception cref="Telstra.Messaging.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="body">A JSON payload containing the required attributes</param>
 /// <returns>ProvisionNumberResponse</returns>
 public ProvisionNumberResponse CreateSubscription(ProvisionNumberRequest body)
 {
     Telstra.Messaging.Client.ApiResponse <ProvisionNumberResponse> localVarResponse = CreateSubscriptionWithHttpInfo(body);
     return(localVarResponse.Data);
 }
Beispiel #6
0
        /// <summary>
        /// Create Subscription Provision a mobile number
        /// </summary>
        /// <exception cref="com.telstra.messaging.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">A JSON payload containing the required attributes</param>
        /// <returns>Task of ApiResponse (ProvisionNumberResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <ProvisionNumberResponse> > CreateSubscriptionAsyncWithHttpInfo(ProvisionNumberRequest body)
        {
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling ProvisioningApi->CreateSubscription");
            }

            var    localVarPath         = "/messages/provisioning/subscriptions";
            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("CreateSubscription", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <ProvisionNumberResponse>(localVarStatusCode,
                                                             localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                             (ProvisionNumberResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(ProvisionNumberResponse))));
        }
Beispiel #7
0
        /// <summary>
        /// Create Subscription Provision a mobile number
        /// </summary>
        /// <exception cref="com.telstra.messaging.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">A JSON payload containing the required attributes</param>
        /// <returns>ProvisionNumberResponse</returns>
        public ProvisionNumberResponse CreateSubscription(ProvisionNumberRequest body)
        {
            ApiResponse <ProvisionNumberResponse> localVarResponse = CreateSubscriptionWithHttpInfo(body);

            return(localVarResponse.Data);
        }