Skip to content

Commit bc82370

Browse files
authored
Merge pull request #16 from nstack-io/develop
Develop -> Master
2 parents 550dabd + 0082c9a commit bc82370

16 files changed

+737
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ $nstack = new \NStack\NStack($config);
4343
[x] Content Localize proposals
4444
[x] Content Files
4545
[x] Content Collections
46-
[ ] Notify updates
47-
[ ] UGC pushlogs
48-
[ ] Validators
46+
[x] Notify version control updates
47+
[x] UGC pushlogs
48+
[x] Validators
4949

5050
## 🏆 Credits
5151

src/Clients/NotifyClient.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace NStack\Clients;
4+
5+
use NStack\Exceptions\FailedToParseException;
6+
use NStack\Models\SeenUpdate;
7+
use NStack\Models\VersionControlUpdate;
8+
9+
/**
10+
* Class NotifyClient
11+
*
12+
* @package NStack\Clients
13+
* @author Tiago Araujo <tiar@nodesagency.com>
14+
*/
15+
class NotifyClient extends NStackClient
16+
{
17+
/** @var string */
18+
protected $path = 'notify/updates';
19+
20+
/**
21+
* versionControlIndex
22+
*
23+
* @param String $platform
24+
* @param String|null $currentVersion
25+
* @param String|null $lastVersion
26+
* @param String|null $test
27+
* @return VersionControlUpdate
28+
* @throws FailedToParseException
29+
* @author Tiago Araujo <tiar@nodesagency.com>
30+
*/
31+
public function versionControlIndex(
32+
String $platform,
33+
String $currentVersion = null,
34+
String $lastVersion = null,
35+
String $test = null
36+
): VersionControlUpdate
37+
{
38+
$path = $this->buildPath($this->path) . "?platform=" . $platform;
39+
if ($currentVersion) {
40+
$path = $path . '&current_version=' . $currentVersion;
41+
}
42+
if ($lastVersion) {
43+
$path = $path . '&last_version=' . $lastVersion;
44+
}
45+
if ($test) {
46+
$path = $path . '&test=' . $test;
47+
}
48+
49+
$response = $this->client->get($path);
50+
$contents = $response->getBody()->getContents();
51+
$data = json_decode($contents, true);
52+
return new VersionControlUpdate($data);
53+
}
54+
55+
/**
56+
* markUpdateAsSeen
57+
*
58+
* @param String $guid
59+
* @param int $updateId
60+
* @param String $answer
61+
* @param String $type
62+
* @return SeenUpdate
63+
* @throws FailedToParseException
64+
*/
65+
public function markUpdateAsSeen(String $guid, int $updateId, String $answer, String $type)
66+
{
67+
$response = $this->client->post($this->buildPath($this->path), [
68+
'form_params' => [
69+
'guid' => $guid,
70+
'update_id' => $updateId,
71+
'answer' => $answer,
72+
'type' => $type,
73+
]
74+
]);
75+
$contents = $response->getBody()->getContents();
76+
$data = json_decode($contents, true);
77+
return new SeenUpdate($data['data']);
78+
}
79+
80+
}

src/Clients/UgcClient.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace NStack\Clients;
4+
5+
use NStack\Exceptions\FailedToParseException;
6+
use NStack\Models\File;
7+
use NStack\Models\IpAddress;
8+
use NStack\Models\Proposal;
9+
use NStack\Models\ProposalDeleted;
10+
11+
/**
12+
* Class UgcClient
13+
*
14+
* @package NStack\Clients
15+
* @author Tiago Araujo <tiar@nodesagency.com>
16+
*/
17+
class UgcClient extends NStackClient
18+
{
19+
/** @var string */
20+
protected $path = 'ugc';
21+
22+
/**
23+
* storePushLog
24+
*
25+
* @param String $provider
26+
* @param String $key
27+
* @param String $type
28+
* @param bool $succeeded
29+
* @param String|null $request
30+
* @param String|null $response
31+
* @param int|null $userId
32+
* @param String|null $relationType
33+
* @param int|null $relationId
34+
*/
35+
public function storePushLog(
36+
String $provider,
37+
String $key,
38+
String $type,
39+
bool $succeeded,
40+
String $request = null,
41+
String $response = null,
42+
int $userId = null,
43+
String $relationType = null,
44+
int $relationId = null
45+
)
46+
{
47+
$this->client->post($this->buildPath($this->path), [
48+
'body' => '{
49+
"provider": "' . $provider . '",
50+
"key": "' . $key . '",
51+
"type": "' . $type . '",
52+
"succeeded": ' . $succeeded . ',
53+
"request": { ' . $request . ', },
54+
"response": { ' . $response . ', },
55+
"user_id": ' . $userId . '
56+
"relation_type": "' . $relationType . '",
57+
"relation_id": ' . $relationId . '
58+
}'
59+
]);
60+
}
61+
62+
}

