Skip to content

Commit e70b751

Browse files
authored
7 support embeds on tickets (#10)
* Update poetry.lock * Update pyproject.toml singer-sdk to 0.30 * Update client.py Bring in params from embeds key * Update client.py Schema for embeds in config * Fix mess * Embeds into params * Add sla_policy to tickets schema * Extended docs * Add sla policy stream * Add new stream to tap
1 parent 6315b04 commit e70b751

File tree

9 files changed

+367
-234
lines changed

9 files changed

+367
-234
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"justMyCode": true,
1515
}
1616
{
17-
"name": "tap-freshdesk invoke",
17+
"name": "tap-freshdesk about",
1818
"type": "python",
1919
"request": "launch",
2020
"module": "tap_freshdesk.tap",
21-
"args": ["--config", ".secrets/config.json", "--test"],
21+
"args": ["--config", ".secrets/config.json", "--about"],
2222
"python": "${command:python.interpreterPath}",
2323
// Set to true to debug third-party library code
2424
"justMyCode": true,

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ This Singer tap will automatically import any environment variables within the w
5151
`.env` if the `--config=ENV` is provided, such that config values will be considered if a matching
5252
environment variable is set either in the terminal context or in the `.env` file.
5353

54+
#### Embeds
55+
The Freshdesk Tickets API allows for a number of 'embeds' - these are extra fields which can be returned from the API, at the cost of consuming more 'credits'.
56+
Turning on these embeds will return more data, but mean that the 'cooloff' happens sooner, and overall syncs may take longer.
57+
58+
See Freshdesk docs here: https://developers.freshdesk.com/api/#view_a_ticket
59+
60+
The available embeds for tickets are specified under the `embeds -> tickets_detail` config key:
61+
```
62+
config:
63+
embeds:
64+
tickets_detail:
65+
- stats
66+
- sla_policy
67+
- company
68+
- requester
69+
```
70+
71+
These extra values will be returned as json objects rather than unpacked in the main schema.
72+
73+
If you don't need these data items, then just don't include the `embeds` key in `meltano.yml` and only the base ticket fields will be returned.
74+
75+
As Freshdesk enables more embeds, they will be added here.
76+
5477
### Source Authentication and Authorization
5578

5679
<!--

poetry.lock

Lines changed: 216 additions & 227 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ license = "Apache 2.0"
1212

1313
[tool.poetry.dependencies]
1414
python = "<3.12,>=3.7.1"
15-
singer-sdk = { version="^0.23.0" }
1615
fs-s3fs = { version = "^1.1.1", optional = true }
1716
requests = "^2.28.2"
17+
singer-sdk = "^0.30.0"
1818

1919
[tool.poetry.group.dev.dependencies]
2020
pytest = "^7.2.1"
@@ -24,7 +24,6 @@ black = "^23.1.0"
2424
pyupgrade = "^3.3.1"
2525
mypy = "^1.0.0"
2626
isort = "^5.11.5"
27-
singer-sdk = { version="^0.23.0", extras = ["testing"] }
2827
types-requests = "^2.28.11.12"
2928

3029
[tool.poetry.extras]

tap_freshdesk/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def get_url_params(
117117
A dictionary of URL query parameters.
118118
"""
119119
params: dict = {}
120+
embeds = self.config.get('embeds')
121+
if embeds:
122+
embed_fields = embeds.get(self.name, [])
123+
if embed_fields: # i.e. 'stats,company,sla_policy'
124+
params['include'] = ','.join(embed_fields)
120125
return params
121126

122127
def prepare_request_payload(
@@ -215,4 +220,4 @@ def get_url_params(
215220
return params
216221

217222
def get_new_paginator(self) -> BasePageNumberPaginator:
218-
return FreshdeskPaginator(start_value=1)
223+
return FreshdeskPaginator(start_value=1)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"id": {
5+
"type": [
6+
"null",
7+
"integer"
8+
]
9+
},
10+
"name": {
11+
"type": [
12+
"null",
13+
"string"
14+
]
15+
},
16+
"description": {
17+
"type": [
18+
"null",
19+
"string"
20+
]
21+
},
22+
"active": {
23+
"type": [
24+
"null",
25+
"boolean"
26+
]
27+
},
28+
"sla_target": {
29+
"type": [
30+
"null",
31+
"object"
32+
]
33+
},
34+
"applicable_to": {
35+
"type": "object"
36+
},
37+
"is_default": {
38+
"type": [
39+
"null",
40+
"boolean"
41+
]
42+
},
43+
"position": {
44+
"type": [
45+
"null",
46+
"integer"
47+
]
48+
},
49+
"created_at": {
50+
"type": [
51+
"null",
52+
"string"
53+
],
54+
"format": "date-time"
55+
},
56+
"updated_at": {
57+
"type": [
58+
"null",
59+
"string"
60+
],
61+
"format": "date-time"
62+
}
63+
}
64+
}

tap_freshdesk/schemas/tickets.json

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,44 @@
357357
"format": "date-time"
358358
}
359359
}
360+
},
361+
"sla_policy": {
362+
"type": [
363+
"null",
364+
"object"
365+
],
366+
"properties": {
367+
"id": {
368+
"type": [
369+
"null",
370+
"integer"
371+
]
372+
},
373+
"name": {
374+
"type": [
375+
"null",
376+
"string"
377+
]
378+
},
379+
"description": {
380+
"type": [
381+
"null",
382+
"string"
383+
]
384+
},
385+
"active": {
386+
"type": [
387+
"null",
388+
"boolean"
389+
]
390+
},
391+
"sla_target": {
392+
"type": [
393+
"null",
394+
"object"
395+
]
396+
}
397+
}
360398
}
361-
}
362-
}
399+
}
400+
}

tap_freshdesk/streams.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class ContactsStream(FreshdeskStream):
3535
class EmailConfigsStream(FreshdeskStream):
3636
name = "email_configs"
3737

38+
class SlaPoliciesStream(FreshdeskStream):
39+
name = "sla_policies"
40+
3841
class TicketsAbridgedStream(PagedFreshdeskStream):
3942
name = "tickets_abridged"
4043
replication_key = 'updated_at'

tap_freshdesk/tap.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ class Tapfreshdesk(Tap):
3939
th.StringType,
4040
description="The url for the API service",
4141
),
42+
th.Property(
43+
"embeds",
44+
th.ObjectType(
45+
th.Property(
46+
'tickets_detail', th.ArrayType(
47+
th.StringType(allowed_values=['requester', 'company', 'stats', 'sla_policy'])
48+
)
49+
),
50+
),
51+
description='Dictionary of embeds for each stream, see more at https://developers.freshdesk.com/api/'
52+
),
4253
## these two below to enable stream mapping
4354
th.Property(
4455
"stream_maps",
@@ -68,6 +79,7 @@ def discover_streams(self) -> list[streams.FreshdeskStream]:
6879
streams.TicketsDetailStream(tap=self, ticket_ids=_ticket_ids),
6980
streams.ConversationsStream(self),
7081
streams.EmailConfigsStream(self),
82+
streams.SlaPoliciesStream(self),
7183
]
7284

7385

0 commit comments

Comments
 (0)