Giter Club home page Giter Club logo

alegra-php's Introduction

Alegra PHP bindings

You can sign up for a Alegra account at http://www.alegra.com/.

Requirements

PHP 5.6.11 and later.

Composer

You can install the bindings via Composer. Run the following command:

composer require "loduis/alegra-php:@dev"

To use the bindings, use Composer's autoload:

require_once('vendor/autoload.php');

Dependencies

The bindings require the following extension in order to work properly:

  • curl, although you can use your own non-cURL client if you prefer
  • json
  • mbstring (Multibyte String)

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

Getting Started

Any resource containts five main methods (all, get, create, save, delete)

Simple usage looks like:

Your composer.json file

{
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require": {
        "loduis/alegra-php": "1.0.*"
    }
}

Your test.php script

<?php

require './vendor/autoload.php';

Alegra\Api::auth('Your user', 'Your api token');
// Also you can auth api with your app credentials
/*
Alegra\Api::auth([
    'username' => 'Your user',
    'password' => 'Your password'
]);
*/

Create an new resource

$contact = Alegra\Contact::create(['name' => 'Your contact name']);
print_r($contact);

// Create using save

$contact = new Alegra\Contact;
$contact->name = 'My second contact';
$contact->save(); // Update the contact
print_r($contact);

Get an existing resource

$contact = Alegra\Contact::get(100); // where 100 is the id of resource.
$contact->identification = '900.123.123-8';
$contact->email = '[email protected]';
$contact->save();
print_r($contact);

Save an resource without fetch your data

$contact = new Alegra\Contact(100);
$contact->email = '[email protected]';
$contact->save();

Get all resources

$contacts = Alegra\Contact::all();
$contacts->each(function ($contact) {
    print_r($contact);
});

// $contacts is instanceof Illuminate\Support\Collection
// You can use methods like
print_r($contacts->slice(0, 3)); // The three first contacts.

Delete an resource

// Get a delete

Alegra\Contact::get(1)->delete();

// Delete without fetch data

(new Alegra\Contact(1))->delete();

// Delete using static interface

Alegra\Contact::delete(1);

Catch errors

try {
    // Your request code
}

// Exception when a client error is encountered (4xx codes)

catch (GuzzleHttp\Exception\ClientException $e) {
    // code
}

// Exception when a server error is encountered (5xx codes)

catch (GuzzleHttp\Exception\ServerException $e) {
    // code
}

// Exception thrown when a connection cannot be established.

catch (GuzzleHttp\Exception\ConnectException $e) {
    // code
}

// Other exceptions

catch (Exception $e) {
    // code
}

Documentation

Please see http://developer.alegra.com/docs for up-to-date documentation.

alegra-php's People

Contributors

loduis avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jorgadan

alegra-php's Issues

Composer install failed

When i try to execute the following command:

composer require loduis/alegra-php

I get this error message:Problem 1
- Installation request for loduis/alegra-php 1.0.* -> satisfiable by loduis/alegra-php[1.0.x-dev].
- loduis/alegra-php 1.0.x-dev requires loduis/illuminate-api 1.0.* -> no matching package found.

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.