Skip to content

Commit

Permalink
Fixed missing exception
Browse files Browse the repository at this point in the history
Fixed missing vue date picker
  • Loading branch information
Alexej Krzewitzki committed Dec 22, 2021
1 parent c679195 commit b1c0ce6
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 97 deletions.
142 changes: 83 additions & 59 deletions src/LaravelCM/BaseClient.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?php

namespace Flobbos\LaravelCM;
use Flobbos\LaravelCM\Contracts\BaseClientContract;
use GuzzleHttp\Client;

use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Flobbos\LaravelCM\Contracts\BaseClientContract;
use Flobbos\LaravelCM\Exceptions\ConfigKeyNotSetException;

abstract class BaseClient implements BaseClientContract{

protected $guzzle,$base_uri,$skip_key;
abstract class BaseClient implements BaseClientContract
{

protected $guzzle, $base_uri, $skip_key;
protected $options = [];

public function __construct() {

public function __construct()
{
//Initialize Guzzle
$this->initGuzzle();
//Set options
Expand All @@ -22,165 +26,185 @@ public function __construct() {
'listID' => config('laravel-cm.default_list_id')
]);
}


public function setOptions(array $options): self {


public function setOptions(array $options): self
{
$this->options = $options;
return $this;
}

public function getOptions(): array {

public function getOptions(): array
{
return $this->options;
}

/**
* Set the client API Key
* @param string $key
*/
public function setClientApiKey(string $key = null): self{
public function setClientApiKey(string $key = null): self
{
$this->options['clientApiKey'] = $key;
return $this;
}

/**
* Get the current client API Key
*/
public function getClientApiKey(): string{
public function getClientApiKey(): string
{
return $this->options['clientApiKey'];
}

/**
* Set the client ID
* @param string $client_id
* @return \self
*/
public function setClientID(string $client_id = null): self{
public function setClientID(string $client_id = null): self
{
$this->options['clientID'] = $client_id;
return $this;
}

/**
* Get the current client ID
* @return string
*/
public function getClientID(): string {
public function getClientID(): string
{
return $this->options['clientID'];
}

/**
* Set the list ID to be used
* @param string $list_id
*/
public function setListID(string $list_id = null): self{
$this->options['listID'] = $list_id?:$this->getListID();
public function setListID(string $list_id = null): self
{
$this->options['listID'] = $list_id ?: $this->getListID();
return $this;
}

/**
* Get the current List ID
*/
public function getListID(): string{
public function getListID(): string
{
return $this->options['listID'];
}

/**
* Set the format of the call
* @param string $format json|xml
*/
public function setFormat(string $format): self{
public function setFormat(string $format): self
{
$this->options['format'] = $format;
return $this;
}

/**
* Get the current format in use
*/
public function getFormat(): string{
public function getFormat(): string
{
return $this->options['format'];
}

/**
* Get a clean guzzle client object
*/
public function getGuzzle(): Client{
public function getGuzzle(): Client
{
return new Client;
}

/**
* Initialize guzzle with a base_uri called by the constructor
* @param type $base_uri
*/
public function initGuzzle($base_uri = null): self{
if(!is_null($base_uri)){
$this->guzzle = new Client(['base_uri'=>config('laravel-cm.base_uri')]);
public function initGuzzle($base_uri = null): self
{
if (!is_null($base_uri)) {
$this->guzzle = new Client(['base_uri' => config('laravel-cm.base_uri')]);
}
$this->guzzle = new Client(['base_uri'=>config('laravel-cm.base_uri')]);
$this->guzzle = new Client(['base_uri' => config('laravel-cm.base_uri')]);
return $this;
}

/**
* Retrieve auth information for API Call
* @return array
*/
public function getAuthInformation(): array {
return [$this->getClientApiKey(),''];
public function getAuthInformation(): array
{
return [$this->getClientApiKey(), ''];
}

/**
* Retrieve basic Guzzle options for making an API call
* @return array
*/
public function getBaseRequestData(): array{
public function getBaseRequestData(): array
{
return [
'stream' => true,
'auth' => $this->getAuthInformation(),
'headers' => [
'Accept' => 'application/json'
]
'Accept' => 'application/json'
]
];
}

/**
* Merge the request data with parameters provided by calling function
* @param array $request_data
* @return type
*/
public function mergeRequestData(array $request_data): array{
return array_merge($request_data,$this->getBaseRequestData());
public function mergeRequestData(array $request_data): array
{
return array_merge($request_data, $this->getBaseRequestData());
}

/**
* Check api options and skip optional values
* @return Guzzle client
*/
private function checkOptions(): void{
foreach($this->options as $k=>$v){
if(empty($v) && $this->skip_key != $k){
throw new ConfigKeyNotSetException('No '.$k.' found. Please update your settings or generate a resource');
private function checkOptions(): void
{
foreach ($this->options as $k => $v) {
if (empty($v) && $this->skip_key != $k) {
throw new ConfigKeyNotSetException('No ' . $k . ' found. Please update your settings or generate a resource');
}
}
return;
}

/**
* Call the guzzle Client and provide optional validation key to skip
* when validating options
* @return Guzzle\Client
*/
public function callApi(): \GuzzleHttp\Client{
public function callApi(): \GuzzleHttp\Client
{
$this->checkOptions();
return $this->guzzle;
}

public function makeCall($method = 'get', $url, array $request_data){
try{

public function makeCall($method = 'get', $url, array $request_data)
{
try {
return $this->formatResult(
$this->callApi()->{$method}($url.'.'.$this->getFormat(),
$this->mergeRequestData($request_data)));
$this->callApi()->{$method}(
$url . '.' . $this->getFormat(),
$this->mergeRequestData($request_data)
)
);
} catch (RequestException $ex) {
$response_body = $this->formatBody($ex->getResponse()->getBody());
throw new Exception('Code '.$response_body->Code.': '.$response_body->Message);
throw new Exception('Code ' . $response_body->Code . ': ' . $response_body->Message);
}
}

}
}
76 changes: 38 additions & 38 deletions src/resources/views/bootstrap4/campaigns/schedule.blade.php
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
@extends('layouts.'.config('laravel-cm.layout_file'))

@section('content')
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="card">

<form action="{{ route('laravel-cm::campaigns.send',$campaign->CampaignID) }}" role="form" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}

<div class="card-header">
<h3>{{$campaign->Name}}</h3>
@lang('laravel-cm::campaigns.schedule_title')
</div>

<div class="card-body">

@include('laravel-cm::notifications')

@lang('laravel-cm::campaigns.preview'): <a href="{{$campaign->PreviewURL}}" target="_blank"><strong>{{$campaign->PreviewURL}}</strong></a><br />

<div class="form-group">
<label class="control-label" for="ConfirmationEmail">@lang('laravel-cm::campaigns.confirmation_emails_title')</label>
<input class="form-control" placeholder="@lang('laravel-cm::campaigns.confirmation_emails_placeholder')" type="text" name="ConfirmationEmail" value="{{ old('ConfirmationEmail') }}" />
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="card">

<form action="{{ route('laravel-cm::campaigns.send', $campaign->CampaignID) }}" role="form" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}

<div class="form-group">
<label class="control-label" for="SendDate">@lang('laravel-cm::campaigns.send_date')</label>
<vue-date-picker name="SendDate"></vue-date-picker>
<div class="card-header">
<h3>{{ $campaign->Name }}</h3>
@lang('laravel-cm::campaigns.schedule_title')
</div>

</div>
<div class="card-body">

<div class="card-footer">
@include('laravel-cm::notifications')

<div class="row">
@lang('laravel-cm::campaigns.preview'): <a href="{{ $campaign->PreviewURL }}" target="_blank"><strong>{{ $campaign->PreviewURL }}</strong></a><br />

<div class="col-sm-6">
<a href="{{ route('laravel-cm::campaigns.index') }}" class="btn btn-danger">@lang('laravel-cm::crud.cancel')</a>
<div class="form-group">
<label class="control-label" for="ConfirmationEmail">@lang('laravel-cm::campaigns.confirmation_emails_title')</label>
<input class="form-control" placeholder="@lang('laravel-cm::campaigns.confirmation_emails_placeholder')" type="text" name="ConfirmationEmail" value="{{ old('ConfirmationEmail') }}" />
</div>

<div class="col-sm-6 text-right">
<button type="submit" class="btn btn-success">@lang('laravel-cm::crud.save')</button>
<div class="form-group">
<label class="control-label" for="SendDate">@lang('laravel-cm::campaigns.send_date')</label>
<input type="text" name="SendDate" class="form-control" placeholder="Format: yyyy-mm-dd HH:mm" />
</div>

</div>

</div>
<div class="card-footer">

<div class="row">

</form>
<div class="col-sm-6">
<a href="{{ route('laravel-cm::campaigns.index') }}" class="btn btn-danger">@lang('laravel-cm::crud.cancel')</a>
</div>

<div class="col-sm-6 text-right">
<button type="submit" class="btn btn-success">@lang('laravel-cm::crud.save')</button>
</div>

</div>

</div>

</form>

</div>
</div>
</div>

</div>
</div>
</div>
@stop
@stop

0 comments on commit b1c0ce6

Please sign in to comment.