Coder Social home page Coder Social logo

melonsmasher / ethos-laravel Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 2.89 MB

A Laravel package that utilizes ethos-php to interact with the Ellucian Ethos API.

Home Page: https://melonsmasher.github.io/ethos-laravel/

License: MIT License

PHP 100.00%
ellucian ethos ellucian-ethos php-library laravel laravel-package api-client ethos-php ellucian-ethos-api ellucian-banner

ethos-laravel's Introduction

ethos-laravel

Ellucian Ethos client library, built upon MelonSmasher/ethos-php, with enhancements for Laravel.

License GitHub issues GitHub top language Codacy grade


Installation

Pull the library into your project:

composer require melonsmasher/ethos-laravel

Publish ethos.php to the config directory:

php artisan vendor:publish --tag ethos

API Docs

Complete API docs can be found here.

Features

  • Ethos settings are read from .env.

  • Ethos sessions are cached.

  • Efficiently handles authentication.

    • New authenticated sessions are created before the previous session expires.
  • Traits for 316 Ethos data models, related by using the Ethos object ID.

  • Trait model responses can be cached for a configurable amount of time.

Config Options

# Your Ethos API key / refresh token.
ETHOS_SECRET=YourEthosApiKey
# The base url that should be used to connect to Ethos. If omitted https://integrate.elluciancloud.com is used.
ETHOS_BASE_URL=https://integrate.elluciancloud.com
# The ERP backend that is connected to Ethos. Must be either 'banner' or 'colleague'. If nothing is supplied 'colleague' is used.
ETHOS_ERP_BACKEND=banner
# How long trait responses should remain in the cache in seconds. Set to 0 to disable. If omitted this option is disabled.
ETHOS_TRAIT_CACHE_TTL=300

Usage/Examples

Using Helper Function

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MelonSmasher\EthosPHP\Student\CoursesClient;

class ExampleController extends Controller
{
    public function index()
    {
        $ethos = getEthosSession();
        $courses = new CoursesClient($ethos);
        return $courses->read()->toJson();
    }
}

Using Facade

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MelonSmasher\EthosPHP\Laravel\Facade\Ethos;
use MelonSmasher\EthosPHP\Foundation\BuildingsClient;

class ExampleController extends Controller
{
    public function index()
    {
        $ethos = Ethos::get();
        $buildings = new BuildingsClient($ethos);
        return $buildings->read()->data();
    }
}

Traits

HasEthosPersonModel

An example of how to use the HasEthosPersonModel trait on a Laravel User model.

User migration:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('ethos_person_id')->unique(); // Add this to your user's model and fill it with the related Ethos Person ID.
            $table->string('username');
            $table->string('name');
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

User model:

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use MelonSmasher\EthosPHP\Laravel\Traits\Foundation\HasEthosPersonModel;

class User extends Authenticatable
{
    use HasEthosPersonModel;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'ethos_person_id', // <--- This attribute must be present on your model.
        'username',
        'name'
    ];
}

Example usage :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Model\User;

class MyController extends Controller
{
    
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
    
    /**
    * Shows a user's Ethos Person Model
    */
    public function showUserAccount($id) 
    {
        $user = User::findOrFail($id);
        
        return $user->ethosPerson(); // Returns the Ethos account
    }
}

Dev Setup

Install PHIVE

Install build tools

phive install

Install composer requirements

./composer install

ethos-laravel's People

Contributors

melonsmasher avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ethos-laravel's Issues

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.