DigitalOcean API Client
When I went to Davis, WV for Thanksgiving with my family, I started working on a DigitalOcean API Client. I have since started over twice in an attempt to make it better. Getting it to work is not a problem, but making it easy to use can be a challenge. I am using interfaces, abstract classes, traits, and concrete classes to help organize the code and make each part replaceable. Any request made will need a request object, which is similar to a DTO (Data Transfer Object). If you want to create a droplet, then you will need to create a CreateDropletRequest object; the CreateDropletRequest construct requires the same parameters that DigitalOcean's API requires. You will also need a Droplets object that has methods for all the actions you can execute on that API endpoint. I'm currently using Guzzle for the HTTP client, but you can use another if you like. Below is an example of creating a droplet with the minimal options.
<?php $response = (new Droplets)->create( new CreateDroplet( 'vps.levi.lol', // name of the droplet 'nyc1', // region '512mb', // size 'ubuntu-14-04-x64' // image ) );
I would enjoy some feedback on my approach to making this library. Looking at other PHP API clients, some do something similar to this, but some don't. Creating the request this way makes sense to me, but I'm writing this for other people to use. Some of the other PHP API clients leave the request portion up to the developer to get right; this to me seems a bit ill-natured.
I'm currently working on the latest version of my library in a branch of the repo; so I don't accidentally mess it up again. The
Factory class is one of my favorite parts of this library. It tackles lazy loading of object instantiation in a way I haven't done before. I had the idea and started writing it without a clear view of what I was doing. By keeping to a consistent naming convention; it can predict class names based on the type hinted method parameter.
DigitalOcean recently updated their API, but not their changelog. How are we supposed to know about new features? Yes, they gave us the ability to enable `Monitoring` on our droplets, and it works via the API, but we need to know those things. I am hoping they create an endpoint to get the data from the monitor; as that could help with load balancing and deciding on the need to scale the app up or down.