Skip to content

Commit f29ed5a

Browse files
committed
Merge pull request #114 from intercom/RuairiK/bulk_api_support
Add bulk API support
2 parents c7ef82f + 35fe6d1 commit f29ed5a

File tree

9 files changed

+233
-37
lines changed

9 files changed

+233
-37
lines changed

src/Intercom/Service/config/intercom_public.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"intercom_public_admin.json",
1515
"intercom_public_user.json",
1616
"intercom_public_contact.json",
17+
"intercom_public_job.json",
1718
"intercom_public_abstract_operations.json"
1819
]
1920
}

src/Intercom/Service/config/intercom_public_event.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@
4040
},
4141
"summary": "Records an event",
4242
"uri": "/events"
43+
},
44+
"bulkEvents": {
45+
"httpMethod": "POST",
46+
"parameters": {
47+
"items": {
48+
"location": "json",
49+
"required": true,
50+
"type": "array"
51+
},
52+
"job": {
53+
"location": "json",
54+
"required": false,
55+
"type": "object"
56+
}
57+
},
58+
"responseClass": "JobModel",
59+
"responseType": "model",
60+
"summary": "Creates or updates events in bulk, asynchronously",
61+
"uri": "/bulk/events"
4362
}
4463
}
4564
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"name": "Intercom API (Job)",
3+
"description": "The Intercom API (Job)",
4+
"operations": {
5+
"getJob": {
6+
"httpMethod": "GET",
7+
"parameters": {
8+
"id": {
9+
"location": "uri",
10+
"required": true,
11+
"type": "string"
12+
}
13+
},
14+
"responseClass": "JobModel",
15+
"responseType": "model",
16+
"summary": "Gets a job",
17+
"uri": "/jobs/{id}"
18+
},
19+
"getJobErrors": {
20+
"httpMethod": "GET",
21+
"parameters": {
22+
"id": {
23+
"location": "uri",
24+
"required": true,
25+
"type": "string"
26+
}
27+
},
28+
"responseClass": "ErrorFeedModel",
29+
"responseType": "model",
30+
"summary": "Gets a job's error feed",
31+
"uri": "/jobs/{id}/error"
32+
}
33+
},
34+
"models": {
35+
"JobModel": {
36+
"type": "object",
37+
"properties": {
38+
"id": {
39+
"location": "json",
40+
"type": "string"
41+
},
42+
"app_id": {
43+
"location": "json",
44+
"type": "string"
45+
},
46+
"name": {
47+
"location": "json",
48+
"type": "string"
49+
},
50+
"state": {
51+
"location": "json",
52+
"type": "string"
53+
},
54+
"updated_at": {
55+
"location": "json",
56+
"type": "integer"
57+
},
58+
"created_at": {
59+
"location": "json",
60+
"type": "integer"
61+
},
62+
"completed_at": {
63+
"location": "json",
64+
"type": "integer"
65+
},
66+
"links": {
67+
"location": "json",
68+
"type": "object"
69+
}
70+
}
71+
},
72+
"ErrorFeedModel": {
73+
"type": "object",
74+
"properties": {
75+
"type": {
76+
"location": "json",
77+
"type": "string"
78+
},
79+
"items": {
80+
"location": "json",
81+
"type": "array",
82+
"items": {
83+
"type": "object"
84+
}
85+
},
86+
"pages": {
87+
"location": "json",
88+
"type": "object"
89+
}
90+
}
91+
}
92+
}
93+
}

