Beer Drinkin, Libraries

Updated BreweryDB .NET client

687474703a2f2f7777772e6272657765727964622e636f6d2f696d672f62616467652e706e67

header.png


Over the weekend I decided to look at a project which hasn’t recieved much love since I orginally wrote it earlier in the year. That project is PCL for interacting with the awesome beer database that is BreweryDB.

My orginal implementation was very simplistic in its design, only exposed a handful of the endpoint, lacked any error checking and also had a few too little unit tests. With BeerDrinkin’s development coming along nicey, I thought it time to take a look at some of its dependencies and see how I could improve them. First up was BreweryDB and so I set about improving the PCL to hopefully make it useful for other .NET developers.

Supported enpoints

This new version of BreweryDB includes many more supported endpoints. Its now possible to query almost all of BreweryDB using .NET.

  • Adjuncts
  • Beers
  • Breweries
  • Categories
  • Events
  • Features
  • Fermentables
  • FluidSizes
  • Guilds
  • SocialSites
  • Yeasts

 

Getting Started

Beers

  • GET/beers
  • GET/beer/beerId
  • GET/search/

Get all

This returns a list of all beers but will be paginated with 50 beers per page.

//Will return the first page
var response = await client.Beers.GetAll();

//Will return the fourth page
var response = await client.Beers.GetAll(4);

Get by id

This returns a single beer

var response = awaitclient.Beers.Get("cBLTUw");

Using request parameters

This returns a  list of beers

var parameters = new NameValueCollection {{BeerRequestParameters.Name, "duvel single"}};
var response = await client.Beers.Get(parameters);

Search by name

This returns a  list of beers

var response = await client.Beers.Search("duvel");

Breweries

  • GET/breweries
  • GET/brewery/breweryId
  • GET/search/

Get all

This returns a list of all breweries but will be paginated with 50 breweries per page.

//Will return the first page
var response = await client.Breweries.GetAll();

//Will return the forth page
var response = await client.Breweries.GetAll(4);

Get by Id

This returns a single Brewery

var response = await client.Breweries.Get("YXDiJk");

Search by name

This returns a  list of breweries

var response = await client.Breweries.Search("duvel");

Naturally its open source

As always, I’ve made this avaiaible on GitHub and Nuget for you to use in your own apps.

iOS, Libraries

iOS Awesomizer

A couple of weeks ago I started writing a library to speed up the development of iOS app. My aim was to make creating beautiful iOS apps even easier and share more code accross my iOS projects.

The main requirment of iOS development that I found consitant across all my apps is the need for animations. Since the orginal iPhone, iOS has had beautiful animations that create compelling user experiances which is why I feel its essential to have animations in my apps. Thankfully, creating animations for iOS is pretty simple but it still remains repetitive.

Its for this reason that I created iOS Awesomizer. Awesomizer allows me to animate any class that inherhits from UIView (thats most of the UI controls you’ll be using) with an extension method.


Whats supported?

Rotation

rotation

 

Flip

flip

 

 

 

 

Horizontal and verticle shake

shake

 

 

 

Pulse

pulse.gif

 

 

 

 

 


 

How to use

Because the animations are UIView extensions, its incredibly easy to add animations to existing controls. Let say I wanted to add a shake animation to a UIImageView, I’d simply do the following:


using Awesomizer;

//More code here which we don't care about
myImageView.ShakeHorizontally();

Naturally, its open source

You can find the code for iOS Awesomizer on GitHub. I’m happy to accept any pull requests!

Libraries

Find your users gender without asking

The app I’m working on in my spare time (BeerDrinkin) requires a modest amount of user data to in the future provide the best possible suggestions for new beers the user might like to try. Part of building a great model of my users is knowing thier gender.

When a user authenticates within BeerDrinkin using Facebook, I can simply parse the returned information and add the users gender to my database. Unfortunately, not all social authentication providers were born equal. With the recent addition of Google Auth, which I added to allow my father (who isn’t even sure what Facebook is) to use my app, I was unable to get the users gender.

Its for this reason that I’ve created a library that allows me to query Genderize. Genderize is a restful service which allows me to determine the gender of a user based on only a first name. It offers a free tier which includes the ability to query 1000 names a day which is more than enough for my requirements. If I find myself hitting the limit I’ll firstly buy a bottle of champagne to celebrate high user adoption and to drink away the thoughts of my Azure bill. On a serious note, Genderize provide the option to upgrade the account plan for a nominal fee to 100,000 users a month.

Given that BeerDrinkin does some sneaky UX to make a Facebook auth more likely (I delay showing the Google sign-in button for a few seconds so the user intially is confronted with only 1 option. Its very subtle but seems to help push Facebook as the prefered option), the free teir should be perfect for me.

Creating a PCL to interact with Genderize

To get started I headed over to the Genderize’s documentation to see what response I should expect back when querying the service. It’s actually increbily easy to use this service so much so that the entire PCL consists of no more than 100 lines of code.

Sample JSON response

{
    “name”:“peter”,
    “gender”:“male”,
    “probability”:“0.99”,
    “count”:796
}

Corresponding C# model


public class Response
{
    private string gender { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonConverter(typeof(StringEnumConverter))]
    public Gender Gender { get; set; }

    [JsonProperty("probability")]
    public string Probability { get; set; }

    [JsonProperty("count")]
    public int Count { get; set; }
}

public enum Gender
{
    Male,
    Female,
    None,
}

One thing to note is that I’m using Json.NET’s JsonConverter to deal with converting from a string gender to an enum. This is just one of the many featuress of Json.NET that make it a pleasure to use.

Genderize Client Code


public class Client
{
    public Client()
    {
    }

    public async Task GenderizeSingleName(string name)
    {
        if (_client == null)
            _client = new HttpClient();

        Response model;

        var url = string.Format("http://api.genderize.io/?name={0}", name);
        var response = await _client.GetAsync(url);

        var jsonString = response.Content.ReadAsStringAsync();
        jsonString.Wait();
        model = JsonConvert.DeserializeObject(jsonString.Result);

        return model;
    }

    HttpClient _client;
}

As always, its open source

If you want to use the library, you can go ahead and grab a copy from my GitHub page. Once I get home from Australia I’ll add more features and publish to Nuget.