diff --git a/appveyor.yml b/appveyor.yml index 488e610..46bf967 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.2.{build} +version: 0.3.{build} configuration: Release notifications: - provider: Webhook diff --git a/src/Untappd.Net.UnitTests/Request/TestRepository.cs b/src/Untappd.Net.UnitTests/Request/TestRepository.cs index 9a5b815..5b89871 100644 --- a/src/Untappd.Net.UnitTests/Request/TestRepository.cs +++ b/src/Untappd.Net.UnitTests/Request/TestRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using Moq; using Newtonsoft.Json; using NUnit.Framework; @@ -6,7 +7,6 @@ using RestSharp; using Untappd.Net.Client; using Untappd.Net.Request; using Untappd.Net.Responses.BeerInfo; -using System.Threading.Tasks; namespace Untappd.Net.UnitTests.Request { @@ -19,7 +19,7 @@ namespace Untappd.Net.UnitTests.Request var mockCreds = new Mock(); mockCreds.Setup(a => a.ClientId).Returns("id"); mockCreds.Setup(a => a.ClientSecret).Returns("secret"); - var bodyParam = new Dictionary {{"key", "value"}}; + var bodyParam = new Dictionary {{"key", "value"}}; var client = new Mock(); var request = new Mock(); request.Setup(a => a.AddParameter(It.IsAny(), It.IsAny())); @@ -67,9 +67,9 @@ namespace Untappd.Net.UnitTests.Request public void ConfirmConfigureGetRequestClearsParams() { var constructorTest = new Repository(); - constructorTest.Request.Parameters.Add(new Parameter(){Name = "param"}); + constructorTest.Request.Parameters.Add(new Parameter {Name = "param"}); Assert.IsTrue(constructorTest.Request.Parameters.Count > 0); - constructorTest.ConfigureGetRequest("endpoint"); + constructorTest.ConfigureRequest("endpoint"); Assert.IsTrue(constructorTest.Request.Parameters.Count == 0); } } diff --git a/src/Untappd.Net.UnitTests/Responses/Actions/TestCheckInAction.cs b/src/Untappd.Net.UnitTests/Responses/Actions/TestCheckInAction.cs new file mode 100644 index 0000000..09df9b1 --- /dev/null +++ b/src/Untappd.Net.UnitTests/Responses/Actions/TestCheckInAction.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Untappd.Net.Responses.Actions; + +namespace Untappd.Net.UnitTests.Responses.Actions +{ + [TestFixture] + public class TestCheckInAction + { + [Test] + public void TestAccessors() + { + Assert.Throws(() => { new CheckIn(string.Empty, "timezone", 1); }); + Assert.Throws(() => { new CheckIn("1", string.Empty, 1); }); + var checkin = new CheckIn("offset", "timezone", 1); + Assert.IsNotNullOrEmpty(checkin.RequestMethod.ToString()); + Assert.Throws(() => { checkin.Rating = -1; }); + Assert.Throws(() => { checkin.Rating = 6; }); + Assert.Throws(() => { checkin.Shout = new String('d', 141); }); + checkin.Rating = 3; + Assert.AreEqual(3, checkin.Rating); + var t = "tst"; + checkin.Shout = t; + Assert.IsNotNullOrEmpty(checkin.EndPoint); + Assert.AreEqual(checkin.Shout, t); + } + + [Test] + public void TestDictionaryGeneration() + { + var checkin = new CheckIn("offset", "timezone", 1); + Assert.AreEqual(checkin.BodyParameters["gmt_offset"], "offset"); + Assert.AreEqual(checkin.BodyParameters["timezone"], "timezone"); + Assert.AreEqual(checkin.BodyParameters["bid"], 1); + + Assert.IsFalse(checkin.BodyParameters.ContainsKey("geolat")); + checkin.Geolat = 4; + Assert.IsTrue(checkin.BodyParameters.ContainsKey("geolat")); + Assert.AreEqual(checkin.BodyParameters["geolat"], 4); + + Assert.IsFalse(checkin.BodyParameters.ContainsKey("geolng")); + checkin.Geolng = 4; + Assert.IsTrue(checkin.BodyParameters.ContainsKey("geolng")); + Assert.AreEqual(checkin.BodyParameters["geolng"], 4); + + Assert.IsFalse(checkin.BodyParameters.ContainsKey("shout")); + checkin.Shout = "shout"; + Assert.IsTrue(checkin.BodyParameters.ContainsKey("shout")); + Assert.AreEqual(checkin.BodyParameters["shout"], "shout"); + + Assert.IsFalse(checkin.BodyParameters.ContainsKey("rating")); + checkin.Rating = 2; + Assert.IsTrue(checkin.BodyParameters.ContainsKey("rating")); + Assert.AreEqual(checkin.BodyParameters["rating"], 2); + + + + } + + } +} diff --git a/src/Untappd.Net.UnitTests/Responses/Actions/TestSimpleActions.cs b/src/Untappd.Net.UnitTests/Responses/Actions/TestSimpleActions.cs new file mode 100644 index 0000000..9aa1429 --- /dev/null +++ b/src/Untappd.Net.UnitTests/Responses/Actions/TestSimpleActions.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Untappd.Net.Responses.Actions; + +namespace Untappd.Net.UnitTests.Responses.Actions +{ + [TestFixture] + public class TestSimpleActions + { + [Test] + public void TestFriends() + { + var accept = new AcceptFriend("targetid"); + Assert.IsNotNullOrEmpty(accept.RequestMethod.ToString()); + Assert.IsTrue(accept.EndPoint.Contains("targetid")); + Assert.IsNotNull(accept.BodyParameters); + + var add = new AddFriend("targetid"); + Assert.IsNotNullOrEmpty(add.RequestMethod.ToString()); + Assert.IsTrue(add.EndPoint.Contains("targetid")); + Assert.IsNotNull(add.BodyParameters); + + var toast = new ToastUntoast("targetid"); + Assert.IsNotNullOrEmpty(toast.RequestMethod.ToString()); + Assert.IsTrue(toast.EndPoint.Contains("targetid")); + Assert.IsNotNull(toast.BodyParameters); + + var remove = new RemoveFriend("targetid"); + Assert.IsNotNullOrEmpty(remove.RequestMethod.ToString()); + Assert.IsTrue(remove.EndPoint.Contains("targetid")); + Assert.IsNotNull(remove.BodyParameters); + + var removeWish = new RemoveFromWishList(1); + Assert.IsNotNullOrEmpty(removeWish.RequestMethod.ToString()); + Assert.IsNotNullOrEmpty(removeWish.EndPoint); + Assert.AreEqual(removeWish.BodyParameters["bid"], 1); + + + var addWish = new AddToWishList(1); + Assert.IsNotNullOrEmpty(addWish.RequestMethod.ToString()); + Assert.IsNotNullOrEmpty(addWish.EndPoint); + Assert.AreEqual(addWish.BodyParameters["bid"], 1); + + var comment = new AddComment("checkin", "shout"); + Assert.IsNotNullOrEmpty(comment.RequestMethod.ToString()); + Assert.IsTrue(comment.EndPoint.Contains("checkin")); + Assert.AreEqual(comment.BodyParameters["shout"], "shout"); + } + + [Test] + public void TestPendingFriends() + { + var pending = new PendingFriends(); + Assert.IsNotNullOrEmpty(pending.RequestMethod.ToString()); + Assert.IsNotNullOrEmpty(pending.EndPoint); + Assert.IsNotNull(pending.BodyParameters); + Assert.IsFalse(pending.BodyParameters.ContainsKey("limit")); + pending.Limit = 1; + Assert.IsTrue(pending.BodyParameters.ContainsKey("limit")); + Assert.IsFalse(pending.BodyParameters.ContainsKey("offset")); + pending.Offset = 1; + Assert.IsTrue(pending.BodyParameters.ContainsKey("offset")); + } + + [Test] + public void TestArgumentNull() + { + Assert.Throws(() => { new AcceptFriend(string.Empty); }); + Assert.Throws(() => { new AddFriend(string.Empty); }); + Assert.Throws(() => { new RemoveFriend(string.Empty); }); + Assert.Throws(() => { new ToastUntoast(string.Empty); }); + Assert.Throws(() => { new AddComment(string.Empty, "ds"); }); + Assert.Throws(() => { new AddComment("ds", string.Empty); }); + Assert.Throws(() => { new AddComment("ds", new String('d', 141)); }); + } + } +} diff --git a/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs b/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs index 1486e1f..7a3889f 100644 --- a/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs +++ b/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using Newtonsoft.Json; using NUnit.Framework; @@ -16,7 +17,6 @@ using Untappd.Net.Responses.UserInfo; using Untappd.Net.Responses.VenueInfo; using UserDistinctBeers = Untappd.Net.Responses.UserDistinctBeer; using UserWishList = Untappd.Net.Responses.UserWishlist; -using System; namespace Untappd.Net.UnitTests { @@ -31,7 +31,7 @@ namespace Untappd.Net.UnitTests { var credentials = new AuthenticatedUntappdCredentials(""); - Dictionary parameters = new Dictionary(); + Dictionary parameters = new Dictionary(); parameters.Add("q", "wild rose"); var repo = new Repository(); diff --git a/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs b/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs index deba7af..d4eba9d 100644 --- a/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs +++ b/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using NUnit.Framework; using Untappd.Net.Request; diff --git a/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj b/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj index 9bb0afb..d5a937d 100644 --- a/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj +++ b/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj @@ -69,6 +69,8 @@ + + diff --git a/src/Untappd.Net/Exception/EndpointConfigurationException.cs b/src/Untappd.Net/Exception/EndpointConfigurationException.cs index 2d9786d..14db0d5 100644 --- a/src/Untappd.Net/Exception/EndpointConfigurationException.cs +++ b/src/Untappd.Net/Exception/EndpointConfigurationException.cs @@ -1,6 +1,8 @@ -namespace Untappd.Net.Exception +using System; + +namespace Untappd.Net.Exception { - [System.Serializable] + [Serializable] public class EndpointConfigurationException : BaseUntappdException { /// diff --git a/src/Untappd.Net/Request/IAction.cs b/src/Untappd.Net/Request/IAction.cs new file mode 100644 index 0000000..c169757 --- /dev/null +++ b/src/Untappd.Net/Request/IAction.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using RestSharp; + +namespace Untappd.Net.Request +{ + public interface IAction + { + Method RequestMethod { get; } + string EndPoint { get; } + IDictionary BodyParameters { get; } + } +} diff --git a/src/Untappd.Net/Request/Repository.cs b/src/Untappd.Net/Request/Repository.cs index d398ff8..ad0af81 100644 --- a/src/Untappd.Net/Request/Repository.cs +++ b/src/Untappd.Net/Request/Repository.cs @@ -1,13 +1,11 @@ using System.Collections.Generic; +using System.Threading.Tasks; using Newtonsoft.Json; using RestSharp; -using Untappd.Net.Client; -using System.Threading.Tasks; -using System.Threading; namespace Untappd.Net.Request { - public class Repository + public partial class Repository { internal IRestClient Client; internal IRestRequest Request; @@ -24,7 +22,7 @@ namespace Untappd.Net.Request Request = request; } - internal void ConfigureGetRequest(string endPoint, Method webMethod = Method.GET, IDictionary bodyParameters = null) + internal void ConfigureRequest(string endPoint, IDictionary bodyParameters = null , Method webMethod = Method.GET) { Request.Resource = endPoint; Request.Method = webMethod; @@ -38,83 +36,13 @@ namespace Untappd.Net.Request } - /// - /// Get the things! - /// - /// What you want to request - /// Pass in a credentials object - /// this is the main parameter for a request. ie v4/user/checkins/urlParameter. Consult the untappd docs, this can be null for a few requests - /// Any additional params you wish to add to the request - /// - public TResult Get (IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary bodyParameters = null) - where TResult : IUnAuthenticatedRequest,new() + private TResult ExecuteRequest() { - var result = new TResult(); - ConfigureGetRequest(result.EndPoint(urlParameter), Method.GET, bodyParameters); - Request.AddParameter("client_id", credentials.ClientId); - Request.AddParameter("client_secret", credentials.ClientSecret); - return DoRestRequest(); - } - - /// - /// Get the things! Async! - /// - /// - /// - /// - /// - /// - public Task GetAsync(IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary bodyParameters = null) - where TResult : IUnAuthenticatedRequest, new() - { - var result = new TResult(); - ConfigureGetRequest(result.EndPoint(urlParameter), Method.GET, bodyParameters); - Request.AddParameter("client_id", credentials.ClientId); - Request.AddParameter("client_secret", credentials.ClientSecret); - return DoRestRequestAsync(); - } - - /// - /// Get the things! authenticated! - /// - /// - /// Pass in a credentials object - /// this is the main parameter for a request. ie v4/user/checkins/urlParameter. Consult the untappd docs, this can be null for a few requests - /// Any additional params you wish to add to the request - /// - public TResult Get(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary bodyParameters = null) - where TResult : IAuthenticatedRequest, new() - { - var result = new TResult(); - ConfigureGetRequest(result.EndPoint(urlParameter), Method.GET, bodyParameters); - Request.AddParameter("access_token", credentials.AccessToken); - return DoRestRequest(); - } - - /// - /// Get the things Authenticated! Async!! - /// - /// - /// - /// - /// - /// - public Task GetAsync(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary bodyParameters = null) - where TResult : IAuthenticatedRequest, new() - { - var result = new TResult(); - ConfigureGetRequest(result.EndPoint(urlParameter), Method.GET, bodyParameters); - Request.AddParameter("access_token", credentials.AccessToken); - return DoRestRequestAsync(); - } - - private TResult DoRestRequest() - { - var response = Client.Execute(this.Request); + var response = Client.Execute(Request); return JsonConvert.DeserializeObject(response.Content); } - private async Task DoRestRequestAsync() + private async Task ExecuteRequestAsync() { var response = await Client.ExecuteTaskAsync(Request); return JsonConvert.DeserializeObject(response.Content); diff --git a/src/Untappd.Net/Request/RepositoryGet.cs b/src/Untappd.Net/Request/RepositoryGet.cs new file mode 100644 index 0000000..08a21c4 --- /dev/null +++ b/src/Untappd.Net/Request/RepositoryGet.cs @@ -0,0 +1,79 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Untappd.Net.Client; + +namespace Untappd.Net.Request +{ + public partial class Repository + { + /// + /// Get the things! + /// + /// What you want to request + /// Pass in a credentials object + /// this is the main parameter for a request. ie v4/user/checkins/urlParameter. Consult the untappd docs, this can be null for a few requests + /// Any additional params you wish to add to the request + /// + public TResult Get(IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary bodyParameters = null) + where TResult : IUnAuthenticatedRequest, new() + { + var result = new TResult(); + ConfigureRequest(result.EndPoint(urlParameter), bodyParameters); + Request.AddParameter("client_id", credentials.ClientId); + Request.AddParameter("client_secret", credentials.ClientSecret); + return ExecuteRequest(); + } + + /// + /// Get the things! Async! + /// + /// + /// + /// + /// + /// + public Task GetAsync(IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary bodyParameters = null) + where TResult : IUnAuthenticatedRequest, new() + { + var result = new TResult(); + ConfigureRequest(result.EndPoint(urlParameter), bodyParameters); + Request.AddParameter("client_id", credentials.ClientId); + Request.AddParameter("client_secret", credentials.ClientSecret); + return ExecuteRequestAsync(); + } + + /// + /// Get the things! authenticated! + /// + /// + /// Pass in a credentials object + /// this is the main parameter for a request. ie v4/user/checkins/urlParameter. Consult the untappd docs, this can be null for a few requests + /// Any additional params you wish to add to the request + /// + public TResult Get(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary bodyParameters = null) + where TResult : IAuthenticatedRequest, new() + { + var result = new TResult(); + ConfigureRequest(result.EndPoint(urlParameter), bodyParameters); + Request.AddParameter("access_token", credentials.AccessToken); + return ExecuteRequest(); + } + + /// + /// Get the things Authenticated! Async!! + /// + /// + /// + /// + /// + /// + public Task GetAsync(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary bodyParameters = null) + where TResult : IAuthenticatedRequest, new() + { + var result = new TResult(); + ConfigureRequest(result.EndPoint(urlParameter), bodyParameters); + Request.AddParameter("access_token", credentials.AccessToken); + return ExecuteRequestAsync(); + } + } +} diff --git a/src/Untappd.Net/Request/RepositoryPost.cs b/src/Untappd.Net/Request/RepositoryPost.cs new file mode 100644 index 0000000..ee1e3d7 --- /dev/null +++ b/src/Untappd.Net/Request/RepositoryPost.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using Untappd.Net.Client; + +namespace Untappd.Net.Request +{ + public partial class Repository + { + /// + /// do a post with actions + /// + /// + /// + /// returns dynamic since often the return doesn't matter + public dynamic Post(IAuthenticatedUntappdCredentials credentials, IAction action) + { + ConfigureRequest(action.EndPoint, action.BodyParameters, action.RequestMethod); + Request.AddParameter("access_token", credentials.AccessToken); + return ExecuteRequest(); + } + + /// + /// do a post with actions, Async! + /// + /// + /// + /// returns dynamic since often the return doesn't matter + public Task PostAsync(IAuthenticatedUntappdCredentials credentials, IAction action) + { + ConfigureRequest(action.EndPoint, action.BodyParameters, action.RequestMethod); + Request.AddParameter("access_token", credentials.AccessToken); + return ExecuteRequestAsync(); + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/AcceptFriend.cs b/src/Untappd.Net/Responses/Actions/AcceptFriend.cs new file mode 100644 index 0000000..7003de0 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/AcceptFriend.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class AcceptFriend : IAction + { + public Method RequestMethod { get { return Method.GET; } } + public string EndPoint { get; private set; } + public IDictionary BodyParameters { get { return new Dictionary(); } } + public AcceptFriend(string target_id) + { + if (string.IsNullOrWhiteSpace(target_id)) + { + throw new ArgumentNullException("target_id"); + } + EndPoint = string.Format("v4/friend/accept/{0}", target_id); + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/AddComment.cs b/src/Untappd.Net/Responses/Actions/AddComment.cs new file mode 100644 index 0000000..7c088f4 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/AddComment.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class AddComment : IAction + { + public Method RequestMethod { get {return Method.POST;} } + public string EndPoint { get; private set; } + public IDictionary BodyParameters { get; private set; } + public AddComment(string checkinId, string shout) + { + if (string.IsNullOrWhiteSpace(checkinId)) + { + throw new ArgumentNullException("checkinId"); + } + if (string.IsNullOrWhiteSpace(shout)) + { + throw new ArgumentNullException("shout"); + } + if (shout.Length > 140) + { + throw new ArgumentOutOfRangeException("shout", shout, "Shout cannot be more than 140 characters"); + } + EndPoint = string.Format("v4/checkin/addcomment/{0}", checkinId); + BodyParameters = new Dictionary {{shout, shout}}; + + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/AddFriend.cs b/src/Untappd.Net/Responses/Actions/AddFriend.cs new file mode 100644 index 0000000..c67fca6 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/AddFriend.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class AddFriend : IAction + { + public Method RequestMethod { get{return Method.GET;} } + public string EndPoint { get; private set; } + public IDictionary BodyParameters { get{ return new Dictionary();} } + public AddFriend(string target_id) + { + if (string.IsNullOrWhiteSpace(target_id)) + { + throw new ArgumentNullException("target_id"); + } + EndPoint = string.Format("v4/friend/request/{0}", target_id); + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/AddToWishList.cs b/src/Untappd.Net/Responses/Actions/AddToWishList.cs new file mode 100644 index 0000000..991fb3f --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/AddToWishList.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class AddToWishList : IAction + { + public Method RequestMethod { get {return Method.GET;} } + public string EndPoint { get { return "v4/user/wishlist/add"; } } + public IDictionary BodyParameters { get; private set; } + public AddToWishList(int beerId) + { + BodyParameters = new Dictionary() { { "bid", beerId } }; + + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/CheckIn.cs b/src/Untappd.Net/Responses/Actions/CheckIn.cs new file mode 100644 index 0000000..9682366 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/CheckIn.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class CheckIn : IAction + { + private short _rating; + private string _shout; + public Method RequestMethod { get{ return Method.POST;} } + public string EndPoint { get { return "v4/checkin/add"; } } + + public IDictionary BodyParameters + { + get + { + var dict = new Dictionary + { + {"gmt_offset", GmtOffset}, + {"timezone", Timezone}, + {"bid", Bid} + }; + if (Geolat.HasValue) + { + dict.Add("geolat", Geolat.Value); + } + if (Geolng.HasValue) + { + dict.Add("geolng", Geolng.Value); + } + if (!string.IsNullOrWhiteSpace(Shout) && Shout.Length <= 140) + { + dict.Add("shout", Shout); + } + if (Rating > 0 && Rating < 6) + { + dict.Add("rating", Rating); + } + return dict; + } + } + + public string GmtOffset { get; private set; } + public string Timezone { get; private set; } + public int Bid { get; private set; } + public int? Geolat { get; set; } + public int? Geolng { get; set; } + + public string Shout + { + get { return _shout; } + set + { + if (value.Length > 140) + { + throw new ArgumentOutOfRangeException("value", value,"Shout can be no more than 140 characters"); + } + _shout = string.Copy(value); + } + } + + public short Rating + { + get { return _rating; } + set + { + if (value < 1 || value > 5) + { + throw new ArgumentOutOfRangeException("value", value, "Ratings should be between 1 and 5"); + } + _rating = value; + } + } + + + public CheckIn(string gmtOffset, string timezone, int bid) + { + if (string.IsNullOrWhiteSpace(gmtOffset)) + { + throw new ArgumentNullException("gmtOffset"); + } + if (string.IsNullOrWhiteSpace(timezone)) + { + throw new ArgumentNullException("timezone"); + } + GmtOffset = string.Copy(gmtOffset); + Timezone = string.Copy(timezone); + Bid = bid; + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/PendingFriends.cs b/src/Untappd.Net/Responses/Actions/PendingFriends.cs new file mode 100644 index 0000000..aec06d3 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/PendingFriends.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class PendingFriends : IAction + { + public Method RequestMethod { get {return Method.GET;} } + public string EndPoint { get { return "v4/user/pending"; }} + + public IDictionary BodyParameters + { + get + { + var dict = new Dictionary(); + if (Offset.HasValue) + { + dict.Add("offset", Offset.Value); + } + if (Limit.HasValue) + { + dict.Add("limit", Limit.Value); + } + return dict; + } + } + + public int? Offset { get; set; } + public int? Limit { get; set; } + } +} diff --git a/src/Untappd.Net/Responses/Actions/RemoveFriend.cs b/src/Untappd.Net/Responses/Actions/RemoveFriend.cs new file mode 100644 index 0000000..0463da6 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/RemoveFriend.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class RemoveFriend : IAction + { + public Method RequestMethod { get { return Method.GET; } } + public string EndPoint { get; private set; } + public IDictionary BodyParameters { get { return new Dictionary(); } } + public RemoveFriend(string target_id) + { + if (string.IsNullOrWhiteSpace(target_id)) + { + throw new ArgumentNullException("target_id"); + } + EndPoint = string.Format("v4/friend/reject/{0}", target_id); + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/RemoveFromWishList.cs b/src/Untappd.Net/Responses/Actions/RemoveFromWishList.cs new file mode 100644 index 0000000..9623913 --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/RemoveFromWishList.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class RemoveFromWishList : IAction + { + public Method RequestMethod { get {return Method.GET;} } + public string EndPoint { get { return "v4/user/wishlist/delete"; } } + public IDictionary BodyParameters { get; private set; } + public RemoveFromWishList(int beerId) + { + BodyParameters = new Dictionary() { { "bid", beerId } }; + + } + } +} diff --git a/src/Untappd.Net/Responses/Actions/ToastUntoast.cs b/src/Untappd.Net/Responses/Actions/ToastUntoast.cs new file mode 100644 index 0000000..3fee33c --- /dev/null +++ b/src/Untappd.Net/Responses/Actions/ToastUntoast.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using RestSharp; +using Untappd.Net.Request; + +namespace Untappd.Net.Responses.Actions +{ + public class ToastUntoast : IAction + { + public Method RequestMethod { get { return Method.POST; } } + public IDictionary BodyParameters { get { return new Dictionary(); } } + public string EndPoint { get; private set; } + /// + /// + /// + /// + /// + public ToastUntoast(string checkinId) + { + if (string.IsNullOrWhiteSpace(checkinId)) + { + throw new ArgumentNullException("checkinId"); + } + EndPoint = string.Format("v4/checkin/toast/{0}", checkinId); + } + } +} diff --git a/src/Untappd.Net/SingleObjectArrayConverter.cs b/src/Untappd.Net/SingleObjectArrayConverter.cs index cbfc17e..1d5ce7b 100644 --- a/src/Untappd.Net/SingleObjectArrayConverter.cs +++ b/src/Untappd.Net/SingleObjectArrayConverter.cs @@ -1,6 +1,5 @@ using System; using Newtonsoft.Json; -using Untappd.Net.Request; namespace Untappd.Net { diff --git a/src/Untappd.Net/Untappd.Net.csproj b/src/Untappd.Net/Untappd.Net.csproj index f25d01e..a57e78c 100644 --- a/src/Untappd.Net/Untappd.Net.csproj +++ b/src/Untappd.Net/Untappd.Net.csproj @@ -47,6 +47,18 @@ + + + + + + + + + + + + @@ -79,9 +91,7 @@ - - - +