src/Clients/ValidatorsClient.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace NStack\Clients;
4+
5+
use NStack\Exceptions\FailedToParseException;
6+
use NStack\Models\EmailValidation;
7+
use NStack\Models\IpAddress;
8+
use NStack\Models\PhoneValidation;
9+
10+
/**
11+
* Class ValidatorsClient
12+
*
13+
* @package NStack\Clients
14+
* @author Tiago Araujo <tiar@nodesagency.com>
15+
*/
16+
class ValidatorsClient extends NStackClient
17+
{
18+
/** @var string */
19+
protected $path = 'validator';
20+
21+
/**
22+
* email
23+
*
24+
* @param String $email
25+
* @return EmailValidation
26+
* @throws FailedToParseException
27+
* @author Tiago Araujo <tiar@nodesagency.com>
28+
*/
29+
public function email(String $email): EmailValidation
30+
{
31+
$response = $this->client->get($this->buildPath($this->path . '/email?email=' . $email));
32+
$contents = $response->getBody()->getContents();
33+
$data = json_decode($contents, true);
34+
return new EmailValidation($data);
35+
}
36+
37+
/**
38+
* phone
39+
*
40+
* @param String $phone
41+
* @param String|null $fallbackCountryCode
42+
* @param Boolean|null $validateWithTwilio
43+
* @param String|null $twilioType
44+
* @return PhoneValidation
45+
* @throws FailedToParseException
46+
* @author Tiago Araujo <tiar@nodesagency.com>
47+
*/
48+
public function phone(
49+
String $phone,
50+
String $fallbackCountryCode = null,
51+
bool $validateWithTwilio = null,
52+
String $twilioType = null
53+
): PhoneValidation
54+
{
55+
$path = $this->buildPath($this->path . '/phone?phone=' . $phone);
56+
57+
if ($fallbackCountryCode) {
58+
$path = $path . '&fallback_country_code=' . $fallbackCountryCode;
59+
}
60+
if ($validateWithTwilio) {
61+
$path = $path . '&twilio=' . $validateWithTwilio;
62+
}
63+
if ($twilioType) {
64+
$path = $path . '&twilio_type=' . $twilioType;
65+
}
66+
67+
$response = $this->client->get($path);
68+
$contents = $response->getBody()->getContents();
69+
$data = json_decode($contents, true);
70+
return new PhoneValidation($data);
71+
}
72+
}

src/Models/EmailValidation.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace NStack\Models;
4+
5+
/**
6+
* Class EmailValidation
7+
*
8+
* @package NStack\Models
9+
* @author Tiago Araujo <tiar@nodesagency.com>
10+
*/
11+
class EmailValidation extends Model
12+
{
13+
/** @var boolean */
14+
protected $ok;
15+
16+
/**
17+
* parse
18+
*
19+
* @param array $data
20+
* @author Tiago Araujo <tiar@nodesagency.com>
21+
*/
22+
public function parse(array $data)
23+
{
24+
$this->ok = (int)$data['ok'];
25+
}
26+
27+
/**
28+
* toArray
29+
*
30+
* @return array
31+
* @author Tiago Araujo <tiar@nodesagency.com>
32+
*/
33+
public function toArray(): array
34+
{
35+
return ['ok' => $this->ok];
36+
}
37+
38+
/**
39+
* @return bool
40+
*/
41+
public function isOk(): bool
42+
{
43+
return $this->ok;
44+
}
45+
46+
}

src/Models/PhoneValidation.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace NStack\Models;
4+
5+
/**
6+
* Class PhoneValidation
7+
*
8+
* @package NStack\Models
9+
* @author Tiago Araujo <tiar@nodesagency.com>
10+
*/
11+
class PhoneValidation extends Model
12+
{
13+
/** @var boolean */
14+
protected $ok;
15+
16+
/** @var String */
17+
protected $countryCode;
18+
19+
/** @var String */
20+
protected $nationalNumber;
21+
22+
/**
23+
* parse
24+
*
25+
* @param array $data
26+
* @author Tiago Araujo <tiar@nodesagency.com>
27+
*/
28+
public function parse(array $data)
29+
{
30+
$this->ok = (String)$data['ok'];
31+
$this->countryCode = (String)$data['country_code'];
32+
$this->nationalNumber = (String)$data['national_number'];
33+
}
34+
35+
/**
36+
* toArray
37+
*
38+
* @return array
39+
* @author Tiago Araujo <tiar@nodesagency.com>
40+
*/
41+
public function toArray(): array
42+
{
43+
return [
44+
'ok' => $this->ok,
45+
'country_code' => $this->countryCode,
46+
'national_number' => $this->nationalNumber,
47+
];
48+
}
49+
50+
/**
51+
* @return bool
52+
*/
53+
public function isOk(): bool
54+
{
55+
return $this->ok;
56+
}
57+
58+
/**
59+
* @return String
60+
*/
61+
public function getCountryCode(): String
62+
{
63+
return $this->countryCode;
64+
}
65+
66+
/**
67+
* @return String
68+
*/
69+
public function getNationalNumber(): String
70+
{
71+
return $this->nationalNumber;
72+
}
73+
74+
}

0 commit comments

Comments
 (0)