Merge pull request #10 from tparnell8/master

Release .2
This commit is contained in:
Tommy Parnell
2015-04-20 18:39:25 -04:00
35 changed files with 278 additions and 149 deletions

View File

@@ -2,6 +2,6 @@
<configuration>
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="Untappd.net Backup" value="https://www.myget.org/F/untappd-net/" />
<add key="Untappd.net Backup" value="https://www.myget.org/F/untappd-net/api/v2" />
</packageSources>
</configuration>

View File

@@ -4,7 +4,7 @@
**Tips:** [![Shameless tip badge tips](https://img.shields.io/gratipay/TommyParnell.svg)](https://gratipay.com/TommyParnell)
# Untappd.Net
This is a c# wrapper around the Untappd API. This can be downloaded via [Nuget](https://www.nuget.org/packages/Untappd.Net/)
This is a c# wrapper around the Untappd API. This can be downloaded via [Nuget](https://www.nuget.org/packages/Untappd.Net/), or the [backup feed](https://www.myget.org/F/untappd-net/api/v2).
## Coverage
@@ -13,7 +13,7 @@ So far only the Requests that do not require user tokens have been implemented
## How do I use?
* Request an [API Key](http://untappd.com/api/register)
* Request an [API Key](https://untappd.com/api/register?register=new)
* You should be able to make a repository and call the get method with the thing you are requesting.
Note: Additional parameters can be passed into the Get Method with an IDictionary.
@@ -29,14 +29,8 @@ var t = new Repository().Get<UserDistinctBeers>(ts, "tparnell");
## Contributing
* Everyone is welcome to contribute!
* If you are looking for something to do, look at the issues.
* There are no special instructions, submit pull requests against the master branch.
* Releases to nuget occur on successful release branch builds
* Releases to nuget occur on successful release branch builds.
* The only reason I do not publish on master, is because sometimes commits can just contain readme files, or unit tests changes that do not affect the nuget package
## TODO
* Actually Make unit tests
* Add authentication wrapper
* Implement API calls that require authentication tokens
* Coveralls?
* Code Quality?

View File

@@ -1,4 +1,4 @@
version: 0.1.{build}
version: 0.2.{build}
configuration: Release
assembly_info:
patch: true
@@ -23,7 +23,7 @@ deploy:
on:
branch: release
- provider: NuGet
server: https://www.myget.org/F/untappd-net/
server: https://www.myget.org/F/untappd-net/api/v2
api_key:
secure: wsN6BzH8ETiXhB9SndP57mHhivqM+CVnghI/+w5XE3bI8K092Z4V4FrJixcrxKnI
on:

View File

@@ -1,8 +1,8 @@
using System;
using NUnit.Framework;
using Untappd.Client.Net;
using Untappd.Net.Client;
using Untappd.Net.Request;
using Untappd.Net.Responses.UserDistinctBeer;
using Untappd.Net.Responses.UserInfo;
namespace Untappd.Net.UnitTests
{
@@ -13,8 +13,9 @@ namespace Untappd.Net.UnitTests
[Ignore]
public void Test()
{
var ts = new UnAuthenticatedUntappdCredentials("clientid", "clientkey");
var t = new Repository().Get<UserDistinctBeers>(ts, "tparnell");
var ts = new UnAuthenticatedUntappdCredentials("id", "scrt");
var t = new Repository().Get<UserInfo>(ts, "tparnell");
Console.WriteLine(t);
}
}

View File

@@ -0,0 +1,27 @@
using System;
using NUnit.Framework;
using Untappd.Net.Client;
namespace Untappd.Net.UnitTests.Client
{
[TestFixture]
public class TestAuthenticatedUntappdCredentials
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectException()
{
var t = new AuthenticatedUntappdCredentials(null, "d", "d");
}
[Test]
public void ExpectValid()
{
var token = "awesome";
var t = new AuthenticatedUntappdCredentials(token, "d", "d");
Assert.AreEqual(token, "awesome");
token = "newString";
//Make sure the reference is not copied over
Assert.AreEqual("awesome", t.AccessToken);
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using NUnit.Framework;
using Untappd.Net.Client;
namespace Untappd.Net.UnitTests.Client
{
[TestFixture]
public class TestUnAuthenticatedUntappdCredentials
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectClientIdException()
{
var t = new UnAuthenticatedUntappdCredentials(string.Empty, "t");
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectClientSecretException()
{
var t = new UnAuthenticatedUntappdCredentials("t", string.Empty);
}
}
}

View File

@@ -0,0 +1,28 @@
using NUnit.Framework;
using Untappd.Net.Exception;
namespace Untappd.Net.UnitTests.Exception
{
[TestFixture]
public class TestBaseUntappdException
{
[ExpectedException(typeof (BaseUntappdException))]
[Test]
public void TestStandardException()
{
throw new BaseUntappdException();
}
[ExpectedException(typeof(BaseUntappdException), ExpectedMessage = "messageHere")]
[Test]
public void TestStandardExceptionWithMessage()
{
throw new BaseUntappdException("messageHere");
}
[ExpectedException(typeof(BaseUntappdException), ExpectedMessage = "messageHere")]
[Test]
public void TestStandardExceptionWithInner()
{
throw new BaseUntappdException("messageHere", new System.Exception("innerException!"));
}
}
}

View File

@@ -0,0 +1,17 @@
using NUnit.Framework;
using Untappd.Net.Exception;
namespace Untappd.Net.UnitTests.Exception
{
[TestFixture]
public class TestEndpointConfigurationException
{
[Test]
[ExpectedException(typeof(EndpointConfigurationException), ExpectedMessage = "Invalid endpoint configured")]
public void TestThrownExeption()
{
throw new EndpointConfigurationException();
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

View File

@@ -0,0 +1,49 @@
using System.Collections.Generic;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using RestSharp;
using Untappd.Net.Client;
using Untappd.Net.Request;
using Untappd.Net.Responses.BeerInfo;
namespace Untappd.Net.UnitTests.Request
{
[TestFixture]
public class TestRepository
{
[Test]
public void ConfirmRequestWorks()
{
var mockCreds = new Mock<IUntappdCredentials>();
mockCreds.Setup(a => a.ClientId).Returns("id");
mockCreds.Setup(a => a.ClientSecret).Returns("secret");
var bodyParam = new Dictionary<string, string> {{"key", "value"}};
var client = new Mock<IRestClient>();
var request = new Mock<IRestRequest>();
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
var response = new Mock<IRestResponse>();
var obj = JsonConvert.SerializeObject(new BeerInfo());
response.Setup(a => a.Content).Returns(obj);
client.Setup(a => a.Execute(It.IsAny<IRestRequest>())).Callback(() =>
{
}).Returns(response.Object);
var repository = new Repository(client.Object, request.Object);
repository.Get<BeerInfo>(mockCreds.Object, "awesome", bodyParam);
request.Verify(a => a.AddParameter("client_id", mockCreds.Object.ClientId));
request.Verify(a => a.AddParameter("client_secret", mockCreds.Object.ClientSecret));
request.Verify(a => a.AddParameter("key", "value"));
}
[Test]
public void ConfirmBasicConstructorWorks()
{
var constructorTest = new Repository();
Assert.IsTrue(constructorTest.Client != null);
Assert.IsTrue(constructorTest.Request != null);
}
}
}

View File

@@ -30,6 +30,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq">
<HintPath>..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.core">
<HintPath>..\..\packages\NUnitTestAdapter.1.2\lib\nunit.core.dll</HintPath>
<Private>False</Private>
@@ -49,6 +56,10 @@
<HintPath>..\..\packages\NUnitTestAdapter.1.2\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RestSharp, Version=105.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -59,7 +70,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Client\TestAuthenticatedUntappdCredentials.cs" />
<Compile Include="Client\TestUnAuthenticatedUntappdCredentials.cs" />
<Compile Include="Exception\TestBaseUntappdException.cs" />
<Compile Include="Exception\TestEndpointConfigurationException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Request\TestRepository.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Moq" version="4.2.1502.0911" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnitTestAdapter" version="1.2" targetFramework="net45" />
<package id="RestSharp" version="105.0.1" targetFramework="net45" />
</packages>

View File

@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Client.Net;
namespace Untappd.Net.Client
{
public class AuthenticatedUntappdCredentials : UnAuthenticatedUntappdCredentials
public sealed class AuthenticatedUntappdCredentials : UnAuthenticatedUntappdCredentials
{
internal string AccessToken { get; private set; }
/// <summary>
@@ -19,7 +14,10 @@ namespace Untappd.Net.Client
public AuthenticatedUntappdCredentials(string accessToken, string clientId, string clientSecret)
:base(clientId, clientSecret)
{
if (string.IsNullOrWhiteSpace(accessToken)) throw new ArgumentNullException("accessToken");
if (string.IsNullOrWhiteSpace(accessToken))
{
throw new ArgumentNullException("accessToken");
}
AccessToken = string.Copy(accessToken);
}
}

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net.Client
namespace Untappd.Net.Client
{
public interface IAuthenticatedUntappdCredentials : IUntappdCredentials
{

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net.Client
namespace Untappd.Net.Client
{
public interface IUntappdCredentials
{

View File

@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Net.Client;
namespace Untappd.Client.Net
namespace Untappd.Net.Client
{
public class UnAuthenticatedUntappdCredentials : IUntappdCredentials
{

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net
namespace Untappd.Net
{
public struct Constants
{

View File

@@ -0,0 +1,20 @@
using System;
namespace Untappd.Net.Exception
{
[Serializable]
public class BaseUntappdException : System.Exception
{
public BaseUntappdException()
{
}
public BaseUntappdException(string message) : base(message)
{
}
public BaseUntappdException(string message, System.Exception inner) : base(message, inner)
{
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Untappd.Net.Exception
{
public class EndpointConfigurationException : BaseUntappdException
{
/// <summary>
/// Called when a class has an empty endpoint
/// </summary>
/// <param name="type"></param>
public EndpointConfigurationException()
:base("Invalid endpoint configured")
{
}
}
}

View File

@@ -32,5 +32,6 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.*")]
[assembly: AssemblyFileVersion("0.2.*")]
[assembly: InternalsVisibleTo("Untappd.Net.UnitTests")]

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Net.Exception;
namespace Untappd.Net.Request
{
@@ -10,12 +6,16 @@ namespace Untappd.Net.Request
{
protected abstract string _EndPoint { get; }
/// <summary>
/// Pass in the parameter into the request...ie username, brewery, etc.
/// Pass in the url parameter into the request...ie username, brewery, etc.
/// </summary>
/// <param name="parameter"></param>
/// <param name="parameter">this can be null if request has no url params</param>
/// <returns></returns>
internal string EndPoint(string parameter)
{
if (string.IsNullOrWhiteSpace(_EndPoint))
{
throw new EndpointConfigurationException();
}
return string.Format(_EndPoint, parameter);
}
}

View File

@@ -1,17 +1,27 @@
using Newtonsoft.Json;
using RestSharp;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Client.Net;
using Newtonsoft.Json;
using RestSharp;
using Untappd.Net.Client;
namespace Untappd.Net.Request
{
public class Repository
{
internal IRestClient Client;
internal IRestRequest Request;
public Repository()
{
Client = new RestClient(Constants.BaseRequestString);
Request = new RestRequest();
}
internal Repository(IRestClient client, IRestRequest request)
{
Client = client;
Request = request;
}
/// <summary>
/// Get the things!
/// </summary>
@@ -23,18 +33,17 @@ namespace Untappd.Net.Request
public TResult Get<TResult> (IUntappdCredentials credentials, string urlParameter, IDictionary<string, string> bodyParameters = null)
where TResult : UnAuthenticatedRequest,new()
{
// throw new NotImplementedException();
var result = new TResult();
var client = new RestClient(Constants.BaseRequestString);
var request = new RestRequest(result.EndPoint(urlParameter), Method.GET);
request.AddParameter("client_id", credentials.ClientId);
request.AddParameter("client_secret", credentials.ClientSecret);
Request.Resource = result.EndPoint(urlParameter);
Request.Method = Method.GET;
Request.AddParameter("client_id", credentials.ClientId);
Request.AddParameter("client_secret", credentials.ClientSecret);
if (bodyParameters != null)
foreach (var x in bodyParameters)
{
request.AddParameter(x.Key, x.Value);
Request.AddParameter(x.Key, x.Value);
}
var resp = client.Execute(request);
var resp = Client.Execute(Request);
var jsonresult = JsonConvert.DeserializeObject<TResult>(resp.Content);
return jsonresult;

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net.Request
namespace Untappd.Net.Request
{
public abstract class UnAuthenticatedRequest : AuthenticatedRequest
{

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BeerInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BeerSearch
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BreweryInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BrewerySearch
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.Feeds
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserBadges
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserDistinctBeer
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserFriends
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserWishlist
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.VenueInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -51,6 +51,8 @@
<Compile Include="Client\IUntappdCredentials.cs" />
<Compile Include="Client\UnAuthenticatedUntappdCredentials.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Exception\BaseUntappdException.cs" />
<Compile Include="Exception\EndpointConfigurationException.cs" />
<Compile Include="Request\AuthenticatedRequest.cs" />
<Compile Include="Request\UnAuthenticatedRequest.cs" />
<Compile Include="Responses\BeerInfo.cs" />