added options of default image, added no response exception

This commit is contained in:
Tommy Parnell
2014-01-26 04:22:23 -05:00
parent 8662b0a5ea
commit 892e1e6b48
3 changed files with 19 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ namespace GravatarWrapper.Test
[TestMethod]
public void TestMethod1()
{
var req = GravatarWrapper.Request("test@mctest.com", 400, true);
var req = GravatarWrapper.Request("test@mctest.com", 400, false);
if (req != null)
{
req.Save(@"c:\users\test\Desktop\bmp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GravatarWrapper.Exceptions
{
class NoResponseReturnedException : Exception
{
public NoResponseReturnedException()
: base("No response returned from server"){}
}
}

View File

@@ -7,6 +7,8 @@ using System.Security.Cryptography;
using RestSharp;
using System.Drawing;
using System.IO;
using GravatarWrapper;
using GravatarWrapper.Exceptions;
namespace GravatarWrapper
{
@@ -34,7 +36,7 @@ namespace GravatarWrapper
{
var client = new RestClient("http://www.gravatar.com/avatar/" + HashEmailForGravatar(email));
var req = new RestRequest(Method.GET);
if (ShowDefaultImage) req.AddParameter("d", "%22%22" );
if (!ShowDefaultImage) req.AddParameter("d", "%22%22" );
req.AddParameter("s", size);
var res = client.Execute(req);
if (res != null)
@@ -47,7 +49,7 @@ namespace GravatarWrapper
}
}
return null;
throw new NoResponseReturnedException();
}
}
}