php-invoiceocean, a PHP client to interact with the InvoiceOcean.com API

It’s been a while since I created a public PHP library to interact with another API but here we go.

php-invoiceocean is a PHP client to communicatie with the InvoiceOcean.com API.

What is InvoicingOcean?

“The easiest way to online invoicing”. Over 70 000 companies are using the InvoiceOcean software. The application’s simplicity and intuitive interface is aimed at quick and efficient invoice issuing. Because of the SaaS environment, your data is securely stored in the Cloud and available to access from anywhere in the world. Whether you are a small or medium business owner or an individual entrepreneur, InvoiceOcean will make your work easier.

A few facts

– it’s RESTful
– works with Json exclusively (although they have XML api’s, I like Json more)
– it’s pretty smart in a way that you only have to define the method names, no parameter or http method checking
– works with composer (obviously)

Clone this repo @ https://github.com/kryap/php-invoiceocean

How to use?

composer require kryap/php-invoiceocean
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing kryap/php-invoiceocean (dev-master a8ccf4d)
Cloning a8ccf4dfd3b8daa611087822f27da2a773c073ce
 
Writing lock file
Generating autoload files
Generating optimized class loader

Here’s how you could use it:

<?php
 
$io = new InvoiceOceanClient('username', 'api_token_goes_here');
$clients = $io->getClients();
 
var_dump($clients);
 
?>

Need more documentation about the InvoiceOcean API?

Visit these links:

Behind the scenes @ Coolblue HQ

What is Coolblue?

Last week I was invited to go visit Coolblue behind the scenes in Rotterdam, NL. Coolblue has always been one of my favorite online dutch/belgian webshops because of their great customer service, their clear but simple websites, and most important, their great range of products at very affordable prices.

They roughly have about 50k unique products in 150-200 different webshops (they launch 2 new webshops per week on average), which they all have in stock at all time in one of their huge warehouses. Their biggest warehouse is more than 40.000 square meters which is about 10-20 FIFA football fields! How big is that! Ordering before 23.59 means it’s delivered at your doorstep for free the next day, or the same day when paying additional shipping costs. Also on sunday!

Why would they organise behind the scenes events?

The main idea behind this ‘Behind the scenes’ is that they are looking for talent programmers. They’re looking for roughly 100 new developers. They have about 40 right now so it seems they have big plans. Are they going international? Who knows! But their CEO didn’t really deny it. Their global employee basis is about 750 people.

Since I’m a freelancer I won’t be able to work for them so why did I go to this event? Well.. because their main dev talk was about scalability. I find this a very interesting and challenging topic so getting insights from one of the biggest webshops in the Benelux was a great opportunity for me to learn.

So what did I learn at Coolblue?

  1. use microservices / hypermedia api’s to flatten out your infrastructure. This allows you to easily isolate bugs and/or maintain those API’s without having to retest stable services on every deploy.
  2. every microservice uses an isolated datastore. CouchDB for customer data, PostgreSQL for order+payment information, ElasticSearch for the product catalog.
  3. RabbitMQ as a central state change notification mechanism. This is the glue between your microservices.
  4. use git pull requests to review & validate your team members changes
  5. CentOS RPM packages to distribute everything
  6. Puppet labs or Chef to install & maintain your (virtual) servers
  7. Statsd + Graphite for advanced reporting
  8. Nagios for alerting
  9. Create a “Chaos Monkey”. It’s single purpose is to once in a while kill your live environment. Your devs should then come with solutions to auto-fix these downtimes. This is how Netflix stayed online during the massive AWS outage a while ago: http://techblog.netflix.com/2012/07/chaos-monkey-released-into-wild.html

Have a look at the slides from their software architect.

Why should you attend one of these meetings?

  1. If you want a developer job @ Coolblue obviously.
  2. If you want to learn more about scalability.
  3. If you want to network with hundreds of other devs.

Inform yourself on this page: http://www.coolblue.nl/behindthescenes

Here’s a nice dutch article about the same event: http://www.dailybits.be/item/coolblue-behind-scenes/

Deploying PHP projects with Jenkins on OS X

jenkins

Continuous deployment, automated unit testing, code analysis & reports, git repo’s, Laravel 4 using Composer. This must be a dream project right? Well, yes, if you have it working correctly. It took me a while to get everything working together but now it works like a charm. I chose to deploy via my macbook, but some people might find it handier to install this setup on a public webserver so they can bind their commits to automated deployments, use it as a team, ….
Anyway, this tutorial will be about deployment for php projects (Laravel 4 in particular) on OS X. I’m assuming you already have a webserver up & running (I’m using MAMP).

1) Install Jenkins

Go to http://jenkins-ci.org/ and install Jenkins for Mac OS X, make sure to use seperate new user. Here’s a great tutorial about this: http://colonelpanic.net/2011/06/jenkins-on-mac-os-x-git-w-ssh-public-key/

