Coder Social home page Coder Social logo

vineyardkoeln / churchtools-api Goto Github PK

View Code? Open in Web Editor NEW
14.0 7.0 8.0 263 KB

Access the API for ChurchTools at https://api.churchtools.de/ in an object-oriented way that integrates nicely with modern PHP projects via Composer.

License: Apache License 2.0

PHP 100.00%

churchtools-api's Introduction

No longer maintained. Please move to https://github.com/5pm-HDH/churchtools-api!

ChurchTools API

Access the API for ChurchTools at https://api.churchtools.de/ in an object-oriented way that integrates nicely with modern PHP projects via Composer.

The API v2 which uses the new (2019) REST api can be found in the README_API2.md.

Free software (both as in free beer and free speech) by Vineyard Köln, licensed under Apache 2.0

[4]:

Further development

Currently this library has not been updated recently. If you wish to participate in development, you can send us pull requests to integrate in the main branch

Other php CT API implementations

https://github.com/5pm-HDH/churchtools-api

Installation

composer require vineyardkoeln/churchtools-api

Usage

Prerequisite: Autoloading

If you haven't already configured autoloading in your project, start by including the Composer autoloader:

require __DIR__ . '/vendor/autoload.php';

Login to use the API

In order to use the ChurchTools API you need a valid login. This can either be a username / password pair or you can use a login ID and token. The latter is the recommended way because it keeps you API separate from any user account but username and password is fine for testing purposes.

To login with username and password, use this code snippet:

$api = \ChurchTools\Api\RestApi::createWithUsernamePassword('mychurch', 'username', 'password');

where mychurch is your church handle or subdomain like in the URL to your web interface: https://mychurch.church.tools/. If you are self-hosting ChurchTools, then use full server name of your installation without protocol (so for example: 'mychurch.example.org').

To login with a login ID and token, use this code snippet (recommended):

$api = \ChurchTools\Api\RestApi::createWithLoginIdToken('mychurch', 1337, 'a really long seemingly random string of 256 alphanumeric characters');

You can retrieve the token by logging in once to the API with a username and password via the static method getLoginToken() (see below).

The login is valid for the duration of the programm call (script lifecycle). This way you can perform many requests with only one login via the static constructor method of your choice.

The following examples mostly assume you have a valid login and the API object is assigned to the variable $api.

Get Token

In order to acquire a login ID and token you must call the getLoginToken method once:

$result = \ChurchTools\Api\RestApi::getLoginToken($churchHandle, $usernameOrEmail, $pass);
var_dump($result);

This will return something like:

array(2) {
  ["status"]=>
  string(7) "success"
  ["data"]=>
  array(2) {
    ["token"]=>
    string(256) "this is the very long string of seemingly random 256 alphanumberic characters that you need to store"
    ["id"]=>
    string(4) "1337"
  }
}

Get all calendar entries

To get all calendar entries from now until 10 days in the future:

$events = $api->getCalendarEvents([1,2,…]);

foreach ($events['data'] as $event) {
    // …
}

This method also has two optional parameters, $toDays and $fromDays, which allow you to select the desired timeframe.

Get master data

To get calendar or service master data, use this method:

var_dump($api->getCalendarMasterData());

or

var_dump($api->getServiceMasterData());

TODO: In one of the upcoming alpha versions, methods will return model objects and not plain arrays.

TODOs

  1. Wrap more API calls
  2. Use Model classes for the return data instead of plain arrays
  3. Someday, wrap all available API calls
  4. Document every single available method

churchtools-api's People

Contributors

a-schild avatar alexanderkraemer avatar jochenkalmbach avatar yeticgn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

churchtools-api's Issues

State of API2 implementation and usage questions

I'm planing to build a website that uses the data we have on church.tools, but can be styled as we wish. So it will be like a reimplementation of the frontend of the mychurch.church.tools website. I'm still figuring out, whether I want to implement the connection to the backend via JS in the webbrowser or via php on my webserver. If I chose the latter, this project seems useful, but I have some questions.

  1. Is this project still maintained? The last change was last year.

  2. Are you actively using this project yourself, or have you switched to another solution?

  3. How much of the API2 is implemented (percentagewise)?

  4. Why are you using the Ajax APi to get the login token here? Why not via the rest api as explained here?

  5. How is the authentication supposed to work with this package?
    the CT docs say one should always send a valid session cookie (as it is faster) and only if it expires, one should use the login token. when you use the login token, you get a new valid session cookie in the response. Are you using the session cookie? it seems, only the login token is stored in the RestApi2 Object. (sry, my php knowledge is very limited.)

  6. What CT user should the webserver use? should we create a special CT user for the website? then we need to make permission checks on our site, and the webserver contains login data for an account with many( maybe all) rights on CT. Or should we better ask the user for his CT username and password and the webserver forwards them to CT? it feels wrong, to handle user names and passwords for another website.

  7. suppose we take the latter: how do we handle the session cookie and login token? is it ok to store one or both on the webserver for longer than just the current request? it would probably be better to store both on the client and then use the session-cookie (sent with every request). Only if we notice, that it expired, we ask the client for the login token, get and forward the new session-cookie and forget the the login token again. but the way RestApi2 is currently written, it looks like there is no way to create a client object with just a session cookie. can you tell me why?

I feel like some questions are beginner questions, but that's just what I am. Thanks for your understanding.

Use object model for master data and other API calls

Hello,

I have written some classes to be used with the API, which encapsulate the calendar, events and parts of the bookings stuff of ct.

Before I make a pull request, how should I integrate it with the existing API?

  1. Change api calls to return the objects (Would not be backward compatible)
  2. Add separate calls which return object and leave the existing calls as they are?

Currently it would be the getCalendarEvents which I have implemented with an object model, and also the calendar part of the masterdata.

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.