Skip to content

Commit

Permalink
Merge pull request #2 from taur/api-gateway-upgrade
Browse files Browse the repository at this point in the history
Api gateway upgrade
  • Loading branch information
carlos-ea authored Sep 8, 2023
2 parents 9ced92b + bd50696 commit f8c60f6
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 32 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
}
],
"require": {
"guzzlehttp/guzzle": "^6.0"
"guzzlehttp/guzzle": "3.8 - 6.5"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
"phpunit/phpunit": "4.8 - 5"
},
"autoload": {
"psr-4": {
Expand Down
142 changes: 139 additions & 3 deletions src/Minutemailer/ContactLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,149 @@

class ContactLists extends RestAPI
{
public $endpoint = 'contactlists';
public $endpoint = 'contact-lists';

public function subscribe($data)
/**
* @deprecated
* @param mixed $data default null
* @return ContactLists $this
*/
public function subscribe($data = null)
{
$this->segment = 'subscribe';
$this->deprecated(__METHOD__, 'Contacts->create');

return $this;
}

/**
* @param int $limit default 10
* @param int $page default 1
* @param int $with_contacts_count 0|1 default 1
* @param string $query
* @param string[] $include_lists default []
* @return mixed
*/
public function getContactlists($limit = 10, $page = 1, $with_contacts_count = 1, $query = '', array $include_lists = array())
{
$data = array(
'limit' => $limit,
'page' => $page,
'with_contacts_count' => $with_contacts_count,
);
if ($query != null) $data['query'] = $query;
if (count($include_lists)) $data['include_lists'] = implode(',', $include_lists);
$response = $this->get($data);

return $response;
}

/**
* @return mixed
*/
public function show()
{
$response = $this->get();

return $response;
}

/**
* @param string[] $contact_lists
* @return mixed
*/
public function batchDelete($contact_lists)
{
$data = array(
'contact_lists' => $contact_lists,
);
$this->segment = 'batch';
$response = $this->delete($data);

return $response;
}

/**
* @param string $name
* @param array $metadata
* @return mixed
*/
public function create($name, array $metadata = array())
{
$data = array(
'name' => $name,
'metadata' => $metadata,
);
$response = $this->post($data);

return $response;
}

/**
* @param mixed $data
*/
public function update($data)
{
$response = $this->put($data);

return $response;
}

/**
* @param string $contact_uuid
* @return mixed
*/
public function addContact($contact_uuid)
{
$this->segment = 'add-contact/' . $contact_uuid;
$response = $this->put();

return $response;
}

/**
* @param string $contact_uuid
* @param mixed $data
* @return mixed
*/
public function updateContact($contact_uuid, $data)
{
$this->segment = 'contacts/' . $contact_uuid;
$response = $this->put($data);

return $response;
}

/**
* @param string $contact_uuid
* @return mixed
*/
public function removeContact($contact_uuid)
{
$this->segment = 'remove-contact/' . $contact_uuid;
$response = $this->put();

return $response;
}

/**
* @param string[] $contacts contact UUID<string>
*/
public function batchAddContact($contacts)
{
$this->segment = 'batch-add-contacts';
$response = $this->put(array('contacts' => $contacts));

return $response;
}

/**
* @param string[] $contacts contact UUID<string>
*/
public function batchRemoveContact($contacts)
{
$this->segment = 'batch-remove-contacts';
$response = $this->put(array('contacts' => $contacts));

return $response;
}
}
164 changes: 164 additions & 0 deletions src/Minutemailer/Contacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

namespace Minutemailer;

class Contacts extends RestAPI
{
/**
* @var string
*/
public $endpoint = 'contacts';

/**
* @param int $limit default 10
* @param int $page default 1
* @param \DateTimeInterface|null $since default null
* @param string[] $fields default []
* @return mixed
*/
public function get($limit = 10, $page = 1, $since = null, array $fields = array())
{
$data = array(
'limit' => $limit,
'page' => $page,
);
if ($since instanceof \DateTimeInterface) $data['since'] = $since->format('Y-m-d');
if (count($fields) > 0) $data['fields'] = implode(',', $fields);
$response = parent::get($data);

return $response;
}

/**
* @param string[] $contactIds UUID<string>
* @param string[] $fields
*/
public function batchShow(array $contactIds, array $fields)
{
$data = array(
'contacts' => $contactIds,
'fields' => $fields,
);
$this->id = 'batch-show';
$response = $this->getWithBody($data);

return $response;
}

/**
* @param string[] $contactIds UUID<string>
* @return mixed
*/
public function batchDelete(array $contactIds)
{
$data = array(
'contacts' => $contactIds,
);
$this->id = 'batch';
$this->delete($data);
}

/**
* @param string[] $contactIds UUID<string>
* @param string $origin UUID
* @param string $destination UUID
* @return mixed
*/
public function batchMove(array $contactIds, $origin, $destination)
{
$data = array(
'contacts' => $contactIds,
'origin' => $origin,
'destination' => $destination,
);
$this->id = 'batch-move';
$response = $this->put($data);

return $response;
}

/**
* @param string $email
* @param array $fields
* @param string[] $contactListIds UUID<string>
* @return mixed
*/
public function create($email, array $fields, $contactListIds)
{
$data = array(
'email' => $email,
'status' => 1,
'contact_lists' => $contactListIds,
);
// Elevate top-level fields
if (isset($fields['email'])) unset($fields['email']);
if (isset($fields['status'])) unset($fields['status']);
if (isset($fields['contact_lists'])) unset($fields['contact_lists']);
foreach (['first_name', 'last_name', 'phone', 'address', 'postal_code', 'city', 'note'] as $key) {
if (!empty($fields[$key])) {
$data[$key] = $fields[$key];
unset($fields[$key]);
}
}
if (count($fields) > 0) {
$data['fields'] = $fields;
}

$response = $this->post($data);
return $response;

}

/**
* @param array $fields
* @return mixed
*/
public function update(array $fields)
{
$data = array();
// Elevate top-level fields
foreach (['email', 'first_name', 'last_name', 'phone', 'address', 'postal_code', 'city', 'note', 'status'] as $key) {
if (!empty($fields[$key])) {
$data[$key] = $fields[$key];
unset($fields[$key]);
}
}
$data['fields'] = $fields;
$response = $this->put($data);

return $response;
}

/**
* @param array $data
* @return mixed
*/
public function unsubscribe()
{
$this->segment = __METHOD__;
$response = $this->put();

return $response;
}

/**
* @return mixed
*/
public function options()
{
$response = $this->get();

return $response;
}

/**
* @return mixed
*/
public function show()
{
$response = $this->get();

return $response;
}

}
Loading

0 comments on commit f8c60f6

Please sign in to comment.