Skip to content

Commit

Permalink
0.0.3 12 services
Browse files Browse the repository at this point in the history
  • Loading branch information
cyingfan committed Jun 28, 2021
1 parent 7a61d21 commit b1e24b7
Show file tree
Hide file tree
Showing 13 changed files with 653 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ M3O Client for PHP
use M3O\Factory;

$m3o = (new Factory())->getM3O();
$m3o->getCryptoService()->news('BTC');
echo $m3o->getHelloworldService()->call('John Doe'), "\n";
```

## Service completion status
Expand All @@ -33,9 +33,9 @@ $m3o->getCryptoService()->news('BTC');
- [X] [forex](https://m3o.com/forex)
- [X] [geocoding](https://m3o.com/geocoding)
- [X] [helloword](https://m3o.com/helloword)
- [ ] [id](https://m3o.com/id)
- [ ] [image](https://m3o.com/image)
- [ ] [ip](https://m3o.com/ip)
- [X] [id](https://m3o.com/id)
- [X] [image](https://m3o.com/image)
- [X] [ip](https://m3o.com/ip)
- [ ] [location](https://m3o.com/location)
- [ ] [otp](https://m3o.com/otp)
- [ ] [routing](https://m3o.com/routing)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yingfan/m3o-php",
"description": "M3O client for PHP",
"version": "0.0.2",
"version": "0.0.3",
"type": "library",
"license": "MIT",
"keywords": ["M3O", "API"],
Expand Down
29 changes: 29 additions & 0 deletions src/M3O.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use M3O\Service\Forex as ForexService;
use M3O\Service\Geocoding as GeocodingService;
use M3O\Service\Helloworld as HelloworldService;
use M3O\Service\Id as IdService;
use M3O\Service\Image as ImageService;
use M3O\Service\Ip as IpService;
use M3O\Util\PhoneValidator;

class M3O
Expand All @@ -29,6 +32,9 @@ class M3O
private ?ForexService $forexService;
private ?GeocodingService $geocodingService;
private ?HelloworldService $helloworldService;
private ?IdService $idService;
private ?ImageService $imageService;
private ?IpService $ipService;

public function __construct(ClientInterface $client, PhoneValidator $phoneValidator)
{
Expand Down Expand Up @@ -109,5 +115,28 @@ public function getHelloworldService(): HelloworldService
return $this->helloworldService;
}

public function getIdService(): IdService
{
if ($this->idService === null) {
$this->idService = new IdService($this->client);
}
return $this->idService;
}

public function getImageService(): ImageService
{
if ($this->imageService === null) {
$this->imageService = new ImageService($this->client);
}
return $this->imageService;
}

public function getIpService(): IpService
{
if ($this->ipService === null) {
$this->ipService = new IpService($this->client);
}
return $this->ipService;
}

}
50 changes: 50 additions & 0 deletions src/Model/Id/GenerateOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace M3O\Model\Id;


use M3O\Model\AbstractModel;

class GenerateOutput extends AbstractModel
{
private string $id;
private string $type;

public function getId(): string
{
return $this->id;
}

public function setId(string $id): GenerateOutput
{
$this->id = $id;
return $this;
}

public function getType(): string
{
return $this->type;
}

public function setType(string $type): GenerateOutput
{
$this->type = $type;
return $this;
}

public static function fromArray(array $array): GenerateOutput
{
return (new GenerateOutput())
->setId((string) ($array['id'] ?? ''))
->setType((string) ($array['type'] ?? ''));
}

public function toArray(): array
{
return [
'id' => $this->getId(),
'type' => $this->getType()
];
}
}
41 changes: 41 additions & 0 deletions src/Model/Image/ConvertInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

namespace M3O\Model\Image;


use M3O\Model\AbstractModel;

class ConvertInput extends UploadInput
{
private bool $outputURL;

public function getOutputURL(): bool
{
return $this->outputURL;
}

/**
* @param bool $outputURL
* @return static
*/
public function setOutputURL(bool $outputURL)
{
$this->outputURL = $outputURL;
return $this;
}

public static function fromArray(array $array): ConvertInput
{
return (new ConvertInput())
->setBase64((string) ($array['base64'] ?? ''))
->setName((string) ($array['name'] ?? ''))
->setOutputURL((bool) ($array['outputURL'] ?? false))
->setUrl((string) ($array['url'] ?? ''));
}

public function toArray(): array
{
return parent::toArray() + ['outputURL' => $this->getOutputURL()];
}
}
90 changes: 90 additions & 0 deletions src/Model/Image/CropOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);

namespace M3O\Model\Image;


use InvalidArgumentException;
use M3O\Model\AbstractModel;

class CropOptions extends AbstractModel
{
public const ANCHOR_TOP = 'top';
public const ANCHOR_TOP_LEFT = 'top left';
public const ANCHOR_TOP_RIGHT = 'top right';
public const ANCHOR_LEFT = 'left';
public const ANCHOR_CENTER = 'center';
public const ANCHOR_RIGHT = 'right';
public const ANCHOR_BOTTOM_LEFT = 'bottom left';
public const ANCHOR_BOTTOM = 'bottom';
public const ANCHOR_BOTTOM_RIGHT = 'bottom right';
public const ANCHORS = [
self::ANCHOR_LEFT,
self::ANCHOR_TOP_LEFT,
self::ANCHOR_TOP_RIGHT,
self::ANCHOR_LEFT,
self::ANCHOR_CENTER,
self::ANCHOR_RIGHT,
self::ANCHOR_BOTTOM_LEFT,
self::ANCHOR_BOTTOM,
self::ANCHOR_BOTTOM_RIGHT
];

private string $anchor;
private int $width;
private int $height;

public function getWidth(): int
{
return $this->width;
}

public function setWidth(int $width): CropOptions
{
$this->width = $width;
return $this;
}

public function getHeight(): int
{
return $this->height;
}

public function setHeight(int $height): CropOptions
{
$this->height = $height;
return $this;
}

public function getAnchor(): string
{
return $this->anchor;
}

public function setAnchor(string $anchor): CropOptions
{
if (!in_array(strtolower(trim($anchor)), self::ANCHORS, true)) {
throw new InvalidArgumentException('Invalid anchor');
}
$this->anchor = $anchor;
return $this;
}

public static function fromArray(array $array): CropOptions
{
return (new CropOptions())
->setAnchor((string) ($array['anchor'] ?? self::ANCHOR_CENTER))
->setWidth((int) ($array['width'] ?? 0))
->setHeight((int) ($array['height'] ?? 0));
}

public function toArray(): array
{
return [
'anchor' => $this->getAnchor(),
'width' => $this->getWidth(),
'height' => $this->getHeight()
];
}

}
50 changes: 50 additions & 0 deletions src/Model/Image/Output.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace M3O\Model\Image;


use M3O\Model\AbstractModel;

class Output extends AbstractModel
{
private string $base64;
private string $url;

public function getBase64(): string
{
return $this->base64;
}

public function setBase64(string $base64): Output
{
$this->base64 = $base64;
return $this;
}

public function getUrl(): string
{
return $this->url;
}

public function setUrl(string $url): Output
{
$this->url = $url;
return $this;
}

public static function fromArray(array $array): Output
{
return (new Output())
->setBase64((string) ($array['base64'] ?? ''))
->setUrl((string) ($array['url'] ?? ''));
}

public function toArray(): array
{
return [
'base64' => $this->getBase64(),
'url' => $this->getUrl()
];
}
}
68 changes: 68 additions & 0 deletions src/Model/Image/ResizeInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);

namespace M3O\Model\Image;


use M3O\Model\AbstractModel;

class ResizeInput extends ConvertInput
{
private CropOptions $cropOptions;
private int $height;
private int $width;

public function getCropOptions(): CropOptions
{
return $this->cropOptions;
}

public function setCropOptions(CropOptions $cropOptions): ResizeInput
{
$this->cropOptions = $cropOptions;
return $this;
}

public function getHeight(): int
{
return $this->height;
}

public function setHeight(int $height): ResizeInput
{
$this->height = $height;
return $this;
}

public function getWidth(): int
{
return $this->width;
}

public function setWidth(int $width): ResizeInput
{
$this->width = $width;
return $this;
}

public static function fromArray(array $array): ResizeInput
{
return (new ResizeInput())
->setBase64((string)($array['base64'] ?? ''))
->setName((string)($array['name'] ?? ''))
->setOutputURL((bool)($array['outputURL'] ?? false))
->setUrl((string)($array['url'] ?? ''))
->setCropOptions($array['cropOptions'] ?? null)
->setHeight((int)($array['height'] ?? 0))
->setWidth((int)($array['width'] ?? 0));
}

public function toArray(): array
{
return parent::toArray() + [
'cropOptions' => $this->getCropOptions(),
'height' => $this->getHeight(),
'width' => $this->getWidth()
];
}
}
Loading

0 comments on commit b1e24b7

Please sign in to comment.