Permalink
Browse files

'throw new Exception' to Contracts.Ensures + public Transport + publi…

…c RequestBuilder
  • Loading branch information...
1 parent e34942e commit 5b45bc0a52dfc2ea215b14f3f522614ab880ec54 @The-Smallest The-Smallest committed Feb 26, 2012
View
6 Yandex.Direct/Data Classes/Enums/ActivatingStatus.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Yandex.Direct
View
6 Yandex.Direct/Data Classes/Enums/AutoBudgetPriority.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Yandex.Direct
View
8 Yandex.Direct/Data Classes/Enums/InstantMessagingClient.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
+using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@@ -12,7 +8,7 @@ namespace Yandex.Direct.Data_Classes.Enums
public enum InstantMessagingClient
{
[EnumMember(Value = "icq")]
- ICQ,
+ Icq,
[EnumMember(Value = "jabber")]
Jabber,
View
6 Yandex.Direct/Data Classes/Enums/ModerationStatus.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Yandex.Direct
View
6 Yandex.Direct/Data Classes/Enums/RejectReasonType.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Yandex.Direct
View
1 Yandex.Direct/Data Classes/Reports/NewReportInfo.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace Yandex.Direct
View
1 Yandex.Direct/Data Classes/Reports/ReportInfo.cs
@@ -1,4 +1,3 @@
-using System.Diagnostics;
using Newtonsoft.Json;
namespace Yandex.Direct
View
7 Yandex.Direct/Serialization/YesNo.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Diagnostics.Contracts;
using Newtonsoft.Json;
namespace Yandex.Direct.Serialization
@@ -21,8 +19,7 @@ public YesNo(bool value)
public static bool TryParse(string s, out YesNo result)
{
- if (s == null)
- throw new ArgumentNullException("s");
+ Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(s), "s");
switch (s.ToLowerInvariant())
{
View
2 Yandex.Direct/YapiRequestBuilder.cs
@@ -5,7 +5,7 @@
namespace Yandex.Direct
{
- internal class YapiRequestBuilder
+ public class YapiRequestBuilder
{
readonly Dictionary<string, string> _dictionary = new Dictionary<string, string>();
View
1 Yandex.Direct/YapiService.ApiCommands.cs
@@ -142,6 +142,5 @@ public enum YapiErrorCode
// Other
LoginDoesNotExist = 251
}
-
}
}
View
59 Yandex.Direct/YapiService.cs
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
-using System.IO;
using System.Linq;
using System.Net;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Converters;
using Yandex.Direct.Serialization;
namespace Yandex.Direct
@@ -43,7 +38,6 @@ public YapiService(string certificatePath, string certificatePassword)
#endregion
-
#region PingApi
public int PingApi()
@@ -118,8 +112,7 @@ public BannerInfo GetBanner(int bannerId)
public BannerInfoWithPhrases<BannerPhraseInfo> GetBannerWithPhrases(BannerInfo banner)
{
- if (banner == null)
- throw new ArgumentNullException("banner");
+ Contract.Requires<ArgumentNullException>(banner != null, "banner");
return GetBannerWithPhrases(banner.BannerId);
}
@@ -131,8 +124,7 @@ public BannerInfoWithPhrases<BannerPhraseInfo> GetBannerWithPhrases(int bannerId
public BannerInfoWithPhrases<BannerPhraseInfoWithStats> GetBannerWithPhrasesAndStats(BannerInfo banner)
{
- if (banner == null)
- throw new ArgumentNullException("banner");
+ Contract.Requires<ArgumentNullException>(banner != null, "banner");
return GetBannerWithPhrasesAndStats(banner.BannerId);
}
@@ -144,33 +136,24 @@ public BannerInfoWithPhrases<BannerPhraseInfoWithStats> GetBannerWithPhrasesAndS
public List<BannerInfo> GetBanners(int[] bannerIds, BannersFilterInfo filter = null)
{
- if (bannerIds == null || bannerIds.Length == 0)
- throw new ArgumentNullException("bannerIds");
-
- if (bannerIds.Length > 2000)
- throw new ArgumentOutOfRangeException("bannerIds", "Maximum allowed number of identifiers per call is 2000.");
+ Contract.Requires<ArgumentException>(bannerIds != null && bannerIds.Any(), "bannerIds");
+ Contract.Requires<ArgumentOutOfRangeException>(bannerIds.Length <= 2000, "Maximum allowed number of identifiers per call is 2000.");
return GetBannersInternal<BannerInfo>(null, bannerIds, PhraseInfoType.No, filter);
}
public List<BannerInfoWithPhrases<BannerPhraseInfo>> GetBannersWithPhrases(int[] bannerIds, BannersFilterInfo filter = null)
{
- if (bannerIds == null || bannerIds.Length == 0)
- throw new ArgumentNullException("bannerIds");
-
- if (bannerIds.Length > 2000)
- throw new ArgumentOutOfRangeException("bannerIds", "Maximum allowed number of identifiers per call is 2000.");
+ Contract.Requires<ArgumentException>(bannerIds != null && bannerIds.Any(), "bannerIds");
+ Contract.Requires<ArgumentOutOfRangeException>(bannerIds.Length <= 2000, "Maximum allowed number of identifiers per call is 2000.");
return GetBannersInternal<BannerInfoWithPhrases<BannerPhraseInfo>>(null, bannerIds, PhraseInfoType.Yes, filter);
}
public List<BannerInfoWithPhrases<BannerPhraseInfoWithStats>> GetBannersWithPhrasesAndStats(int[] bannerIds, BannersFilterInfo filter = null)
{
- if (bannerIds == null || bannerIds.Length == 0)
- throw new ArgumentNullException("bannerIds");
-
- if (bannerIds.Length > 2000)
- throw new ArgumentOutOfRangeException("bannerIds", "Maximum allowed number of identifiers per call is 2000.");
+ Contract.Requires<ArgumentException>(bannerIds != null && bannerIds.Any(), "bannerIds");
+ Contract.Requires<ArgumentOutOfRangeException>(bannerIds.Length <= 2000, "Maximum allowed number of identifiers per call is 2000.");
return GetBannersInternal<BannerInfoWithPhrases<BannerPhraseInfoWithStats>>(null, bannerIds, PhraseInfoType.WithPrices, filter);
}
@@ -200,16 +183,14 @@ private List<T> GetBannersInternal<T>(int[] campaingIds, int[] bannerIds, Phrase
public List<BannerPhraseInfo> GetBannerPhrases(BannerInfo banner, bool considerTimeTarget = false)
{
- if (banner == null)
- throw new ArgumentNullException("banner");
+ Contract.Requires<ArgumentNullException>(banner != null, "banner");
return GetBannerPhrases(banner.BannerId, considerTimeTarget);
}
public List<BannerPhraseInfoWithStats> GetBannerPhrasesWithStats(BannerInfo banner, bool considerTimeTarget = false)
{
- if (banner == null)
- throw new ArgumentNullException("banner");
+ Contract.Requires<ArgumentNullException>(banner != null, "banner");
return GetBannerPhrasesWithStats(banner.BannerId, considerTimeTarget);
}
@@ -226,11 +207,8 @@ public List<BannerPhraseInfoWithStats> GetBannerPhrasesWithStats(int bannerId, b
public List<BannerPhraseInfo> GetBannerPhrases(int[] bannerIds, bool considerTimeTarget = false)
{
- if (bannerIds == null || bannerIds.Length == 0)
- throw new ArgumentNullException("bannerIds");
-
- if (bannerIds.Length > 1000)
- throw new ArgumentOutOfRangeException("bannerIds", "Maximum allowed number of identifiers per call is 1000.");
+ Contract.Requires<ArgumentException>(bannerIds != null && bannerIds.Any(), "bannerIds");
+ Contract.Requires<ArgumentOutOfRangeException>(bannerIds.Length <= 1000, "Maximum allowed number of identifiers per call is 1000.");
var request = new { BannerIDS = bannerIds, RequestPrices = YesNo.No, ConsiderTimeTarget = (YesNo)considerTimeTarget };
@@ -239,11 +217,8 @@ public List<BannerPhraseInfo> GetBannerPhrases(int[] bannerIds, bool considerTim
public List<BannerPhraseInfoWithStats> GetBannerPhrasesWithStats(int[] bannerIds, bool considerTimeTarget = false)
{
- if (bannerIds == null || bannerIds.Length == 0)
- throw new ArgumentNullException("bannerIds");
-
- if (bannerIds.Length > 1000)
- throw new ArgumentOutOfRangeException("bannerIds", "Maximum allowed number of identifiers per call is 1000.");
+ Contract.Requires<ArgumentException>(bannerIds != null && bannerIds.Any(), "bannerIds");
+ Contract.Requires<ArgumentOutOfRangeException>(bannerIds.Length <= 1000, "Maximum allowed number of identifiers per call is 1000.");
var request = new { BannerIDS = bannerIds, RequestPrices = YesNo.Yes, ConsiderTimeTarget = (YesNo)considerTimeTarget };
@@ -252,16 +227,14 @@ public List<BannerPhraseInfoWithStats> GetBannerPhrasesWithStats(int[] bannerIds
public int CreateOrUpdateBanner(EditableBannerInfo banner)
{
- if (banner == null)
- throw new ArgumentNullException("banner");
+ Contract.Requires<ArgumentNullException>(banner != null, "banner");
return CreateOrUpdateBanners(new[] { banner }).FirstOrDefault();
}
public List<int> CreateOrUpdateBanners(IEnumerable<EditableBannerInfo> banners)
{
- if (banners == null)
- throw new ArgumentNullException("banners");
+ Contract.Requires<ArgumentNullException>(banners != null, "banner");
var bannersArray = banners.ToArray();
View
2 Yandex.Direct/YapiTransport.cs
@@ -9,7 +9,7 @@
namespace Yandex.Direct
{
- internal sealed class YapiTransport
+ public sealed class YapiTransport
{
public YapiSettings Setting { get; private set; }
private readonly YapiSerializer _serializer;

0 comments on commit 5b45bc0

Please sign in to comment.