freebox_api_php/freebox/api/v3/Service.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2016-02-02 20:34:57 +01:00
<?php
namespace alphayax\freebox\api\v3;
2016-06-03 22:25:19 +02:00
use alphayax\freebox\utils;
2016-02-02 20:34:57 +01:00
/**
* Class freebox_service
*/
abstract class Service {
2016-06-03 22:25:19 +02:00
/** @var \alphayax\freebox\utils\Application */
2016-02-02 20:34:57 +01:00
protected $application;
/// Freebox API host URI
const API_HOST = 'http://mafreebox.freebox.fr';
/**
* Service constructor.
2016-06-03 22:25:19 +02:00
* @param \alphayax\freebox\utils\Application $application
2016-02-02 20:34:57 +01:00
*/
2016-06-03 22:25:19 +02:00
public function __construct( utils\Application $application){
2016-02-02 20:34:57 +01:00
$this->application = $application;
}
/**
* @param $service
2016-06-03 22:25:19 +02:00
* @return \alphayax\freebox\utils\rest\Rest
2016-02-02 20:34:57 +01:00
*/
protected function getService( $service){
2016-06-03 22:25:19 +02:00
return new utils\rest\Rest( static::API_HOST . $service);
2016-02-02 20:34:57 +01:00
}
/**
* @param string $service
* @param bool $isJson
* @param bool $returnAsArray
2016-06-03 22:25:19 +02:00
* @return utils\rest\RestAuth
2016-02-02 20:34:57 +01:00
*/
protected function getAuthService( $service, $isJson = true, $returnAsArray = true){
2016-06-03 22:25:19 +02:00
$rest = new utils\rest\RestAuth( static::API_HOST . $service, $isJson, $returnAsArray);
2016-02-02 20:34:57 +01:00
$rest->setSessionToken( $this->application->getSessionToken());
return $rest;
}
}