Merge remote-tracking branch 'upstream/master'

This commit is contained in:
rodkings
2015-05-03 17:01:27 -06:00
28 changed files with 621 additions and 97 deletions

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
**/.settings
# Build results
[Dd]ebug/
[Dd]ebugPublic/

View File

@@ -46,6 +46,17 @@ var t = new Repository().Get<ActivityFeed>(ts);
```
For Actions (usually post requests). Note: Actions return a dynamic object. Usually these responses are not needed, and you should still be able to use the dynamic object's data. If strong typed returns is required feel free to file an issue. However we don't predict people will really need to care about the returns of these actions.
```csharp
var ts = new AuthenticatedUntappdCredentials("token", "key", "secret");
var checkin = new CheckIn("-5", "EST", 1044097) { Shout = "Awesome Brew", Rating = 4 };
var response = repository.Post(ts, checkin);
```
## Contributing
* Everyone is welcome to contribute!

View File

@@ -1,4 +1,4 @@
version: 0.2.{build}
version: 0.3.{build}
configuration: Release
notifications:
- provider: Webhook

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
@@ -6,7 +7,7 @@ using RestSharp;
using Untappd.Net.Client;
using Untappd.Net.Request;
using Untappd.Net.Responses.BeerInfo;
using System.Threading.Tasks;
using Untappd.Net.Responses.Actions;
namespace Untappd.Net.UnitTests.Request
{
@@ -19,7 +20,7 @@ namespace Untappd.Net.UnitTests.Request
var mockCreds = new Mock<IUnAuthenticatedUntappdCredentials>();
mockCreds.Setup(a => a.ClientId).Returns("id");
mockCreds.Setup(a => a.ClientSecret).Returns("secret");
var bodyParam = new Dictionary<string, string> {{"key", "value"}};
var bodyParam = new Dictionary<string, object> {{"key", "value"}};
var client = new Mock<IRestClient>();
var request = new Mock<IRestRequest>();
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
@@ -54,6 +55,15 @@ namespace Untappd.Net.UnitTests.Request
repository.GetAsync<BeerInfo>(mockAuthCreds.Object, "awesome", bodyParam).Wait();
request.Verify(a => a.AddParameter("key", "value"));
request.Verify(a => a.AddParameter("access_token", "accessToken"));
mockAuthCreds.Setup(a => a.AccessToken).Returns("PostaccessToken");
var checkin = new CheckIn("-5", "EST", 1044097) { Shout = "Awesome Brew", Rating = 4 };
repository.Post(mockAuthCreds.Object, checkin);
request.Verify(a => a.AddParameter("access_token", "PostaccessToken"));
mockAuthCreds.Setup(a => a.AccessToken).Returns("PostAsyncaccessToken");
repository.PostAsync(mockAuthCreds.Object, checkin).Wait();
request.Verify(a => a.AddParameter("access_token", "PostAsyncaccessToken"));
}
[Test]
@@ -67,9 +77,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);
}
}

View File

@@ -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<ArgumentNullException>(() => { new CheckIn(string.Empty, "timezone", 1); });
Assert.Throws<ArgumentNullException>(() => { new CheckIn("1", string.Empty, 1); });
var checkin = new CheckIn("offset", "timezone", 1);
Assert.IsNotNullOrEmpty(checkin.RequestMethod.ToString());
Assert.Throws<ArgumentOutOfRangeException>(() => { checkin.Rating = -1; });
Assert.Throws<ArgumentOutOfRangeException>(() => { checkin.Rating = 6; });
Assert.Throws<ArgumentOutOfRangeException>(() => { 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);
}
}
}

View File

@@ -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<ArgumentNullException>(() => { new AcceptFriend(string.Empty); });
Assert.Throws<ArgumentNullException>(() => { new AddFriend(string.Empty); });
Assert.Throws<ArgumentNullException>(() => { new RemoveFriend(string.Empty); });
Assert.Throws<ArgumentNullException>(() => { new ToastUntoast(string.Empty); });
Assert.Throws<ArgumentNullException>(() => { new AddComment(string.Empty, "ds"); });
Assert.Throws<ArgumentNullException>(() => { new AddComment("ds", string.Empty); });
Assert.Throws<ArgumentOutOfRangeException>(() => { new AddComment("ds", new String('d', 141)); });
}
}
}

View File

@@ -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<string, string> parameters = new Dictionary<string, string>();
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("q", "wild rose");
var repo = new Repository();

View File

@@ -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;

View File

@@ -69,6 +69,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Responses\Actions\TestCheckInAction.cs" />
<Compile Include="Responses\Actions\TestSimpleActions.cs" />
<Compile Include="Responses\TestDeserializer.cs" />
<Compile Include="Authentication\TestAuthenticationHelper.cs" />
<Compile Include="Client\TestAuthenticatedUntappdCredentials.cs" />

View File

@@ -1,6 +1,8 @@
namespace Untappd.Net.Exception
using System;
namespace Untappd.Net.Exception
{
[System.Serializable]
[Serializable]
public class EndpointConfigurationException : BaseUntappdException
{
/// <summary>

View File

@@ -0,0 +1,12 @@
using System.Collections.Generic;
using RestSharp;
namespace Untappd.Net.Request
{
public interface IAction
{
Method RequestMethod { get; }
string EndPoint { get; }
IDictionary<string, object> BodyParameters { get; }
}
}

View File

@@ -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<string, string> bodyParameters = null)
internal void ConfigureRequest(string endPoint, IDictionary<string, object> bodyParameters = null , Method webMethod = Method.GET)
{
Request.Resource = endPoint;
Request.Method = webMethod;
@@ -38,83 +36,13 @@ namespace Untappd.Net.Request
}
/// <summary>
/// Get the things!
/// </summary>
/// <typeparam name="TResult">What you want to request</typeparam>
/// <param name="credentials">Pass in a credentials object</param>
/// <param name="urlParameter">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</param>
/// <param name="bodyParameters">Any additional params you wish to add to the request</param>
/// <returns></returns>
public TResult Get<TResult> (IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary<string, string> bodyParameters = null)
where TResult : IUnAuthenticatedRequest,new()
private TResult ExecuteRequest<TResult>()
{
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<TResult>();
}
/// <summary>
/// Get the things! Async!
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="credentials"></param>
/// <param name="urlParameter"></param>
/// <param name="bodyParameters"></param>
/// <returns></returns>
public Task<TResult> GetAsync<TResult>(IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary<string, string> 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<TResult>();
}
/// <summary>
/// Get the things! authenticated!
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="credentials">Pass in a credentials object</param>
/// <param name="urlParameter">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</param>
/// <param name="bodyParameters">Any additional params you wish to add to the request</param>
/// <returns></returns>
public TResult Get<TResult>(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary<string, string> 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<TResult>();
}
/// <summary>
/// Get the things Authenticated! Async!!
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="credentials"></param>
/// <param name="urlParameter"></param>
/// <param name="bodyParameters"></param>
/// <returns></returns>
public Task<TResult> GetAsync<TResult>(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary<string, string> 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<TResult>();
}
private TResult DoRestRequest<TResult>()
{
var response = Client.Execute(this.Request);
var response = Client.Execute(Request);
return JsonConvert.DeserializeObject<TResult>(response.Content);
}
private async Task<TResult> DoRestRequestAsync<TResult>()
private async Task<TResult> ExecuteRequestAsync<TResult>()
{
var response = await Client.ExecuteTaskAsync(Request);
return JsonConvert.DeserializeObject<TResult>(response.Content);

View File

@@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Untappd.Net.Client;
namespace Untappd.Net.Request
{
public partial class Repository
{
/// <summary>
/// Get the things!
/// </summary>
/// <typeparam name="TResult">What you want to request</typeparam>
/// <param name="credentials">Pass in a credentials object</param>
/// <param name="urlParameter">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</param>
/// <param name="bodyParameters">Any additional params you wish to add to the request</param>
/// <returns></returns>
public TResult Get<TResult>(IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary<string, object> 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<TResult>();
}
/// <summary>
/// Get the things! Async!
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="credentials"></param>
/// <param name="urlParameter"></param>
/// <param name="bodyParameters"></param>
/// <returns></returns>
public Task<TResult> GetAsync<TResult>(IUnAuthenticatedUntappdCredentials credentials, string urlParameter, IDictionary<string, object> 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<TResult>();
}
/// <summary>
/// Get the things! authenticated!
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="credentials">Pass in a credentials object</param>
/// <param name="urlParameter">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</param>
/// <param name="bodyParameters">Any additional params you wish to add to the request</param>
/// <returns></returns>
public TResult Get<TResult>(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary<string, object> bodyParameters = null)
where TResult : IAuthenticatedRequest, new()
{
var result = new TResult();
ConfigureRequest(result.EndPoint(urlParameter), bodyParameters);
Request.AddParameter("access_token", credentials.AccessToken);
return ExecuteRequest<TResult>();
}
/// <summary>
/// Get the things Authenticated! Async!!
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="credentials"></param>
/// <param name="urlParameter"></param>
/// <param name="bodyParameters"></param>
/// <returns></returns>
public Task<TResult> GetAsync<TResult>(IAuthenticatedUntappdCredentials credentials, string urlParameter = "", IDictionary<string, object> bodyParameters = null)
where TResult : IAuthenticatedRequest, new()
{
var result = new TResult();
ConfigureRequest(result.EndPoint(urlParameter), bodyParameters);
Request.AddParameter("access_token", credentials.AccessToken);
return ExecuteRequestAsync<TResult>();
}
}
}

View File

@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using Untappd.Net.Client;
namespace Untappd.Net.Request
{
public partial class Repository
{
/// <summary>
/// do a post with actions
/// </summary>
/// <param name="credentials"></param>
/// <param name="action"></param>
/// <returns>returns dynamic since often the return doesn't matter</returns>
public dynamic Post(IAuthenticatedUntappdCredentials credentials, IAction action)
{
ConfigureRequest(action.EndPoint, action.BodyParameters, action.RequestMethod);
Request.AddParameter("access_token", credentials.AccessToken);
return ExecuteRequest<dynamic>();
}
/// <summary>
/// do a post with actions, Async!
/// </summary>
/// <param name="credentials"></param>
/// <param name="action"></param>
/// <returns>returns dynamic since often the return doesn't matter</returns>
public Task<dynamic> PostAsync(IAuthenticatedUntappdCredentials credentials, IAction action)
{
ConfigureRequest(action.EndPoint, action.BodyParameters, action.RequestMethod);
Request.AddParameter("access_token", credentials.AccessToken);
return ExecuteRequestAsync<dynamic>();
}
}
}

View File

@@ -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<string, object> BodyParameters { get { return new Dictionary<string, object>(); } }
public AcceptFriend(string target_id)
{
if (string.IsNullOrWhiteSpace(target_id))
{
throw new ArgumentNullException("target_id");
}
EndPoint = string.Format("v4/friend/accept/{0}", target_id);
}
}
}

View File

@@ -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<string, object> 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<string, object> {{shout, shout}};
}
}
}

View File

@@ -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<string, object> BodyParameters { get{ return new Dictionary<string, object>();} }
public AddFriend(string target_id)
{
if (string.IsNullOrWhiteSpace(target_id))
{
throw new ArgumentNullException("target_id");
}
EndPoint = string.Format("v4/friend/request/{0}", target_id);
}
}
}

View File

@@ -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<string, object> BodyParameters { get; private set; }
public AddToWishList(int beerId)
{
BodyParameters = new Dictionary<string, object>() { { "bid", beerId } };
}
}
}

View File

@@ -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<string, object> BodyParameters
{
get
{
var dict = new Dictionary<string, object>
{
{"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;
}
}
}

View File

@@ -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<string, object> BodyParameters
{
get
{
var dict = new Dictionary<string, object>();
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; }
}
}

View File

@@ -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<string, object> BodyParameters { get { return new Dictionary<string, object>(); } }
public RemoveFriend(string target_id)
{
if (string.IsNullOrWhiteSpace(target_id))
{
throw new ArgumentNullException("target_id");
}
EndPoint = string.Format("v4/friend/reject/{0}", target_id);
}
}
}

View File

@@ -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<string, object> BodyParameters { get; private set; }
public RemoveFromWishList(int beerId)
{
BodyParameters = new Dictionary<string, object>() { { "bid", beerId } };
}
}
}

View File

@@ -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<string, object> BodyParameters { get { return new Dictionary<string, object>(); } }
public string EndPoint { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="checkinId"></param>
/// <exception cref="ArgumentNullException"></exception>
public ToastUntoast(string checkinId)
{
if (string.IsNullOrWhiteSpace(checkinId))
{
throw new ArgumentNullException("checkinId");
}
EndPoint = string.Format("v4/checkin/toast/{0}", checkinId);
}
}
}

View File

@@ -331,7 +331,7 @@ namespace Untappd.Net.Responses.Feeds.ActivityFeed
[JsonProperty("count")]
public int Count { get; set; }
[JsonProperty("auth_toast")]
[JsonProperty("auth_toast", NullValueHandling = NullValueHandling.Ignore)]
public bool AuthToast { get; set; }
[JsonProperty("items")]
@@ -516,6 +516,7 @@ namespace Untappd.Net.Responses.Feeds.ActivityFeed
public Meta Meta { get; set; }
[JsonProperty("notifications")]
[JsonConverter(typeof(SingleObjectArrayConverter<Notifications>))]
public Notifications Notifications { get; set; }
[JsonProperty("response")]

View File

@@ -348,7 +348,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed
[JsonProperty("count")]
public int Count { get; set; }
[JsonProperty("auth_toast")]
[JsonProperty("auth_toast", NullValueHandling = NullValueHandling.Ignore)]
public bool AuthToast { get; set; }
[JsonProperty("items")]
@@ -483,6 +483,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed
public Meta Meta { get; set; }
[JsonProperty("notifications")]
[JsonConverter(typeof(SingleObjectArrayConverter<Notifications>))]
public Notifications Notifications { get; set; }
[JsonProperty("response")]

View File

@@ -872,6 +872,7 @@ namespace Untappd.Net.Responses.UserInfo
public Meta Meta { get; set; }
[JsonProperty("notifications")]
[JsonConverter(typeof(SingleObjectArrayConverter<Notifications>))]
public Notifications Notifications { get; set; }
[JsonProperty("response")]

View File

@@ -1,6 +1,5 @@
using System;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net
{

View File

@@ -47,6 +47,18 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Authentication\AuthenticationHelper.cs" />
<Compile Include="Request\IAction.cs" />
<Compile Include="Request\RepositoryGet.cs" />
<Compile Include="Request\RepositoryPost.cs" />
<Compile Include="Responses\Actions\RemoveFromWishList.cs" />
<Compile Include="Responses\Actions\AddToWishList.cs" />
<Compile Include="Responses\Actions\AddComment.cs" />
<Compile Include="Responses\Actions\CheckIn.cs" />
<Compile Include="Responses\Actions\PendingFriends.cs" />
<Compile Include="Responses\Actions\AcceptFriend.cs" />
<Compile Include="Responses\Actions\RemoveFriend.cs" />
<Compile Include="Responses\Actions\AddFriend.cs" />
<Compile Include="Responses\Actions\ToastUntoast.cs" />
<Compile Include="SingleObjectArrayConverter.cs" />
<Compile Include="Client\AuthenticatedUntappdCredentials.cs" />
<Compile Include="Client\IAuthenticatedUntappdCredentials.cs" />
@@ -79,9 +91,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Responses\Actions\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.