Git Product home page Git Product logo

flaryi's Introduction

Kiryi's FLARYI

A Flarum API client.

Installation

composer require kiryi/flaryi

Usage

First initialize the client in one of two possible ways. Then call an available Endpoint and perform a method associated with it. You will get the response from Flarum's API as a return and may use it in your further logic.

Constructor Definition

__construct(string $filepath = null)

Parameters

filepath
Optional filepath relative your project's root directory to a custom configuration INI file. If nothing is provided, default (config/flaryi.ini) is used (more information).

Method Definition call

call(string $endpoint): object

Assigns a variable to the view's data object.

Parameters

endpoint
One of the available Endpoints.

Return Values

Returns the Endpoint you can then perform one of its associated methods.

Initialization

You have to provide the client at least two mandatory parameters you can must define in a custom configuration INI file or use the default one.

apiUrl
The URL of your Flarum's API. Usually it is {YOURFLARUMDOMAIN}/api.

apiKey
A API key from your Flarum installation. Currently you have to manually create a 40 character long random string and put it directly into your Flarum's databse api_keys table key column together with an User ID to the user_id column. The User ID depends on the actions you want to perform. If you want to use every possible API Call, use an Administrator User. If not, you can create a role in your Flarum's administration area with the prefered rights.

Wheter you use a custom or the default file, the contens have to be:

[flaryi]
apiUrl = {URLTOYOURFLARUMAPI}
apiKey = {APIKEYFROMYOUFLARUMINSTALLATION}

The default filepath is config/flaryi.ini. If you want to use a custom filepath, you have to provide it to the constructor of the client. The path is relative to your project's root directory.

Available Endpoints

The Flarum API provides some Endpoint you can perform several actions on it. FLARYI covering only some Endpoints and each Endpoint only provides some available methods to perform (actions).

Currently available Endpoints:

Example

configuration/config.ini

[flaryi]
apiUrl = https://flaryi-flarum.com/api
apiKey = qwe147asd258yxc369rtz123fgh456vbn789ui

src/Controller/UserListController.php

$client = new \Kiryi\Flaryi\Client('configuration/config.ini');
$userList = $client->call('User')->getAll([
    'username',
    'email',
]);

will save an object to $userList containing all Users of your Flarum. The User objects containg an ID (always), the requested fields username and email as well as some other information the API provides. Please keep in mind, that not everything can be filtered with an API Call, but you can use the received User list to perform more filtering and e.g. following API Calls like so:

src/Controller/UserGroupController.php

$user = $client->call('User')->get(5);
if (isset($user->data->relationships->groups->data[0]->id)) {
    $client->call('User')->setGroups(5, [2, 3]);
    echo 'User was added to Group 2 and 3.';
} else {
    echo 'User is already in a Group.';
}

This script

  • Gets User with ID 5 through an API Call
  • Checks if the User has a Group
  • If yes, nothing will be changed
  • If no, Group 2 and 3 is set to the User through a second API call

flaryi's People

Contributors

oxsteven avatar

Watchers

James Cloos avatar  avatar

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.