Skip to content

Commit f8c60f6

Browse files
authored
Merge pull request #2 from taur/api-gateway-upgrade
Api gateway upgrade
2 parents 9ced92b + bd50696 commit f8c60f6

File tree

6 files changed

+498
-32
lines changed

6 files changed

+498
-32
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
}
1515
],
1616
"require": {
17-
"guzzlehttp/guzzle": "^6.0"
17+
"guzzlehttp/guzzle": "3.8 - 6.5"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "4.0.*"
20+
"phpunit/phpunit": "4.8 - 5"
2121
},
2222
"autoload": {
2323
"psr-4": {

src/Minutemailer/ContactLists.php

+139-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,149 @@
44

55
class ContactLists extends RestAPI
66
{
7-
public $endpoint = 'contactlists';
7+
public $endpoint = 'contact-lists';
88

9-
public function subscribe($data)
9+
/**
10+
* @deprecated
11+
* @param mixed $data default null
12+
* @return ContactLists $this
13+
*/
14+
public function subscribe($data = null)
1015
{
11-
$this->segment = 'subscribe';
16+
$this->deprecated(__METHOD__, 'Contacts->create');
17+
18+
return $this;
19+
}
20+
21+
/**
22+
* @param int $limit default 10
23+
* @param int $page default 1
24+
* @param int $with_contacts_count 0|1 default 1
25+
* @param string $query
26+
* @param string[] $include_lists default []
27+
* @return mixed
28+
*/
29+
public function getContactlists($limit = 10, $page = 1, $with_contacts_count = 1, $query = '', array $include_lists = array())
30+
{
31+
$data = array(
32+
'limit' => $limit,
33+
'page' => $page,
34+
'with_contacts_count' => $with_contacts_count,
35+
);
36+
if ($query != null) $data['query'] = $query;
37+
if (count($include_lists)) $data['include_lists'] = implode(',', $include_lists);
38+
$response = $this->get($data);
39+
40+
return $response;
41+
}
42+
43+
/**
44+
* @return mixed
45+
*/
46+
public function show()
47+
{
48+
$response = $this->get();
49+
50+
return $response;
51+
}
52+
53+
/**
54+
* @param string[] $contact_lists
55+
* @return mixed
56+
*/
57+
public function batchDelete($contact_lists)
58+
{
59+
$data = array(
60+
'contact_lists' => $contact_lists,
61+
);
62+
$this->segment = 'batch';
63+
$response = $this->delete($data);
64+
65+
return $response;
66+
}
67+
68+
/**
69+
* @param string $name
70+
* @param array $metadata
71+
* @return mixed
72+
*/
73+
public function create($name, array $metadata = array())
74+
{
75+
$data = array(
76+
'name' => $name,
77+
'metadata' => $metadata,
78+
);
1279
$response = $this->post($data);
1380

1481
return $response;
1582
}
83+
84+
/**
85+
* @param mixed $data
86+
*/
87+
public function update($data)
88+
{
89+
$response = $this->put($data);
90+
91+
return $response;
92+
}
93+
94+
/**
95+
* @param string $contact_uuid
96+
* @return mixed
97+
*/
98+
public function addContact($contact_uuid)
99+
{
100+
$this->segment = 'add-contact/' . $contact_uuid;
101+
$response = $this->put();
102+
103+
return $response;
104+
}
105+
106+
/**
107+
* @param string $contact_uuid
108+
* @param mixed $data
109+
* @return mixed
110+
*/
111+
public function updateContact($contact_uuid, $data)
112+
{
113+
$this->segment = 'contacts/' . $contact_uuid;
114+
$response = $this->put($data);
115+
116+
return $response;
117+
}
118+
119+
/**
120+
* @param string $contact_uuid
121+
* @return mixed
122+
*/
123+
public function removeContact($contact_uuid)
124+
{
125+
$this->segment = 'remove-contact/' . $contact_uuid;
126+
$response = $this->put();
127+
128+
return $response;
129+
}
130+
131+
/**
132+
* @param string[] $contacts contact UUID<string>
133+
*/
134+
public function batchAddContact($contacts)
135+
{
136+
$this->segment = 'batch-add-contacts';
137+
$response = $this->put(array('contacts' => $contacts));
138+
139+
return $response;
140+
}
141+
142+
/**
143+
* @param string[] $contacts contact UUID<string>
144+
*/
145+
public function batchRemoveContact($contacts)
146+
{
147+
$this->segment = 'batch-remove-contacts';
148+
$response = $this->put(array('contacts' => $contacts));
149+
150+
return $response;
151+
}
16152
}

src/Minutemailer/Contacts.php

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
3+
namespace Minutemailer;
4+
5+
class Contacts extends RestAPI
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $endpoint = 'contacts';
11+
12+
/**
13+
* @param int $limit default 10
14+
* @param int $page default 1
15+
* @param \DateTimeInterface|null $since default null
16+
* @param string[] $fields default []
17+
* @return mixed
18+
*/
19+
public function get($limit = 10, $page = 1, $since = null, array $fields = array())
20+
{
21+
$data = array(
22+
'limit' => $limit,
23+
'page' => $page,
24+
);
25+
if ($since instanceof \DateTimeInterface) $data['since'] = $since->format('Y-m-d');
26+
if (count($fields) > 0) $data['fields'] = implode(',', $fields);
27+
$response = parent::get($data);
28+
29+
return $response;
30+
}
31+
32+
/**
33+
* @param string[] $contactIds UUID<string>
34+
* @param string[] $fields
35+
*/
36+
public function batchShow(array $contactIds, array $fields)
37+
{
38+
$data = array(
39+
'contacts' => $contactIds,
40+
'fields' => $fields,
41+
);
42+
$this->id = 'batch-show';
43+
$response = $this->getWithBody($data);
44+
45+
return $response;
46+
}
47+
48+
/**
49+
* @param string[] $contactIds UUID<string>
50+
* @return mixed
51+
*/
52+
public function batchDelete(array $contactIds)
53+
{
54+
$data = array(
55+
'contacts' => $contactIds,
56+
);
57+
$this->id = 'batch';
58+
$this->delete($data);
59+
}
60+
61+
/**
62+
* @param string[] $contactIds UUID<string>
63+
* @param string $origin UUID
64+
* @param string $destination UUID
65+
* @return mixed
66+
*/
67+
public function batchMove(array $contactIds, $origin, $destination)
68+
{
69+
$data = array(
70+
'contacts' => $contactIds,
71+
'origin' => $origin,
72+
'destination' => $destination,
73+
);
74+
$this->id = 'batch-move';
75+
$response = $this->put($data);
76+
77+
return $response;
78+
}
79+
80+
/**
81+
* @param string $email
82+
* @param array $fields
83+
* @param string[] $contactListIds UUID<string>
84+
* @return mixed
85+
*/
86+
public function create($email, array $fields, $contactListIds)
87+
{
88+
$data = array(
89+
'email' => $email,
90+
'status' => 1,
91+
'contact_lists' => $contactListIds,
92+
);
93+
// Elevate top-level fields
94+
if (isset($fields['email'])) unset($fields['email']);
95+
if (isset($fields['status'])) unset($fields['status']);
96+
if (isset($fields['contact_lists'])) unset($fields['contact_lists']);
97+
foreach (['first_name', 'last_name', 'phone', 'address', 'postal_code', 'city', 'note'] as $key) {
98+
if (!empty($fields[$key])) {
99+
$data[$key] = $fields[$key];
100+
unset($fields[$key]);
101+
}
102+
}
103+
if (count($fields) > 0) {
104+
$data['fields'] = $fields;
105+
}
106+
107+
$response = $this->post($data);
108+
return $response;
109+
110+
}
111+
112+
/**
113+
* @param array $fields
114+
* @return mixed
115+
*/
116+
public function update(array $fields)
117+
{
118+
$data = array();
119+
// Elevate top-level fields
120+
foreach (['email', 'first_name', 'last_name', 'phone', 'address', 'postal_code', 'city', 'note', 'status'] as $key) {
121+
if (!empty($fields[$key])) {
122+
$data[$key] = $fields[$key];
123+
unset($fields[$key]);
124+
}
125+
}
126+
$data['fields'] = $fields;
127+
$response = $this->put($data);
128+
129+
return $response;
130+
}
131+
132+
/**
133+
* @param array $data
134+
* @return mixed
135+
*/
136+
public function unsubscribe()
137+
{
138+
$this->segment = __METHOD__;
139+
$response = $this->put();
140+
141+
return $response;
142+
}
143+
144+
/**
145+
* @return mixed
146+
*/
147+
public function options()
148+
{
149+
$response = $this->get();
150+
151+
return $response;
152+
}
153+
154+
/**
155+
* @return mixed
156+
*/
157+
public function show()
158+
{
159+
$response = $this->get();
160+
161+
return $response;
162+
}
163+
164+
}

0 commit comments

Comments
 (0)