State-API: Unterschied zwischen den Versionen

Aus Maschinendeck Wiki
Zur Navigation springen Zur Suche springen
>Problame
(Created page with "{{Project |Why=Maschinenlesbarer Hackerspcae |What=software |Who=Problame |Status=running |Tags=php, quickhack }} Ein dreckiger Gammelfleischhack in PHP, weil schnell was her...")
 
>StefanOllinger
Keine Bearbeitungszusammenfassung
 
(2 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 11: Zeile 11:


→ https://github.com/maschinendeck/state.maschinendeck.org
→ https://github.com/maschinendeck/state.maschinendeck.org
== Protokoll/Howto Raumstatus ==
* Zugangsdaten von [[User:Problame|Problame]] geben lassen
* Zum Raumstatus setzen: Mache einen HTTPS-Request gegen http://state.maschinendeck.org/update.php mit HTTP-Basic-Auth und POST-Parameter open=0 für zu oder open=1 für offen
* Details: siehe [https://github.com/maschinendeck/state.maschinendeck.org|Github Repository von state.maschinendeck.org]
curl Beispielcode
    curl -v -H "Content-type: application/x-www-form-urlencoded" -H "Authorization: Basic base64_encode($APIUSER.':'.$APIPASSWORD)" -d 'open=0' -X POST http://state.maschinendeck.org/update.php
PHP Beispielcode:
  function setRaumstatus($newState) {
    global $APIUSER, $APIPASSWORD;
    $url = 'http://state.maschinendeck.org/update.php';
    $data = array("open" => $newState);
 
    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\nAuthorization: Basic ".base64_encode($APIUSER.':'.$APIPASSWORD)."\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
 
    if($state = json_decode($result))
        if($state->status == 200)
            return true;
   
    return false;
  }

Aktuelle Version vom 3. März 2017, 01:26 Uhr

State-API
Weshalb Maschinenlesbarer Hackerspcae
Was software
Wer Problame
Status läuft


Ein dreckiger Gammelfleischhack in PHP, weil schnell was her musste, um als Endpoint für die SpaceAPI sowie unsere Website herzuhalten.

Es geht darum, Metadaten über den Hackerspace maschinenlesbar bereitzustellen.

https://github.com/maschinendeck/state.maschinendeck.org

Protokoll/Howto Raumstatus[Bearbeiten | Quelltext bearbeiten]

curl Beispielcode

   curl -v -H "Content-type: application/x-www-form-urlencoded" -H "Authorization: Basic base64_encode($APIUSER.':'.$APIPASSWORD)" -d 'open=0' -X POST http://state.maschinendeck.org/update.php

PHP Beispielcode:

  function setRaumstatus($newState) {
   global $APIUSER, $APIPASSWORD;
   $url = 'http://state.maschinendeck.org/update.php';
   $data = array("open" => $newState);
  
   // use key 'http' even if you send the request to https://...
   $options = array(
       'http' => array(
           'header'  => "Content-type: application/x-www-form-urlencoded\r\nAuthorization: Basic ".base64_encode($APIUSER.':'.$APIPASSWORD)."\r\n",
           'method'  => 'POST',
           'content' => http_build_query($data),
       ),
   );
   $context  = stream_context_create($options);
   $result = file_get_contents($url, false, $context);
  
   if($state = json_decode($result))
       if($state->status == 200)
           return true;
   
   return false;
  }