Beispiel #1
0
        /// <summary>
        /// Extracting Invalid keys
        /// </summary>
        /// <param name="passData"></param>
        /// <returns></returns>
        private List <string> ExtractInvalidKeys(PassData passData)
        {
            List <string> keysList = new List <string>();

            if (string.IsNullOrWhiteSpace(passData.discount))
            {
                keysList.Add("discount");
            }
            if (string.IsNullOrWhiteSpace(passData.memberName))
            {
                keysList.Add("memberName");
            }

            return(keysList);
        }
Beispiel #2
0
        /// <summary>
        /// Create new NFC pass.
        /// </summary>
        /// <param name="passType"></param>
        /// <param name="passData"></param>
        /// <returns>  Result of creating a new NFC pass.</returns>
        public PassResponseData CreatePass(string passType, PassData passData)
        {
            PassResponseData passResponseData = new PassResponseData();

            try
            {
                if (string.IsNullOrWhiteSpace(passType))
                {
                    throw new PassNinjaInvalidArgumentsException("Must provide passType to PassNinjaClient.CreatePass method. PassNinjaClient.CreatePass(passType: string, passData: PassData)");
                }

                List <string> invalidKeys = ExtractInvalidKeys(passData);

                if (invalidKeys.Count > 0)
                {
                    throw new PassNinjaInvalidArgumentsException("Invalid templateStrings provided in clientPassData object. Invalid keys: " + string.Join(",", invalidKeys.ToArray()));
                }

                var postData = new PassRequestData();
                postData.passType = passType;
                postData.pass     = passData;

                var request = new RestRequest("/passes", Method.POST);
                request.AddJsonBody(postData);
                IRestResponse response = _client.Execute(request);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    passResponseData = JsonConvert.DeserializeObject <PassResponseData>(response.Content);
                    if (passResponseData != null)
                    {
                        passResponseData.url = passResponseData.urls?.landing;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(passResponseData);
        }