Esempio n. 1
0
        /// <summary>Initializes a new instance of the <see cref="Gameball"/> class.</summary>
        /// <param name="apiKey">The API key used by the client to make requests.</param>
        /// <param name="transactionKey">The Transaction key used by the client to make requests.</param>
        /// <exception cref="ArgumentNullException">if <c>apiKey</c> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">
        /// if <c>apiKey</c> is empty or contains whitespace.
        /// if <c>transactionKey</c> is empty or contains whitespace.
        /// </exception>
        public Gameball(string apiKey, string transactionKey = null)
        {
            Client = new HttpClient();
            if (apiKey == null || apiKey.Length == 0)
            {
                throw new ArgumentException("API key cannot be null or an empty string.", nameof(apiKey));
            }

            if (apiKey != null && GameballUtils.ContainsWhitespace(apiKey))
            {
                throw new ArgumentException("API key cannot contain whitespace.", nameof(apiKey));
            }

            if (transactionKey != null && GameballUtils.ContainsWhitespace(transactionKey))
            {
                throw new ArgumentException("Transaction key cannot contain whitespace.", nameof(transactionKey));
            }

            if (transactionKey != null && transactionKey.Length == 0)
            {
                throw new ArgumentException("Transaction key cannot be the empty string.", nameof(transactionKey));
            }



            this.ApiBase        = GameballConstants.BaseURL;
            this.ApiKey         = apiKey;
            this.TransactionKey = transactionKey;
            this.Lang           = GameballLang.English;
            Client.DefaultRequestHeaders.Clear();
            Client.DefaultRequestHeaders.Add("APIKey", ApiKey);
        }
        internal override bool Validate()
        {
            if (PlayerUniqueId == null || PlayerUniqueId.Length == 0)
            {
                throw new ArgumentException("Player Unique ID cannot be null or an empty string.", nameof(PlayerUniqueId));
            }

            if (PlayerUniqueId != null && GameballUtils.ContainsWhitespace(PlayerUniqueId))
            {
                throw new ArgumentException("Player Unique ID cannot contain whitespace.", nameof(PlayerUniqueId));
            }

            if (this.HoldReference != null && this.HoldReference.Length == 0)
            {
                throw new ArgumentException("Hold Reference cannot be the empty string.", nameof(HoldReference));
            }

            if (this.HoldReference != null && GameballUtils.ContainsWhitespace(HoldReference))
            {
                throw new ArgumentException("Hold Reference cannot contain whitespace.", nameof(HoldReference));
            }


            if (Amount < 0)
            {
                throw new ArgumentException("Amount cannot be negative", nameof(Amount));
            }

            return(true);
        }
        internal override bool Validate()
        {
            if (PlayerUniqueId == null || PlayerUniqueId.Length == 0)
            {
                throw new ArgumentException("Player Unique ID cannot be null or an empty string.", nameof(PlayerUniqueId));
            }

            if (PlayerUniqueId != null && GameballUtils.ContainsWhitespace(PlayerUniqueId))
            {
                throw new ArgumentException("Player Unique ID cannot contain whitespace.", nameof(PlayerUniqueId));
            }

            if (this.HoldReference == null || this.HoldReference.Length == 0)
            {
                throw new ArgumentException("Hold Reference cannot be null or an empty string.", nameof(HoldReference));
            }

            if (this.HoldReference != null && GameballUtils.ContainsWhitespace(HoldReference))
            {
                throw new ArgumentException("Hold Reference cannot contain whitespace.", nameof(HoldReference));
            }

            if (TransactionId == null)
            {
                throw new ArgumentException("Transaction on client system Id cannot be null.", nameof(TransactionId));
            }

            if (PlayerAttributes != null)
            {
                PlayerAttributes.Validate();
            }

            return(true);
        }
Esempio n. 4
0
        internal override bool Validate()
        {
            if (PlayerUniqueId == null || PlayerUniqueId.Length == 0)
            {
                throw new ArgumentException("Player Unique ID cannot be null or an empty string.", nameof(PlayerUniqueId));
            }

            if (PlayerUniqueId != null && GameballUtils.ContainsWhitespace(PlayerUniqueId))
            {
                throw new ArgumentException("Player Unique ID cannot contain whitespace.", nameof(PlayerUniqueId));
            }

            if (PlayerCode == null || PlayerCode.Length == 0)
            {
                throw new ArgumentException("Player Code cannot be null or an empty string.", nameof(PlayerCode));
            }

            if (PlayerCode != null && GameballUtils.ContainsWhitespace(PlayerCode))
            {
                throw new ArgumentException("Player Code cannot contain whitespace.", nameof(PlayerCode));
            }

            if (PlayerAttributes != null)
            {
                PlayerAttributes.Validate();
            }

            if (SessionInfo != null)
            {
                SessionInfo.Validate();
            }

            return(true);
        }
Esempio n. 5
0
        internal override bool Validate()
        {
            if (this.HoldReference != null && this.HoldReference.Length == 0)
            {
                throw new ArgumentException("Hold Reference cannot be the empty string.", nameof(HoldReference));
            }

            if (this.HoldReference != null && GameballUtils.ContainsWhitespace(HoldReference))
            {
                throw new ArgumentException("Hold Reference cannot contain whitespace.", nameof(HoldReference));
            }

            try
            {
                int Amount = Convert.ToInt32(RewardAmount);
            }

            catch
            {
                throw new ArgumentException("Reward Amount must be a valid Amount ", nameof(RewardAmount));
            }

            if (Convert.ToInt32(RewardAmount) < 0)
            {
                throw new ArgumentException("Reward Amount cannot be negative", nameof(RewardAmount));
            }

            return(true);
        }
        internal override bool Validate()
        {
            if (PlayerUniqueId == null || PlayerUniqueId.Length == 0)
            {
                throw new ArgumentException("Player Unique ID cannot be null or an empty string.", nameof(PlayerUniqueId));
            }

            if (PlayerUniqueId != null && GameballUtils.ContainsWhitespace(PlayerUniqueId))
            {
                throw new ArgumentException("Player Unique ID cannot contain whitespace.", nameof(PlayerUniqueId));
            }

            if (StartAt != null && EndsAt != null && DateTime.Compare((DateTime)StartAt, (DateTime)EndsAt) > 0)
            {
                throw new ArgumentException("A Coupon cannot have a start date after its end date.", nameof(StartAt));
            }

            return(true);
        }