src/Intercom/Service/config/intercom_public_user.json

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@
248248
"location": "json",
249249
"required": true,
250250
"type": "array"
251+
},
252+
"job": {
253+
"location": "json",
254+
"required": false,
255+
"type": "object"
251256
}
252257
},
253258
"responseClass": "JobModel",
@@ -257,43 +262,6 @@
257262
}
258263
},
259264
"models": {
260-
"JobModel": {
261-
"type": "object",
262-
"properties": {
263-
"id": {
264-
"location": "json",
265-
"type": "string"
266-
},
267-
"app_id": {
268-
"location": "json",
269-
"type": "string"
270-
},
271-
"name": {
272-
"location": "json",
273-
"type": "string"
274-
},
275-
"state": {
276-
"location": "json",
277-
"type": "string"
278-
},
279-
"updated_at": {
280-
"location": "json",
281-
"type": "integer"
282-
},
283-
"created_at": {
284-
"location": "json",
285-
"type": "integer"
286-
},
287-
"completed_at": {
288-
"location": "json",
289-
"type": "integer"
290-
},
291-
"links": {
292-
"location": "json",
293-
"type": "object"
294-
}
295-
}
296-
},
297265
"UserModel": {
298266
"type": "object",
299267
"properties": {

tests/Intercom/Resources/EventTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44

55
class EventTest extends IntercomTestCase
66
{
7+
public function testBulk()
8+
{
9+
$this->setMockResponse($this->client, 'Event/EventJob.txt');
10+
$response = $this->client->bulkEvents(
11+
[
12+
'items' => [
13+
[
14+
'data_type' => 'event',
15+
'method' => 'post',
16+
'data' => [
17+
'created_at' => 1401970113,
18+
'event_name' => 'invited-friend'
19+
]
20+
]
21+
]
22+
]);
23+
24+
$this->assertRequest('POST', '/bulk/events');
25+
$this->assertRequestJson(['items' => [['data_type' => 'event', 'method' => 'post', 'data' =>['created_at' => 1401970113, 'event_name' => 'invited-friend']]]]);
26+
27+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
28+
$this->assertEquals('job_5ca1ab1eca11ab1e', $response['id']);
29+
}
730
public function testCreateEvent()
831
{
932
$this->setMockResponse($this->client, 'Event/Event.txt');
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
class JobTest extends IntercomTestCase
6+
{
7+
public function testGetJob()
8+
{
9+
$this->setMockResponse($this->client, 'Job/MockJob.txt');
10+
$response = $this->client->getJob(['id' => 'job_5ca1ab1eca11ab1e']);
11+
12+
$this->assertBasicAuth('my-app', '1234');
13+
$this->assertRequest('GET', '/jobs/job_5ca1ab1eca11ab1e');
14+
15+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
16+
$this->assertEquals(1438944983, $response['updated_at']);
17+
}
18+
public function testGetJobErrors()
19+
{
20+
$this->setMockResponse($this->client, 'Job/MockErrorFeed.txt');
21+
$response = $this->client->getJobErrors(['id' => 'job_5ca1ab1eca11ab1e']);
22+
23+
$this->assertBasicAuth('my-app', '1234');
24+
$this->assertRequest('GET', '/jobs/job_5ca1ab1eca11ab1e/error');
25+
26+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
27+
$this->assertEquals('email invalid', $response['items'][0]['error']['message']);
28+
}
29+
}

tests/Mock/Event/EventJob.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"id": "job_5ca1ab1eca11ab1e",
9+
"app_id": "pi3243fa",
10+
"name": "api bulk job",
11+
"state": "running",
12+
"updated_at": 1438944983,
13+
"created_at": 1438944983,
14+
"completed_at": null,
15+
"links": {
16+
"error": "https://api.intercom.io/jobs/job_5ca1ab1eca11ab1e/error",
17+
"self": "https://api.intercom.io/jobs/job_5ca1ab1eca11ab1e"
18+
}
19+
}

tests/Mock/Job/MockErrorFeed.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"type" : "job_item.list",
9+
"items" : [
10+
{
11+
"type": "job_item",
12+
"method": "post",
13+
"data_type": "user",
14+
"data": {
15+
"user_id": "32",
16+
"email": "serenity.io"
17+
},
18+
"error": {
19+
"code": "invalid",
20+
"message": "email invalid"
21+
}
22+
}
23+
],
24+
"pages": {}
25+
}

tests/Mock/Job/MockJob.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"id": "job_5ca1ab1eca11ab1e",
9+
"app_id": "pi3243fa",
10+
"name": "api bulk job",
11+
"state": "running",
12+
"updated_at": 1438944983,
13+
"created_at": 1438944983,
14+
"completed_at": null,
15+
"links": {
16+
"error": "https://api.intercom.io/jobs/job_5ca1ab1eca11ab1e/error",
17+
"self": "https://api.intercom.io/jobs/job_5ca1ab1eca11ab1e"
18+
}
19+
}

0 commit comments

Comments
 (0)