Refractor AirMedia & Call Services

This commit is contained in:
alphayax 2016-06-11 21:28:52 +02:00
parent 1a684b206d
commit 173950b095
12 changed files with 133 additions and 100 deletions

View File

@ -7,7 +7,7 @@
[![Build Status](https://travis-ci.org/alphayax/freebox_api_php.svg?branch=master)](https://travis-ci.org/alphayax/freebox_api_php)
[![Coverage](https://api.codacy.com/project/badge/Coverage/f3569cf671f04b8ab6d699be3fd011e5)](https://www.codacy.com/app/alphayax/freebox_api_php?utm_source=github.com&utm_medium=referral&utm_content=alphayax/freebox_api_php&utm_campaign=Badge_Coverage)
![codacy](https://api.codacy.com/project/badge/Grade/f3569cf671f04b8ab6d699be3fd011e5)
[![Codacy](https://api.codacy.com/project/badge/Grade/f3569cf671f04b8ab6d699be3fd011e5)](https://www.codacy.com/app/alphayax/freebox_api_php?utm_source=github.com&utm_medium=referral&utm_content=alphayax/freebox_api_php&utm_campaign=Badge_Grade)
![license](https://img.shields.io/packagist/l/alphayax/freebox_api_php.svg)
@ -88,9 +88,9 @@ L'intégralité des fonctionnalités de l'API Freebox (v3) sont implémentées :
- BSS
- Planning
- Mac Filter
- Parental Control
- Filter
- Planning
- Parental Control
- Filter
- Planning
## Utilisation

View File

@ -1,4 +1,7 @@
<?php
use alphayax\freebox\api\v3\services;
use alphayax\freebox\api\v3\symbols;
use alphayax\freebox\api\v3\models;
/// Require Composer AutoLoader
require_once '../../vendor/autoload.php';
@ -9,21 +12,21 @@ $App->authorize();
$App->openSession();
$AirMediaService = new \alphayax\freebox\api\v3\services\AirMedia\AirMedia( $App);
// AirMedia Config
$AirMediaService = new services\AirMedia\Config( $App);
$Configuration = $AirMediaService->getConfiguration();
print_r( $Configuration);
// AirMedia Receivers
$Receivers = $AirMediaService->getAirMediaReceivers();
$AirMediaService = new services\AirMedia\AirMediaReceiver( $App);
$Receivers = $AirMediaService->getAll();
print_r( $Receivers);
// AirMedia Request
$Request = new \alphayax\freebox\api\v3\models\AirMedia\AirMediaReceiverRequest();
$Request->setAction( \alphayax\freebox\api\v3\symbols\AirMedia\Action::START);
$Request->setMediaType( \alphayax\freebox\api\v3\symbols\AirMedia\MediaType::VIDEO);
$Request = new models\AirMedia\AirMediaReceiverRequest();
$Request->setAction( symbols\AirMedia\Action::START);
$Request->setMediaType( symbols\AirMedia\MediaType::VIDEO);
$Request->setMedia( 'http://anon.nasa-global.edgesuite.net/HD_downloads/GRAIL_launch_480.mov');
$Status = $AirMediaService->sendRequestToAirMediaReceiver( 'Freebox Player', $Request);
$Status = $AirMediaService->sendRequest( 'Freebox Player', $Request);
print_r( $Status);

View File

@ -8,27 +8,14 @@ $App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.call', 'PH
$App->authorize();
$App->openSession();
$ContactService = new \alphayax\freebox\api\v3\services\Call\ContactEntry( $App);
/// Get calls
$ContactService = new \alphayax\freebox\api\v3\services\Call\Contact\ContactEntry( $App);
$ContactEntries = $ContactService->getAll();
print_r( $ContactEntries);
/*
$ContactNumber = new \alphayax\freebox\api\v3\models\Call\ContactNumber();
$ContactNumber->setContactId( 1);
$ContactNumber->setNumber( '0213456789');
$ContactNumber->setType( \alphayax\freebox\api\v3\symbols\Call\ContactNumberType::HOME);
$ContactNumber = $ContactService->addContactNumber( $ContactNumber);
print_r( $ContactNumber);
$ContactNumbers = $ContactService->getContactNumbersFromContactId( 1);
print_r( $ContactNumbers);
*/
/*
$ContactAddressService = new \alphayax\freebox\api\v3\services\Call\ContactAddress( $App);
/// Contact Address
$ContactAddressService = new \alphayax\freebox\api\v3\services\Call\Contact\ContactAddress( $App);
$ContactAddress = new \alphayax\freebox\api\v3\models\Call\ContactAddress();
$ContactAddress->setContactId( $ContactEntries[0]->getId());
@ -41,10 +28,10 @@ print_r( $ContactAddressCreated);
$ContactAddressDeleted = $ContactAddressService->delete( $ContactAddressCreated);
print_r( $ContactAddressDeleted);
*/
$ContactNumbersService = new \alphayax\freebox\api\v3\services\Call\ContactNumber( $App);
/// Contact number
$ContactNumbersService = new \alphayax\freebox\api\v3\services\Call\Contact\ContactNumber( $App);
$Number = new \alphayax\freebox\api\v3\models\Call\ContactNumber();
$Number->setType(\alphayax\freebox\api\v3\symbols\Call\ContactNumberType::HOME);

View File

@ -71,7 +71,7 @@ abstract class Model implements \JsonSerializable {
* which is a value of any type other than a resource.
* @since 5.4.0
*/
function jsonSerialize() {
public function jsonSerialize() {
return $this->toArray();
}

View File

@ -1,62 +0,0 @@
<?php
namespace alphayax\freebox\api\v3\services\AirMedia;
use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service;
/**
* Class AirMedia
* @package alphayax\freebox\api\v3\services\AirMedia
*/
class AirMedia extends Service {
const API_AIRMEDIA_CONFIG = '/api/v3/airmedia/config/';
const API_AIRMEDIA_RECEIVERS = '/api/v3/airmedia/receivers/';
/**
* @throws \Exception
* @return models\AirMedia\AirMediaConfig
*/
public function getConfiguration(){
$rest = $this->getAuthService( self::API_AIRMEDIA_CONFIG);
$rest->GET();
return $rest->getResult( models\AirMedia\AirMediaConfig::class);
}
/**
* @param models\AirMedia\AirMediaConfig $new_AirMediaConfig
* @return models\AirMedia\AirMediaConfig
* @throws \Exception
*/
public function setConfiguration( models\AirMedia\AirMediaConfig $new_AirMediaConfig){
$rest = $this->getAuthService( self::API_AIRMEDIA_CONFIG);
$rest->PUT( $new_AirMediaConfig);
return $rest->getResult( models\AirMedia\AirMediaConfig::class);
}
/**
* Get the list of AirMediaReceiver connected to the Freebox Server
* @return models\AirMedia\AirMediaReceiver[]
*/
public function getAirMediaReceivers(){
$rest = $this->getAuthService( self::API_AIRMEDIA_RECEIVERS);
$rest->GET();
return $rest->getResultAsArray( models\AirMedia\AirMediaReceiver::class);
}
/**
* @param string $AirMediaReceiver_name
* @param models\AirMedia\AirMediaReceiverRequest $AirMediaReceiverRequest
* @return bool
*/
public function sendRequestToAirMediaReceiver( $AirMediaReceiver_name, models\AirMedia\AirMediaReceiverRequest $AirMediaReceiverRequest){
$rest = $this->getAuthService( self::API_AIRMEDIA_RECEIVERS . $AirMediaReceiver_name . DIRECTORY_SEPARATOR);
$rest->POST( $AirMediaReceiverRequest);
return $rest->getSuccess();
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace alphayax\freebox\api\v3\services\AirMedia;
use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service;
/**
* Class AirMedia
* @package alphayax\freebox\api\v3\services\AirMedia
*/
class AirMediaReceiver extends Service {
const API_AIRMEDIA_RECEIVERS = '/api/v3/airmedia/receivers/';
/**
* Get the list of AirMediaReceiver connected to the Freebox Server
* @return models\AirMedia\AirMediaReceiver[]
*/
public function getAll(){
$rest = $this->getAuthService( self::API_AIRMEDIA_RECEIVERS);
$rest->GET();
return $rest->getResultAsArray( models\AirMedia\AirMediaReceiver::class);
}
/**
* Sending a request to an AirMedia receiver
* @param string $AirMediaReceiverName
* @param models\AirMedia\AirMediaReceiverRequest $AirMediaReceiverRequest
* @return bool
*/
public function sendRequest($AirMediaReceiverName, models\AirMedia\AirMediaReceiverRequest $AirMediaReceiverRequest){
$rest = $this->getAuthService( self::API_AIRMEDIA_RECEIVERS . $AirMediaReceiverName . DIRECTORY_SEPARATOR);
$rest->POST( $AirMediaReceiverRequest);
return $rest->getSuccess();
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace alphayax\freebox\api\v3\services\AirMedia;
use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service;
/**
* Class Config
* @package alphayax\freebox\api\v3\services\AirMedia
*/
class Config extends Service {
const API_AIRMEDIA_CONFIG = '/api/v3/airmedia/config/';
/**
* Get the current AirMedia configuration
* @return models\AirMedia\AirMediaConfig
*/
public function getConfiguration(){
$rest = $this->getAuthService( self::API_AIRMEDIA_CONFIG);
$rest->GET();
return $rest->getResult( models\AirMedia\AirMediaConfig::class);
}
/**
* Update the AirMedia configuration
* @param models\AirMedia\AirMediaConfig $new_AirMediaConfig
* @return models\AirMedia\AirMediaConfig
*/
public function setConfiguration( models\AirMedia\AirMediaConfig $new_AirMediaConfig){
$rest = $this->getAuthService( self::API_AIRMEDIA_CONFIG);
$rest->PUT( $new_AirMediaConfig);
return $rest->getResult( models\AirMedia\AirMediaConfig::class);
}
}

View File

@ -1,5 +1,5 @@
<?php
namespace alphayax\freebox\api\v3\services\Call;
namespace alphayax\freebox\api\v3\services\Call\Contact;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
@ -13,6 +13,7 @@ class ContactAddress extends Service {
const API_ADDRESS = '/api/v3/address/';
/**
* Get the address (with the given id)
* @param int $contactAddressId
* @return models\Call\ContactAddress
*/
@ -24,6 +25,7 @@ class ContactAddress extends Service {
}
/**
* Add an address
* @param models\Call\ContactAddress $contactAddress
* @return models\Call\ContactAddress
*/
@ -35,6 +37,7 @@ class ContactAddress extends Service {
}
/**
* Remove an address
* @param models\Call\ContactAddress $contactAddress
* @return bool
*/
@ -43,6 +46,7 @@ class ContactAddress extends Service {
}
/**
* Remove an address (with the given id)
* @param int $contactAddressId
* @return bool
*/
@ -54,6 +58,7 @@ class ContactAddress extends Service {
}
/**
* Update an address
* @param models\Call\ContactAddress $contactAddress
* @return models\Call\ContactAddress
*/

View File

@ -1,5 +1,5 @@
<?php
namespace alphayax\freebox\api\v3\services\Call;
namespace alphayax\freebox\api\v3\services\Call\Contact;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
@ -13,6 +13,7 @@ class ContactEmail extends Service {
const API_EMAIL = '/api/v3/email/';
/**
* Get the email contact (with the given id)
* @param int $ContactEmailId
* @return models\Call\ContactEmail
*/
@ -24,6 +25,7 @@ class ContactEmail extends Service {
}
/**
* Create a new email contact
* @param models\Call\ContactEmail $ContactEmail
* @return models\Call\ContactEmail
*/
@ -35,6 +37,7 @@ class ContactEmail extends Service {
}
/**
* Remove an email contact
* @param models\Call\ContactEmail $ContactEmail
* @return bool
*/
@ -43,6 +46,7 @@ class ContactEmail extends Service {
}
/**
* Remove an email contact (with the given id)
* @param int $ContactEmailId
* @return bool
*/
@ -54,6 +58,7 @@ class ContactEmail extends Service {
}
/**
* Update an email contact
* @param models\Call\ContactEmail $ContactEmail
* @return models\Call\ContactEmail
*/

View File

@ -1,5 +1,5 @@
<?php
namespace alphayax\freebox\api\v3\services\Call;
namespace alphayax\freebox\api\v3\services\Call\Contact;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
@ -17,8 +17,8 @@ class ContactEntry extends Service {
const API_CONTACT_EMAILS = '/api/v3/contact/%u/emails/';
/**
* List every calls
* @return models\Call\CallEntry[]
* List all contacts
* @return models\Call\ContactEntry[]
*/
public function getAll(){
$rest = $this->getAuthService( self::API_CONTACT);
@ -28,6 +28,7 @@ class ContactEntry extends Service {
}
/**
* Get a specific contact entry
* @param int $ContactEntryId
* @return models\Call\ContactEntry
*/
@ -39,6 +40,7 @@ class ContactEntry extends Service {
}
/**
* Add a contact entry
* @param models\Call\ContactEntry $ContactEntry
* @return models\Call\ContactEntry
*/
@ -50,6 +52,7 @@ class ContactEntry extends Service {
}
/**
* Update a contact entry
* @param models\Call\ContactEntry $ContactEntry
* @return models\Call\ContactEntry
*/
@ -61,6 +64,7 @@ class ContactEntry extends Service {
}
/**
* Remove a contact entry
* @param models\Call\ContactEntry $ContactEntry
* @return models\Call\ContactEntry
*/
@ -69,6 +73,7 @@ class ContactEntry extends Service {
}
/**
* Remove a contact entry (with the specified id)
* @param int $ContactEntryId
* @return models\Call\ContactEntry
*/
@ -80,6 +85,7 @@ class ContactEntry extends Service {
}
/**
* Get all numbers associated to a given contact id
* @param int $ContactEntryId
* @return models\Call\ContactNumber[]
*/
@ -92,6 +98,7 @@ class ContactEntry extends Service {
}
/**
* Get all addresses associated to a given contact id
* @param int $ContactEntryId
* @return models\Call\ContactAddress[]
*/
@ -104,6 +111,7 @@ class ContactEntry extends Service {
}
/**
* Get all email addresses associated to a given contact id
* @param int $ContactEntryId
* @return models\Call\ContactEmail[]
*/
@ -116,6 +124,7 @@ class ContactEntry extends Service {
}
/**
* Get all URLs associated to a given contact id
* @param int $ContactEntryId
* @return models\Call\ContactUrl[]
*/

View File

@ -1,5 +1,5 @@
<?php
namespace alphayax\freebox\api\v3\services\Call;
namespace alphayax\freebox\api\v3\services\Call\Contact;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
@ -13,6 +13,7 @@ class ContactNumber extends Service {
const API_NUMBER = '/api/v3/number/';
/**
* Get the contact number (with the given id)
* @param int $ContactNumberId
* @return models\Call\ContactNumber
*/
@ -24,6 +25,7 @@ class ContactNumber extends Service {
}
/**
* Add a new contact number
* @param models\Call\ContactNumber $ContactNumber
* @return models\Call\ContactNumber
*/
@ -35,6 +37,7 @@ class ContactNumber extends Service {
}
/**
* Remove a contact number
* @param models\Call\ContactNumber $ContactNumber
* @return bool
*/
@ -43,6 +46,7 @@ class ContactNumber extends Service {
}
/**
* Remove a contact number (with the specified id)
* @param int $ContactNumberId
* @return bool
*/
@ -54,6 +58,7 @@ class ContactNumber extends Service {
}
/**
* Update a contact number
* @param models\Call\ContactNumber $ContactNumber
* @return models\Call\ContactNumber
*/

View File

@ -1,5 +1,5 @@
<?php
namespace alphayax\freebox\api\v3\services\Call;
namespace alphayax\freebox\api\v3\services\Call\Contact;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
@ -13,6 +13,7 @@ class ContactUrl extends Service {
const API_URL = '/api/v3/url/';
/**
* Get the contact url (with the given id)
* @param int $ContactUrlId
* @return models\Call\ContactUrl
*/
@ -24,6 +25,7 @@ class ContactUrl extends Service {
}
/**
* Add a new contact url
* @param models\Call\ContactUrl $ContactUrl
* @return models\Call\ContactUrl
*/
@ -35,6 +37,7 @@ class ContactUrl extends Service {
}
/**
* Remove a contact url
* @param models\Call\ContactUrl $ContactUrl
* @return bool
*/
@ -43,6 +46,7 @@ class ContactUrl extends Service {
}
/**
* Remove a contact url (with the given id)
* @param int $ContactUrlId
* @return bool
*/
@ -54,6 +58,7 @@ class ContactUrl extends Service {
}
/**
* Update a contact url
* @param models\Call\ContactUrl $ContactUrl
* @return models\Call\ContactUrl
*/