Exemple #1
0
        /// <summary>
        /// Get data for an NFC pass.
        /// </summary>
        /// <param name="passType"></param>
        /// <param name="serialNumber"></param>
        /// <returns>PassResponseData</returns>
        public PassResponseData GetPass(string passType, string serialNumber)
        {
            PassResponseData passResponseData = new PassResponseData();

            try
            {
                if (string.IsNullOrWhiteSpace(passType) || string.IsNullOrWhiteSpace(serialNumber))
                {
                    throw new PassNinjaInvalidArgumentsException("Must provide both passType and serialNumber to PassNinjaClient.GetPass method. PassNinjaClient.GetPass(passType: string, serialNumber: string)");
                }

                var           request  = new RestRequest("/passes/" + passType + "/" + serialNumber, Method.GET);
                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);
        }
Exemple #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);
        }