Source

stacky / trunk / source / Stacky / StackyClientBase.cs

lfoust a2cb220 
lfoust f61c1ce 
lfoust a2cb220 






lfoust 96383a3 
lfoust a2cb220 















lfoust f61c1ce 
lfoust a2cb220 
lfoust f61c1ce 
lfoust a2cb220 




lfoust 73ab0e3 
lfoust a2cb220 

lfoust 96383a3 







lfoust a2cb220 
using System;
using System.Collections.Generic;

namespace Stacky
{
    public abstract class StackyClientBase
    {
        public IProtocol Protocol { get; set; }
        public string SiteUrlName { get; set; }
        public string ApiKey { get; set; }

        public int RemainingRequests { get; internal set; }
        public int MaxRequests { get; internal set; }

        protected string GetSortDirection(SortDirection direction)
        {
            return direction == SortDirection.Ascending ? "asc" : "desc";
        }

        protected string GetSortDirection(SortDirection? direction)
        {
            if (direction.HasValue)
                return GetSortDirection(direction.Value);
            return null;
        }

        protected static string GetEnumValue(object sort)
        {
            return EnumHelper.GetQueryStringValue((Enum)sort);
        }

        protected long? GetDateValue(DateTime? date)
        {
            if (date.HasValue)
                return UnixDateTime.UnixTimeFromDate(date.Value);
            return null;
        }

        protected void EnsureApiKey(IDictionary<string, string> queryStringArguments)
        {
            if (!String.IsNullOrEmpty(ApiKey) && !queryStringArguments.ContainsKey("key"))
            {
                queryStringArguments.Add("key", ApiKey);
            }
        }
    }
}