Skip to content

Commit

Permalink
Merge pull request #1 from LightMediaNL/first-revision
Browse files Browse the repository at this point in the history
First revision
  • Loading branch information
LightMediaNL authored Nov 27, 2016
2 parents 9e0d5b9 + 6a11486 commit 85747f4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Lightmedia\Googleprint\Cache\GooglePrintCache;
use Lightmedia\Googleprint\Exceptions\GooglePrintException;

class QueryBuilder {
class ConnectionBuilder {

protected $accessToken;
protected $values;
Expand Down Expand Up @@ -75,6 +75,15 @@ public function submit(array $array) {
return $result;
}

public function printer(array $array) {

$this->values = $array;

$result = $this->request(self::BASE_URL . '/printer');

return $result;
}

protected function removeEmptyValues() {

foreach($this->values as $key => $value) {
Expand Down Expand Up @@ -115,7 +124,7 @@ protected function request($url) {

if(true !== $response['success']){

throw new GooglePrintException('Error in Google API request: ' . $response['message']);
throw new GooglePrintException('Error in Google API request: ' . $response['message'] . ' in ' . $url);
}

return $response;
Expand Down
30 changes: 25 additions & 5 deletions src/Builders/PrinterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function all() {

public function get() {

$search = new QueryBuilder($this->accessToken);
$search = new ConnectionBuilder($this->accessToken);
$response = $search->search($this->values);


Expand All @@ -134,20 +134,40 @@ protected function arrayToHash(array $array) {

protected function buildObjects(Array $array) {

$return = [];
$return = [ ];

$hide = config('print.printers.hide') ?: [];
$hide = config('print.printers.hide') ?: [ ];

foreach($array as $item) {

if(false === in_array($item['id'], $hide)){
if(false === in_array($item['id'], $hide)) {

$object = new Printer($this->accessToken, $item['id']);
$object = new Printer($item['id']);
$return[] = $object->assign($item);
}

}

return collect($return);
}

public function find($id) {

$params = [
'printerid' => $id,
'extra_fields' => 'connectionStatus,semanticState,uiState',
];

$search = new ConnectionBuilder;
$response = $search->printer($params);

if(count($response['printers']) !== 1){
throw new GooglePrintException('Unable to find printer');
}

$object = new Printer;
$object->assign($response['printers'][0]);

return $object;
}
}
3 changes: 0 additions & 3 deletions src/Cache/GooglePrintCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Lightmedia\Googleprint\Cache;

use Cache;
use Lightmedia\Googleprint\Builders\QueryBuilder;

class GooglePrintCache extends Cache {

Expand All @@ -20,8 +19,6 @@ public static function __callStatic($name, $arguments) {

protected static function cache() {

$request = new QueryBuilder;

return Cache::store(config('print.cache.driver'));
}
}
14 changes: 14 additions & 0 deletions src/Facades/GooglePrint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Lightmedia\Googleprint\Facades;

use Illuminate\Support\Facades\Facade;

class GooglePrint extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'Googleprint'; }
}
11 changes: 11 additions & 0 deletions src/Googleprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
namespace Lightmedia\Googleprint;

use Lightmedia\Googleprint\Builders\PrinterBuilder;
use Lightmedia\Googleprint\Models\PrintJob;

class Googleprint {

public static function printer() {

return new PrinterBuilder();
}

public static function defaultPrinter() {

return (new PrinterBuilder)->find(config('print.printers.default'));
}

public static function newPrintJob() {

return new PrintJob;
}
}
2 changes: 1 addition & 1 deletion src/GoogleprintServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public function boot()
*/
public function register()
{
//
$this->app->bind('Googleprint', 'LightMedia\Googleprint\Googleprint' );
}
}
10 changes: 6 additions & 4 deletions src/Models/PrintJob.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace Lightmedianl\Googleprint\Models;
namespace Lightmedia\Googleprint\Models;

use View;
use Lightmedianl\Googleprint\Builders\QueryBuilder;
use Lightmedianl\Googleprint\Exceptions\GooglePrintException;
use Lightmedia\Googleprint\Builders\ConnectionBuilder;
use Lightmedia\Googleprint\Exceptions\GooglePrintException;

class PrintJob {

Expand Down Expand Up @@ -31,7 +31,7 @@ public function save() {
'contentType' => $this->getContentType(),
];

$request = new QueryBuilder();
$request = new ConnectionBuilder;
$response = $request->submit($params);

$this->assign($response['job']);
Expand Down Expand Up @@ -104,6 +104,8 @@ protected function getTicket() {
public function printer(Printer &$printer) {

$this->printer = &$printer;

return $this;
}

public function view($view, $variables = [ ]) {
Expand Down
14 changes: 4 additions & 10 deletions src/Models/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Lightmedia\Googleprint\Models;

use Lightmedia\Googleprint\Exceptions\GooglePrintException;
use Lightmedia\Googleprint\Models\PrintJob;

class Printer extends BaseObject{

Expand All @@ -22,12 +23,11 @@ protected function getFullObject() {

}

public function submit() {
public function submit(PrintJob $job) {

$this->canPrint();



return $job->printer($this)->save();
}

protected function getStatusAttribute() {
Expand Down Expand Up @@ -74,13 +74,7 @@ protected function getNameAttribute() {
return null;
}
}

protected function getIdAttribute() {

return strtolower($this->id);
}



protected function canPrint() {

if(true === $this->values['isTosAccepted']) {
Expand Down

0 comments on commit 85747f4

Please sign in to comment.