Github API Access Tokens via Curl

I’m working on some demos for a tutorial I’m giving next month and since I’d like to show off Github’s API, I needed an access token for it. They have the usual web flow but I’m cutting as many corners as I can to keep the demos nice and quick, so I looked into the support Github has for generating an API key programmatically. Continue reading

API Documentation with IODocs

I write a lot of APIs, and I also preach that your API isn’t finished until it has excellent documentation. Which is great, but that means I therefore have to lead by example and document my APIs :) Enter iodocs from the talented folk at Mashery.

Iodocs is a node.js application (which is fun for a PHP developer. Most developers write a bit of JS, but this one hasn’t). You describe your API and all its methods in JSON, and then iodocs presents an interface for you to enter API keys, add parameters to each request and press the “try it!” button. This makes your API call and shows you the results on screen, which seems like a great way to demonstrate what all the various parameters do!

iodocs screenshot
Continue reading

Do Open Source with Git and Github

This article originally appeared in the May 2012 php|architect magazine.

Often I find absolutely competent programmers, who aren’t involved in open source, either because they don’t know how to approach a project, or because they just aren’t sure how the process even works. In this article we’ll look at one example, the conference feedback site joind.in, and how you can use GitHub to start contributing code to this project. Since so many projects are hosted on github, this will help you get started with other projects, too.

The tl;dr Version for the Impatient

  1. Fork the main repo so you have your own github repo for the project
  2. Clone your repo onto your development machine
  3. Create a branch
  4. Make changes, commit them
  5. Push your new branch to your github repository
  6. Open a pull request

This article goes through this process in more detail, so you will be able to work with git and github projects as you please.
Continue reading

PHP for Drupalistas

There’s an exciting new venture coming up soon – something I’ve been working on with Emma Jane for a while (yes, Lorna Jane and Emma Jane, we know) – it’s called phpfordevelopers.com. From the site:

This spring Emma Jane and Lorna Jane were chatting about PHP and Drupal and workshops and came to the conclusion that Drupal developers were not necessarily equipped for Drupal 8. With all of the Drupalisms in the Drupal code, it can sometimes be difficult to implement code that is both a Drupal best practice and a PHP best practice. While there are many workshops on how to teach PHP developers how to Drupal, there were no workshops teaching Drupal developers how to PHP. Until now!

My theory is that most developers working with CMSes like Drupal think they don’t know much PHP … but of course they actually know quite a lot! The newer versions make more use of OOP and new PHP features, but nothing that’s really rocket science (although the symfony components are very nice). This course is a chance for us to give a more solid grounding to those skills that developers just pick up along the way, and give some time to master those skills in a safe environment. Continue reading

Posting Raw Data with Curl

This week I’ve been working on a feature which handles an incoming API call from an external source (actually Paypal’s IPN service). Making external calls into my development platform isn’t how I usually work, so instead I captured the body of the request that was being sent, and replayed it against my local script using curl.

I put the data into a separate file, data.txt and then used curl to direct that data at my local URL:

curl -X POST http://localhost/app/test.php --data @data.txt

I find this approach useful for testing, but since I had to look up how to do it, I thought I’d put it here for reference!

The Quest for a Payment Gateway

Although I’ve been “making websites” for a lot of years, I’ve mostly avoided the kind where people actually pay for anything. The result of this is that I built Bitestats (elevator pitch: sign up and get a printable summary report of your web stats every month by email) but then got busy and never built the bit where people can actually pay to use it.

I recently carved out some time to correct this situation, and fell into an absolute pit of confusion when I tried to figure out what my options even were. My requirements are that my customers are global, I am UK-based, people will set up a regular subscription, and I don’t have (and I think I don’t want) a merchant account at this point. I’m not PCI compliant and have no intention ever to attempt that. This post is an attempt to round up some things I found out along the way. Continue reading

Skills Allied to PHP

This post is mostly about a tutorial I will be delivering at PHPNW on October 5th in Manchester, UK, and why I think a tutorial that contains no PHP belongs at a PHP conference

phpnw12 logoIn October, I’ll be delivering a tutorial at the mighty PHPNW Conference which contains very little PHP. Why? Because I think, as developers, it’s our other professional skills that suffer. As a consultant, I work with lots of different teams, and it is very rare for code to be the problem (and the one time it was, it wasn’t the only problem!).

In web development, our biggest challenges are not writing code, we can do that. But getting the code safely from one place to another, with many people’s work preserved, having our platform(s) correctly configured and understanding how to use them, making use of the tools in the ecosystem which will help us improve the quality of our code; these are the big challenges we face, and that’s why I proposed this workshop and why I think all these topics are important. Continue reading

Validating Email Addresses in PHP

A very quick snippet today because I’ve told two people to use this approach in the last few days and both of them told me they didn’t know about it. How to check if an email address is valid in PHP: use one of the Filter functions, like this:


$email1 = "nonsense.something@dottiness";  // not a valid email
$email2 = "[email protected]";  // valid email

$clean_email1 = filter_var($email1, FILTER_VALIDATE_EMAIL); // $clean_email1 = false
$clean_email2 = filter_var($email2, FILTER_VALIDATE_EMAIL); // $clean_email2 = [email protected]

The Filter extension was new in PHP 5.2, but is one of the unsung heroes of the language. It’s rare for me to ever describe one approach as the “right” way to do something – but for validating data, Filter really is excellent, offering both validating and sanitising filters and generally making it super-easy to clean up incoming variables. Many of the frameworks offer equivalents, and I’m sure many of those are wrapping this too.

Two Years of Trading

Two years ago I quite literally gave up the day job. I had no clients, no experience of being anything other than a salaried employee, but I did have an urgent need for change! Two years on I’ve just done the end-of-the-year reporting and I’m struck by how far I’ve come and how much the numbers surprise me (there are no actual numbers in this post, it doesn’t feel appropriate somehow – but there are graphs!). Continue reading

Installing PEAR Packages Offline

As with most tools that work really well, I know very little about PEAR. I mean, I use it all the time, and I love it for getting all the extensions installed that I need for the work I do. But I’ve never made a PEAR package, or channel, and I’ve been happy to leave all those things in the hands of the smart people who have created what we have today.

However I’m now in a situation where I might need to install PEAR packages with a connection that may or may not be working, and I’m not sure exactly which packages I might need, so I wanted to know whether I could use PEAR as my packaging tool even when I wasn’t able to reach the usual channels. And guess what? I can! Continue reading