-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix composer.json
- Loading branch information
0 parents
commit 227bfd7
Showing
11 changed files
with
323 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,7 @@ | ||
# Changelog | ||
|
||
All notable changes to `placid-php` will be documented in this file | ||
|
||
## 1.0.0 - 201X-XX-XX | ||
|
||
- initial release |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Armin Ulrich <armin@nifty.at> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,3 @@ | ||
|
||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
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,31 @@ | ||
{ | ||
"name": "placidapp/placid-php", | ||
"description": "PHP Wrapper around the Placid.app REST API", | ||
"keywords": [ | ||
"placid-php" | ||
], | ||
"homepage": "https://github.com/placidapp/placid-php", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Armin Ulrich", | ||
"email": "armin@nifty.at", | ||
"homepage": "https://placid.app", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1" | ||
}, | ||
"require-dev": { | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Placid\\PHP\\": "src" | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
|
||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Placid\Element; | ||
|
||
class Browserframe extends Element | ||
{ | ||
protected $payload = [ | ||
'url' => null, // - text field | ||
'image' => null // - image field | ||
]; | ||
|
||
public function url($text) | ||
{ | ||
$this->payload['url'] = $this->generateTextPayload($text); | ||
return $this; | ||
} | ||
|
||
public function imageFromWebsite($website_url) | ||
{ | ||
$this->payload['image'] = $this->generateImagePayload( | ||
"website", | ||
$website_url | ||
); | ||
return $this; | ||
} | ||
|
||
public function imageFromUrl($website_url) | ||
{ | ||
$this->payload['image'] = $this->generateImagePayload( | ||
"link", | ||
$website_url | ||
); | ||
return $this; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Placid\Element; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
abstract class Element implements Arrayable | ||
{ | ||
protected $payload; | ||
|
||
public function toArray() | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
protected function generateTextPayload($text) | ||
{ | ||
return $text; | ||
} | ||
|
||
protected function generateColorPayload($hex) | ||
{ | ||
return [ | ||
'hex' => $hex | ||
]; | ||
} | ||
|
||
protected function generateImagePayload($type, $website_url) | ||
{ | ||
return [ | ||
'imageSrc' => $type, | ||
'imageUrl' => $website_url | ||
]; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Placid\Element; | ||
|
||
class Picture extends Element | ||
{ | ||
protected $payload = [ | ||
'image' => null | ||
]; | ||
|
||
public function imageFromWebsite($website_url) | ||
{ | ||
$this->payload['image'] = $this->generateImagePayload( | ||
"website", | ||
$website_url | ||
); | ||
return $this; | ||
} | ||
|
||
public function imageFromUrl($website_url) | ||
{ | ||
$this->payload['image'] = $this->generateImagePayload( | ||
"link", | ||
$website_url | ||
); | ||
return $this; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Placid\Element; | ||
|
||
class Rectangle extends Element | ||
{ | ||
protected $payload = [ | ||
'backgroundColor' => null | ||
]; | ||
|
||
public function backgroundColor($hexcode) | ||
{ | ||
$this->payload['backgroundColor'] = $this->generateColorPayload( | ||
$hexcode | ||
); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Placid\Element; | ||
|
||
class Text extends Element | ||
{ | ||
protected $payload = [ | ||
'text' => null, | ||
'color' => null | ||
]; | ||
|
||
public function text($text) | ||
{ | ||
$this->payload['text'] = $this->generateTextPayload($text); | ||
return $this; | ||
} | ||
|
||
public function color($hexcode) | ||
{ | ||
$this->payload['color'] = $this->generateColorPayload($hexcode); | ||
return $this; | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Placid; | ||
|
||
class GeneratedImage | ||
{ | ||
private $imageUrl; | ||
private $id; | ||
private $status; | ||
|
||
public function __construct($id, $imageUrl, $status) | ||
{ | ||
$this->id = $id; | ||
$this->imageUrl = $imageUrl; | ||
$this->status = $status; | ||
} | ||
|
||
public function getImageUrl() | ||
{ | ||
return $this->imageUrl; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getStatus() | ||
{ | ||
return $this->status; | ||
} | ||
} |
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,91 @@ | ||
<?php | ||
|
||
namespace Placid; | ||
|
||
use Exception; | ||
use Placid\Element\Browserframe; | ||
use Placid\Element\Picture; | ||
use Placid\Element\Rectangle; | ||
use Placid\Element\Text; | ||
|
||
class Template | ||
{ | ||
private $apiKey; | ||
private $successWebhook = null; | ||
private $uuid; | ||
private $fields = []; | ||
private $apiUrl = "http://placid.test/api/rest"; | ||
|
||
public function __construct($uuid, $apiKey = null) | ||
{ | ||
$this->uuid = $uuid; | ||
$this->fields = collect(); | ||
$this->apiKey = $apiKey; | ||
} | ||
|
||
public function successWebhook($webhook_url) | ||
{ | ||
$this->successWebhook = $webhook_url; | ||
} | ||
|
||
public function elementPicture($string): Picture | ||
{ | ||
return $this->fields[$string] = new Picture($string); | ||
} | ||
|
||
public function elementText($string): Text | ||
{ | ||
return $this->fields[$string] = new Text($string); | ||
} | ||
|
||
public function elementRectangle($string): Rectangle | ||
{ | ||
return $this->fields[$string] = new Rectangle($string); | ||
} | ||
|
||
public function elementBrowserframe($string): Browserframe | ||
{ | ||
return $this->fields[$string] = new Browserframe($string); | ||
} | ||
|
||
public function getImage(): GeneratedImage | ||
{ | ||
$payload = [ | ||
'webhook_success' => $this->successWebhook, | ||
'fields' => $this->fields->toArray() | ||
]; | ||
|
||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL, $this->getRequestUrl($this->uuid)); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); | ||
|
||
$headers = array(); | ||
$headers[] = 'User-Agent: placidapp/placid-phpV0.1'; | ||
$headers[] = 'Authorization: Bearer ' . $this->apiKey; | ||
$headers[] = 'Content-Type: application/json'; | ||
$headers[] = 'Accept: application/json'; | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
|
||
$result = curl_exec($ch); | ||
if (curl_errno($ch)) { | ||
throw new Exception(curl_error($ch)); | ||
} | ||
curl_close($ch); | ||
|
||
$json = json_decode($result, true); | ||
|
||
return new GeneratedImage( | ||
$json['id'], | ||
$json['image_url'], | ||
$json['status'] | ||
); | ||
} | ||
|
||
private function getRequestUrl($uuid) | ||
{ | ||
return "{$this->apiUrl}/{$uuid}"; | ||
} | ||
} |