API – Awesome, Powerful, Interesting

Week 10 at Makers Academy – our last week of structured teaching, before we go into doing our final projects. Alex had some good news for us – as a cohort we were ahead of schedule and so we could spend the week learning more advanced, interesting things to help enhance our Rails projects. Essentially, it was API week.

The first thing we learnt was integrating Stripe into our Instagram-style apps, so that users could buy prints of images that they liked. It is incredibly easy to set this up on your site, hence the popularity that Stripe has gained recently. I simply found the relevant documentation page and followed the instructions. For some reason, the first time I set up my API keys as environment variables Stripe didn’t recognise them, but thankfully I had Hamilton to come along and generate new API keys for me, and for some reason those ones now worked. As you may have gathered if you’ve read previous posts on my blog, Makers Academy is all about Test Driven Development, but an interesting thing with regards to implementing Stripe was that it was impossible to test making payments. This is because the customer interacts with the payment process in Stripes on external window, which pops up over your webpage, and this interaction is inaccessible by our testing units. In what was perfect timing, Andy Young visited Makers that evening to chat about his work as part of the team building Stripe, so we had the opportunity to grill him with questions that we’d built up during the day.

The next day, Alex also showed us how to send an e-mail from our applications. This was far more fiddly than setting up Stripe, and though I took detailed notes from the morning, it was hard to keep track of what I should do, and in what order, given when I wanted an e-mail to be sent. To enable us to focus only on the basics, Darrell suggested that we create a new app from scratch whose sole purpose was to enable the user to fill out a form which then sent an e-mail to the chosen recipient. As well as getting our heads around creating and manipulating Rails mailers, we also had to make use of the Mailgun API such that an e-mail was actually sent when our user clicked the submit button. After a couple of hours we had reached our goal, and were then able to try and incorporate e-mail into more complex applications.

Other interesting things that we touched on this week included incorporating Facebook and Twitter logins to our apps, employing the Google Maps API to enable map features, as well as  looking into building our own APIs. It’s amazing just how much there is out there to help you enhance what you are building. Think of a cool new feature? Chances are pretty high for there already being a useful API or gem for you to install. Exploring all of these different things this week felt as if we were just building up our tool kit for the final two weeks, when we’d be working on our final projects.

While having all these ready-made resources is excellent, developers have to be wary about how they use them, and whether they may in fact just complicate what it is you are trying to do. For example, this week my final project team decided to do a bit of work on the app we were going to build – a new way for companies to attract potential customers with exciting deals. We were so used to the ease with which devise could be installed that we set up our app to use it straight away. We realised that we would need to types of users – a customer user and a business user. Fine – Devise allowed for this ‘polymorphic’ functionality. However, since we’ve got the user types set up, it’s been a real struggle trying to make them work in the way we want to, having to work around the quirks that Devise comes bundled with. In fact, we may end up removing Devise from our application and building the user models from scratch in a way that’ll make them far easier to manipulate.

While it may be easy to follow some documentation or run a ‘gem install’ command in your terminal, really think about why you want the feature you want, and what really is the best way to go about developing it. Building it yourself from scratch may just save you a lot of headache.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s