GithubHelp home page GithubHelp logo

webinarium / linode-api3 Goto Github PK

View Code? Open in Web Editor NEW
30.0 6.0 2.0 200 KB

Linode API v3 Client Library for PHP.

Home Page: https://www.linode.com/api

License: MIT License

PHP 100.00%
php api linode

linode-api3's Introduction

PHP Latest Stable Version Build Status Code Coverage Scrutinizer Code Quality

Linode API v3 Client Library for PHP

This library implements full spec of Linode API v3 (in accordance with https://www.linode.com/api/utility/api.spec), including functions which are not described at the Linode's site yet (the documentation seems to be slightly outdated at the moment).

The library wasn't actually implemented, but autogenerated from the spec. This approach provides several advantages as:

  • we can be sure that nothing from the spec is missed,
  • no implementation errors which could be caused by human factor,
  • in case of the spec extension it's fast and easy to update the library's code.

Also please note that "test.echo" is skipped from the implementation.

Warning

The library addresses Linode's legacy API. For most recent API please refer to this library.

Requirements

PHP needs to be a minimum version of PHP 5.6.

Installation

The recommended way to install is via Composer:

composer require "webinarium/linode-api3"

Usage Example

Below is a complete example of how to create a new Linode host using the library:

use Linode\LinodeApi;
use Linode\LinodeException;
use Linode\PaymentTerm;

// Your API key from the Linode profile.
$key = '...';

// Hardcode some IDs to make the example shorter.
// Normally you might want to use "Linode\AvailApi" class functions.
$datacenter = 3;    // Fremont datacenter
$plan       = 1;    // we will use the cheapest plan

// Create new linode.
try {
    $api = new LinodeApi($key);
    $res = $api->create($datacenter, $plan, PaymentTerm::ONE_MONTH);

    printf("Linode #%d has been created.\n", $res['LinodeID']);
}
catch (LinodeException $e) {
    printf("Error #%d: %s.\n", $e->getCode(), $e->getMessage());
}

Batching Requests

The Linode API also supports a batched mode, whereby you supply multiple request sets and receive back an array of responses. Example batch request using the library:

use Linode\Batch;
use Linode\LinodeApi;
use Linode\PaymentTerm;

// Your API key from the Linode profile.
$key = '...';

// Hardcode some IDs to make the example shorter.
// Normally you might want to use "Linode\AvailApi" class functions.
$datacenters = [2, 3, 4, 6];    // all four US datacenters
$plan        = 1;               // we will use the cheapest plan

// Create a batch.
$batch = new Batch($key);

// Create new linode on each of US datacenters.
$api = new LinodeApi($batch);

foreach ($datacenters as $datacenter) {
    $api->create($datacenter, $plan, PaymentTerm::ONE_MONTH);
}

// Execute batch.
$results = $batch->execute();

foreach ($results as $res) {
    printf("Linode #%d has been created.\n", $res['DATA']['LinodeID']);
}

Tests

Almost all tests are mocked so you don't have to use a real API key and no real linodes are affected. The only tests which make a complete API call are TestTest (for "test.echo") and ApiTest (for "api.spec"):

./bin/phpunit --coverage-text

Library regeneration

If you would like to regenerate the library code, you can do it with two simple steps:

php ./generator/generator
php ./bin/php-cs-fixer fix

linode-api3's People

Contributors

webinarium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

ntshop 0x85dotdev

linode-api3's Issues

Linode API SSL upgrade - library no longer works out of the box

This afternoon, the API client stopped working for me. Apparently, Linode has upgraded its TLS infrastructure and no longer supports TLSv1.0.

I was able to fix the issue by setting the curl option CURLOPT_SSLVERSION to 6. I did this in both Batch.php and BaseLinodeApi.php. However, I only patched my local copy of the library and haven't run extensive tests so I'm unsure about any sort of deeper ramifications.

List all linodes and associated public ip address

We are looking at using your library for importing a list of all servers into https://commando.io from Linode.

We need to list all Linodes in an account, and then list each public ip address associated with each server. Can you provide an example of this? Can we use batch to prevent making an API request for each server?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.