Addons:
– Jenkins in your dock: https://github.com/stisti/jenkins-app
– JenkinsMobi (iOS app): http://hudson-mobi.com/

2) Configure Jenkins

I strongly recommend you to follow this tutorial http://jenkins-php.org/ as it has almost everything documented for deploying php apps through Jenkins. My setup is actually based on this documentation.

Download the Jenkins plugins listed on the jenkins-php.org website. I’m using these:
– Jenkins Mailer Plugin
– External Monitor Job Type Plugin
– Ant Plugin
– Static Analysis Utitlities
– Checkstyle Plug-in
– Credentials Plugin
– Jenkins CVS Plug-in
– Duplicate Code Scanner Plug-in
– Jenkins Email Extension Plugin
– FTP publisher plugin
– Jenkins GIT client plugin
– Jenkins GIT plugin
– GitHub API Plugin
– Github plugin
– HTML Publisher plugin
– Jenkins JDepend Plugin
– Plot plugin
– PMD Plug-in
– Publish Over FTP
– xUnit Plugin

3) Configure a new project

Install the jenkins-php’s job template tutorial. When you want to create a new project, simply copy the job template project and modify it as you want.

4) Connect your git repo

Connect your git repo to jenkins. Make sure to use the git protocol (git@github.com:username/repo.git) if you setup key pairs. If you’re using the http:// github url it will keep asking for credentials even though your key pairs are correctly installed.

5) Install Composer

Use this tutorial to install Composer: http://getcomposer.org/doc/01-basic-usage.md#installation

And put it in your bin directory so every user can use this great piece of software:

cp composer.phar /usr/local/bin/composer

If you’re using composer you will at one point notice it will clone your depency repo’s using git everytime you build your application. And this gave me some Jenkins problems.. Even though the normal ‘composer update’ worked like a charm under my jenkins user, Jenkins itself was giving problems.

[exec] [RuntimeException]
[exec] Failed to clone http://github.com/nicolas-grekas/Patchwork-UTF8.git, git was not found, check that it is installed and in your PATH env.
[exec]
[exec] sh: git: command not found

more @ http://jenkins.361315.n4.nabble.com/git-not-found-with-jenkins-composer-php-td4660806.html

To fix this, go to http://localhost:8080/configure -> Global configuration -> Environment variables
And add this:
name = PATH
value = /usr/local/git/bin:$PATH

As you can see in the following picture, composer is now fully working in our build process:
1JMuzxRzPabYasaXePdvw9d6GXHitPljLOciovw

6) Install some additional PHP packages

Now of course we want code statistics, automated unit testing, auto generated API documentation, coverage reports, etc so we need to install some extra tools:

pear (http://pear.php.net/)
Follow this quick guide to install pear: https://gist.github.com/macek/1301527

phpdox (https://github.com/theseer/phpdox)

sudo pear config-set auto_discover 1
sudo pear install pear.netpirates.net/phpDox-0.4.0

phpunit (http://www.phpunit.de/manual/3.0/en/installation.html)

sudo pear channel-discover pear.phpunit.de
sudo pear install phpunit/PHPUnit

phploc (https://github.com/sebastianbergmann/phploc)

sudo pear config-set auto_discover 1
sudo pear install pear.phpunit.de/phploc

pdepend (http://pdepend.org/documentation/getting-started.html)

sudo pear channel-discover pear.pdepend.org
sudo pear install pdepend/PHP_Depend-beta

phpcb

sudo pear channel-discover pear.phpqatools.org
sudo pear install --alldeps phpqatools/PHP_CodeBrowser

7) Create your build file

Next we create our build.xml file and we make sure it’s executed correctly by Jenkins (check Project -> Building steps). Put this file in your /jobs/PROJECT directory.

Here’s mine: http://paste.laravel.com/mLw

Note: you can test the build file manually by executing this command. So no need to build via Jenkins and download 24 composer repo’s before it starts executing the ant build file.

ant -f build.xml -v

You will also need some additional XML config files:

PROJECT/phpcs.xml -> http://paste.laravel.com/mLB

PROJECT/phpdox.xml -> http://paste.laravel.com/mLA

PROJECT/phpmd.xml -> http://paste.laravel.com/mLz

You will also have to alter your Laravel’s phpunit.xml file: http://paste.laravel.com/mLC (the one in your root folder)

8) Build your application

Now try to build your application through Jenkins. Enjoy!

Here’s how it should look like: http://paste.laravel.com/mMn

And some fancy screenshots:
1FxhZRcTJZS4fgVepTvJLoAUx_VwyqjI0xBQTBw

1BWoJILiDN0QjSfOlgQmSwLRB3VsH0FOt58ym3g

These are just some Jenkins screenshots.. our build file is also generating documentation, code coverage, getc which you can find in PROJECT/workspace/build/ and PROJECT/build

Interesting links:
http://jenkins-php.org/
http://erichogue.ca/2011/05/php/continuous-integration-in-php/