Skip to content

Commit 7986f53

Browse files
authored
Merge pull request #105 from rapidpro/api-channel-type
Add support for channel type field on channels endpoint
2 parents 176dbf8 + 17f520c commit 7986f53

5 files changed

Lines changed: 17 additions & 12 deletions

File tree

temba_client/v2/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ def __init__(self, host, token, user_agent=None, verify_ssl=None, transformer=No
3939
# Fetch object operations
4040
# ==================================================================================================================
4141

42-
def get_archives(self, archive_type=None, period=None, before=None, after=None):
42+
def get_archives(self, type=None, period=None, before=None, after=None):
4343
"""
4444
Gets all matching archives
45-
:param str archive_type: "message" or "run"
45+
:param str type: "message" or "run"
4646
:param str period: "daily" or "monthly"
4747
:param datetime before: created before
4848
:param datetime after: created after
4949
:return: archive query
5050
"""
5151

52-
params = self._build_params(archive_type=archive_type, period=period, before=before, after=after)
52+
params = self._build_params(type=type, period=period, before=before, after=after)
5353
return self._get_query("archives", params, Archive)
5454

5555
def get_boundaries(self, geometry=None):

temba_client/v2/tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_get_archives(self, mock_request):
178178
self.assertRequest(mock_request, "get", "archives")
179179
self.assertEqual(len(results), 4)
180180

181-
self.assertEqual(results[1].archive_type, "message")
181+
self.assertEqual(results[1].type, "message")
182182
self.assertEqual(results[1].start_date, datetime(2018, 4, 1, 0, 0, tzinfo=tzone.utc))
183183
self.assertEqual(results[1].period, "monthly")
184184
self.assertEqual(results[1].record_count, 10)
@@ -187,7 +187,7 @@ def test_get_archives(self, mock_request):
187187
self.assertEqual(results[1].download_url, "http://s3-bucket.aws.com/my/archive.jsonl.gz")
188188

189189
self.client.get_archives(
190-
archive_type="message",
190+
type="message",
191191
period="daily",
192192
after=datetime(2018, 1, 1, tzinfo=tzone.utc),
193193
before=datetime(2018, 5, 1, tzinfo=tzone.utc),
@@ -198,7 +198,7 @@ def test_get_archives(self, mock_request):
198198
"get",
199199
"archives",
200200
params={
201-
"archive_type": "message",
201+
"type": "message",
202202
"period": "daily",
203203
"after": "2018-01-01T00:00:00.000000Z",
204204
"before": "2018-05-01T00:00:00.000000Z",
@@ -336,6 +336,7 @@ def test_get_channels(self, mock_request):
336336
self.assertEqual(results[0].name, "Android Phone")
337337
self.assertEqual(results[0].address, "+250788123123")
338338
self.assertEqual(results[0].country, "RW")
339+
self.assertEqual(results[0].type, "android")
339340
self.assertEqual(results[0].device.name, "Nexus 5X")
340341
self.assertEqual(results[0].device.power_level, 99)
341342
self.assertEqual(results[0].device.power_status, "STATUS_DISCHARGING")

temba_client/v2/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FieldRef(TembaObject):
3030

3131

3232
class Archive(TembaObject):
33-
archive_type = SimpleField()
33+
type = SimpleField()
3434
start_date = DatetimeField()
3535
period = SimpleField()
3636
record_count = IntegerField()
@@ -94,9 +94,11 @@ class Device(TembaObject):
9494
power_source = SimpleField()
9595
network_type = SimpleField()
9696

97+
9798
uuid = SimpleField()
9899
name = SimpleField()
99100
address = SimpleField()
101+
type=SimpleField()
100102
country = SimpleField()
101103
device = ObjectField(item_class=Device)
102104
last_seen = DatetimeField()

test_files/v2/archives.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"previous": null,
44
"results": [
55
{
6-
"archive_type": "run",
6+
"type": "run",
77
"start_date": "2018-04-01",
88
"period": "monthly",
99
"record_count": 1,
@@ -12,7 +12,7 @@
1212
"download_url": "http://s3-bucket.aws.com/my/archive.jsonl.gz"
1313
},
1414
{
15-
"archive_type": "message",
15+
"type": "message",
1616
"start_date": "2018-04-01",
1717
"period": "monthly",
1818
"record_count": 10,
@@ -21,7 +21,7 @@
2121
"download_url": "http://s3-bucket.aws.com/my/archive.jsonl.gz"
2222
},
2323
{
24-
"archive_type": "message",
24+
"type": "message",
2525
"start_date": "2018-03-01",
2626
"period": "monthly",
2727
"record_count": 100,
@@ -30,7 +30,7 @@
3030
"download_url": "http://s3-bucket.aws.com/my/archive.jsonl.gz"
3131
},
3232
{
33-
"archive_type": "run",
33+
"type": "run",
3434
"start_date": "2018-03-01",
3535
"period": "monthly",
3636
"record_count": 1000,

test_files/v2/channels.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"uuid": "09d23a05-47fe-11e4-bfe9-b8f6b119e9ab",
77
"name": "Android Phone",
88
"address": "+250788123123",
9+
"type": "android",
910
"country": "RW",
1011
"device": {
1112
"name": "Nexus 5X",
@@ -19,8 +20,9 @@
1920
},
2021
{
2122
"uuid": "9a8b001e-a913-486c-80f4-1356e23f582e",
22-
"name": "Nexmo",
23+
"name": "Vonage",
2324
"address": "+250788000001",
25+
"type": "vonage",
2426
"country": "RW",
2527
"device": null,
2628
"last_seen": "2016-03-01T05:31:27.456000+00:00",

0 commit comments

Comments
 (0)