API - knihovna (jen pro Fakturačku Premium)

<?php

class Fakturacka {

    private 
$email;
    private 
$password;

    public function 
__construct($email$password) {
        
$this->email $email;
        
$this->password $password;
    }

    public function 
getInvoices() {
        return 
$this->run('invoices');
    }
    
    
// direction: customer, supplier
    
public function getInvoice($direction$id) {
        return 
$this->run('get-invoice/' $direction '/' $id);
    }

    public function 
createInvoice($data) {
        return 
$this->run('create-invoice'$data);
    }

    private function 
run($path$data null) {
        
$ch curl_init('https://fakturacka.cz/API/' $path);
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($chCURLOPT_FAILONERRORfalse);
        
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
curl_setopt($chCURLOPT_POSTtrue);
        
curl_setopt($chCURLOPT_POSTFIELDS, [
            
'username' => $this->email,
            
'password' => $this->password,
            
'data' => json_encode($data)
        ]);
        
$response curl_exec($ch);
        
$info curl_getinfo($ch);
        
curl_close($ch);
        if (
$info['http_code'] >= 400) {
            throw new 
Exception($response);
        }
        return 
json_decode($response);
    }

}