softcomtecnologia/softcom-api-php

1.0.7 2019-05-15 13:08 UTC

This package is not auto-updated.

Last update: 2024-12-22 05:55:26 UTC


README

Pacote destinado a prover uma abstração para integração de recursos da API Softcom

Instalação

Este pacote é facilmente instalado via Composer. Basta adicionar o trecho de código abaixo ao arquivo composer.json que encontra-se em seu projeto:

    {
        "require": {
            "softcomtecnologia/softcom-api-php": "*"
        }
    }

Exemplo de Uso

Obtendo Token

    $options = [
        'domain'        => 'http://<url-softcom>/softauth',
        'clientId'      => '<your-client-id>',
        'clientSecret'  => '<your-client-secret>',
        'deviceId'      => '<your-device-id>',
        'deviceName'    => '<name-for-your-device>',
    ];
    
    $provider = new SoftcomProvider($options);
    $token = $provider->getAccessToken(new SoftcomCredentials());
    
    echo $token;//your token ex.: 301b7689eb926495a02fe4ba4932d7bfa80aa202

Realizando uma Request

GET

    $options = [...];
    $provider = new SoftcomProvider($options);
    $token = 'your-token-string';//or SoftcomAccessToken object
    $url = '/api/example';//without domain
    $params = [
        'key' => 'value',
        //...
    ];
    
    $resource = $provider->get($token, $url, $params);
    
    echo json_decode($resource->getContents(), 1);
    /*
     * [
     *      "code" => 1,
     *      "message" => "OK",
     *      "human" => "Sucesso",
     *      "data" => [
     *          "username" => "my username",
     *          "name" => "softcom",
     *      ],
     *      "meta" => []
     * ]
     */

POST

    $options = [...];
    $provider = new SoftcomProvider($options);
    $token = 'your-token-string';//or SoftcomAccessToken object
    $url = '/api/example';//without domain
    $params = [
        'key' => 'value',
        //...
    ];
    
    $resource = $provider->post($token, $url, $params);
    
    echo json_decode($resource->getContents(), 1);
    /*
     * [
     *      "code" => 1,
     *      "message" => "OK",
     *      "human" => "Sucesso",
     *      "data" => [
     *          "username" => "my username",
     *          "name" => "softcom",
     *      ],
     *      "meta" => []
     * ]
     */