-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Airline templates (#83)
* 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
Showing
26 changed files
with
2,231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.