Skip to content

Commit

Permalink
Add support for Airline templates (#83)
Browse files Browse the repository at this point in the history
* Fix OpenGraph template and element class, fix tests

* Fix variables name for OpenGraphElementTest

* Revert setUrl() to url()

* Add support for Airline templates

* Fix issues reported by StyleCI

* Fix issues reported by Travis
  • Loading branch information
ker0x authored and mpociot committed Oct 4, 2018
1 parent 8071f77 commit 627d1b8
Show file tree
Hide file tree
Showing 26 changed files with 2,231 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/Extensions/AbstractAirlineTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace BotMan\Drivers\Facebook\Extensions;

use JsonSerializable;
use BotMan\BotMan\Interfaces\WebAccess;
use BotMan\Drivers\Facebook\Interfaces\Airline;

abstract class AbstractAirlineTemplate implements JsonSerializable, WebAccess, Airline
{
/**
* @var string
*/
protected $locale;

/**
* @var null|string
*/
protected $themeColor;

/**
* AbstractAirlineTemplate constructor.
*
* @param string $locale
*/
public function __construct(string $locale)
{
$this->locale = $locale;
}

/**
* @param string $themeColor
*
* @return \BotMan\Drivers\Facebook\Extensions\AbstractAirlineTemplate
*/
public function themeColor(string $themeColor): self
{
$this->themeColor = $themeColor;

return $this;
}

/**
* @return array
*/
public function toArray(): array
{
return [
'attachment' => [
'type' => 'template',
'payload' => [
'locale' => $this->locale,
'theme_color' => $this->themeColor,
],
],
];
}

/**
* @return array
*/
public function jsonSerialize(): array
{
return $this->toArray();
}

/**
* Get the instance as a web accessible array.
* This will be used within the WebDriver.
*
* @return array
*/
public function toWebDriver(): array
{
return [
'locale' => $this->locale,
'theme_color' => $this->themeColor,
];
}
}
70 changes: 70 additions & 0 deletions src/Extensions/Airline/AbstractAirlineFlightInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace BotMan\Drivers\Facebook\Extensions\Airline;

use JsonSerializable;
use BotMan\Drivers\Facebook\Interfaces\Airline;

abstract class AbstractAirlineFlightInfo implements JsonSerializable, Airline
{
/**
* @var string
*/
protected $flightNumber;

/**
* @var \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport
*/
protected $departureAirport;

/**
* @var \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport
*/
protected $arrivalAirport;

/**
* @var \BotMan\Drivers\Facebook\Extensions\Airline\AirlineFlightSchedule
*/
protected $flightSchedule;

/**
* AbstractAirlineFlightInfo constructor.
*
* @param string $flightNumber
* @param \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport $departureAirport
* @param \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport $arrivalAirport
* @param \BotMan\Drivers\Facebook\Extensions\Airline\AirlineFlightSchedule $flightSchedule
*/
public function __construct(
string $flightNumber,
AirlineAirport $departureAirport,
AirlineAirport $arrivalAirport,
AirlineFlightSchedule $flightSchedule
) {
$this->flightNumber = $flightNumber;
$this->departureAirport = $departureAirport;
$this->arrivalAirport = $arrivalAirport;
$this->flightSchedule = $flightSchedule;
}

/**
* @return array
*/
public function toArray(): array
{
return [
'flight_number' => $this->flightNumber,
'departure_airport' => $this->departureAirport,
'arrival_airport' => $this->arrivalAirport,
'flight_schedule' => $this->flightSchedule,
];
}

/**
* @return array
*/
public function jsonSerialize(): array
{
return $this->toArray();
}
}
98 changes: 98 additions & 0 deletions src/Extensions/Airline/AirlineAirport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace BotMan\Drivers\Facebook\Extensions\Airline;

use JsonSerializable;

class AirlineAirport implements JsonSerializable
{
/**
* @var string
*/
protected $airportCode;

/**
* @var string
*/
protected $city;

/**
* @var string
*/
protected $terminal;

/**
* @var string
*/
protected $gate;

/**
* @param string $airportCode
* @param string $city
*
* @return \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport
*/
public static function create(string $airportCode, string $city): self
{
return new static($airportCode, $city);
}

/**
* AirlineAirport constructor.
*
* @param string $airportCode
* @param string $city
*/
public function __construct(string $airportCode, string $city)
{
$this->airportCode = $airportCode;
$this->city = $city;
}

/**
* @param string $terminal
*
* @return \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport
*/
public function terminal(string $terminal): self
{
$this->terminal = $terminal;

return $this;
}

/**
* @param string $gate
*
* @return \BotMan\Drivers\Facebook\Extensions\Airline\AirlineAirport
*/
public function gate(string $gate): self
{
$this->gate = $gate;

return $this;
}

/**
* @return array
*/
public function toArray(): array
{
$array = [
'airport_code' => $this->airportCode,
'city' => $this->city,
'terminal' => $this->terminal,
'gate' => $this->gate,
];

return array_filter($array);
}

/**
* @return array
*/
public function jsonSerialize(): array
{
return $this->toArray();
}
}
Loading

0 comments on commit 627d1b8

Please sign in to comment.