Skip to content

Commit ee93b08

Browse files
author
markzegarelli
authored
Merge pull request #246 from segmentio/use-ids-for-int-mapping
Use ids for int mapping
2 parents ba75e1c + 007aab1 commit ee93b08

File tree

417 files changed

+606
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+606
-343
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ vendor/bundle:
150150
@bundle config set --local path 'vendor/bundle'
151151
@bundle install
152152

153+
.PHONY: update
154+
update:
155+
@node scripts/update.js
153156

154157
.PHONY: lint
155158
lint: node_modules

scripts/update.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// These lines are the required packages we need. These let us do things like make network requests to the Public API
2+
// and interact with the frontmatter
3+
const axios = require('axios');
4+
const path = require('path');
5+
const fs = require('fs');
6+
const fm = require('front-matter');
7+
const yaml = require('js-yaml');
8+
const {
9+
type
10+
} = require('os');
11+
12+
require('dotenv').config();
13+
14+
// Here, global variables are set
15+
const PAPI_URL = "https://api.segmentapis.com"
16+
const slugOverrides = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/slugs.yml`)))
17+
18+
// This function connects with the Public API. It looks for the endpoint URL and a page token value.
19+
// The function is called in the updateSources and update Destination functions.
20+
// Functions let us reuse code easily. Instead of needing to write this out multiple times, I can define it once
21+
// and pass in the necessary details when I call it.
22+
const getCatalog = async (url, page_token = "MA==") => {
23+
try {
24+
const res = await axios.get(url, {
25+
headers: {
26+
'Content-Type': 'application/json',
27+
'Authorization': `Bearer ${process.env.PAPI_TOKEN}`
28+
},
29+
data: {
30+
"pagination": {
31+
"count": 200,
32+
"cursor": page_token
33+
}
34+
}
35+
});
36+
37+
return res.data
38+
} catch (error) {
39+
console.log(error)
40+
}
41+
}
42+
43+
// This function, again called by the two update functions, is what generates the slug values for each integration.
44+
// It takes the integration's Display Name and converts it to a slug.
45+
const slugify = (displayName) => {
46+
let slug = displayName
47+
.toLowerCase()
48+
.replace(/\s+/g, '-')
49+
.replace('-&-', '-')
50+
.replace('/', '-')
51+
.replace(/[\(\)]/g, '')
52+
.replace('.', '-')
53+
54+
// This is how we handle manual slug overrides right now.
55+
// If a slug appears in the slugOverrides file, we want to use the 'override' value instead.
56+
for (key in slugOverrides) {
57+
let original = slugOverrides[key].original
58+
let override = slugOverrides[key].override
59+
60+
if (slug == original) {
61+
console.log(original + " -> " + override)
62+
slug = override
63+
}
64+
}
65+
66+
return slug
67+
}
68+
69+
// This function does the actual work of adding the id value to the source and destination
70+
// Notice that the write to file step is commented out. This is to verify that the updated frontmatter
71+
// is correct before we write a whole bunch of files.
72+
// Uncomment that line and remove the line above it to run it for real.
73+
const addIdToExisting = (integration) => {
74+
let itemURL = integration.url
75+
try {
76+
const catalogPath = path.resolve('src', itemURL, 'index.md')
77+
if (fs.existsSync(catalogPath)) {
78+
const f = fm(fs.readFileSync(catalogPath, 'utf8'));
79+
const attr = `---\n${f.frontmatter}\nid: ${integration.id}\n---\n`
80+
const body = f.body
81+
const content = attr + body
82+
console.log(attr)
83+
fs.writeFileSync(catalogPath, content)
84+
}
85+
} catch (e) {
86+
console.log(error)
87+
return false
88+
}
89+
}
90+
91+
92+
// This is just a stripped down version of the updateSources() script from the catalog script.
93+
// We're retrieving less information overall, because all we care about here is the id.
94+
const updateSources = async () => {
95+
96+
let sources = []
97+
let nextPageToken = "MA=="
98+
99+
while (nextPageToken !== null) {
100+
const res = await getCatalog(`${PAPI_URL}/catalog/sources/`, nextPageToken)
101+
sources = sources.concat(res.data.sourcesCatalog)
102+
nextPageToken = res.data.pagination.next
103+
}
104+
105+
const libraryCategories = [
106+
'server',
107+
'mobile',
108+
'ott',
109+
'roku',
110+
'website'
111+
]
112+
sources.forEach(source => {
113+
let slug = slugify(source.name)
114+
let mainCategory = source.categories[0] ? source.categories[0].toLowerCase() : ''
115+
116+
if (libraryCategories.includes(mainCategory)) {
117+
url = `connections/sources/catalog/libraries/${mainCategory}/${slug}`
118+
} else {
119+
url = `connections/sources/catalog/cloud-apps/${slug}`
120+
mainCategory = 'cloud-app'
121+
}
122+
// So, we retrieve and store only the id and the URL, which is defined in the if statement on line 116.
123+
let updatedSource = {
124+
id: source.id,
125+
url,
126+
}
127+
addIdToExisting(updatedSource)
128+
})
129+
}
130+
131+
// Similar to the sources script, only for destinations.
132+
const updateDestinations = async () => {
133+
let destinations = []
134+
let nextPageToken = "MA=="
135+
136+
while (nextPageToken !== null) {
137+
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/`, nextPageToken)
138+
destinations = destinations.concat(res.data.destinationsCatalog)
139+
nextPageToken = res.data.pagination.next
140+
}
141+
142+
143+
destinations.forEach(destination => {
144+
let slug = slugify(destination.name)
145+
146+
let url = `connections/destinations/catalog/${slug}`
147+
148+
let updatedDestination = {
149+
id: destination.id,
150+
url
151+
}
152+
addIdToExisting(updatedDestination)
153+
154+
})
155+
156+
}
157+
updateDestinations()
158+
updateSources()

src/_includes/content/destination-dossier.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!-- in the file we're pulling from the API, "name" corresponds with the path to the yml blob for a specific destination.-->
2-
{% assign thisDestination = page.url | split: "/" | last %}
2+
{% assign thisDestination = page.id %}
33

44
{% assign overrideInfo = site.data.catalog.overrides.items % | where: "slug", thisDestination | first %}
55

66

77

8-
{% assign destinationInfo = site.data.catalog.destinations.items | where: "slug", thisDestination | first %}
8+
{% assign destinationInfo = site.data.catalog.destinations.items | where: "destination_id", thisDestination | first %}
99
{% comment %}There are probably prettier ways to generate a list of links to these methods, but this was good enough for me.{% endcomment %}
1010
{% assign destMethods = "" | split: ", " %}
1111
{% assign methodName = "" | split: " " %}
@@ -78,4 +78,4 @@ <h6>Connection Modes <a href="/docs/connections/destinations/#connection-modes">
7878
</table>
7979
</div>
8080
{% endif %}
81-
</div>
81+
</div>

src/connections/destinations/catalog/2mee/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: 2mee Destination
33
rewrite: true
4+
id: 60b5d0a01f3726b85dc05aab
45
---
56
[2mee](https://2mee.com ) is a Human Hologram platform that automatically cuts the person out from the background, removing the visual clutter, and places them in the familiar context of your phone or website so that they dominate the screen.
67

src/connections/destinations/catalog/ab-smartly/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
title: AB Smartly Destination
3+
id: 605dd9d7e5ff0b3873e250a4
34
---
4-
5-
65
[A/B Smartly](https://absmartly.com/?utm_source=segmentio&utm_medium=docs&utm_campaign=partners){:target="_blank"} provides an on-premise, full-stack experimentation platform for engineering and product teams that do continuous experimentation embedded into their development process. A/B Smartly's real-time analytics helps engineering and product teams ensure that new features will improve the customer experience without breaking or degrading performance and/or business metrics.
76

87
This destination is maintained by A/B Smartly. For any issues with the destination, [contact A/B Smartly's Support](mailto:[email protected]).

src/connections/destinations/catalog/actions-amplitude/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Amplitude (Actions) Destination
33
hide-boilerplate: true
44
hide-dossier: false
5+
id: 5f7dd6d21ad74f3842b1fc47
56
---
67
{% include content/plan-grid.md name="actions" %}
78

src/connections/destinations/catalog/actions-facebook-conversions-api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ title: Facebook Conversions API (Actions)
33
strat: facebook
44
hide-boilerplate: true
55
hide-dossier: false
6+
id: 61806e472cd47ea1104885fc
67
---
7-
88
Facebook Conversions API (Actions) enables advertisers to send events from their servers directly to Facebook. Server-side events link to Facebook Pixel events, and process like browser pixel events. This means that server-side events are used in measurement, reporting, and optimization, just like browser pixel events.
99

1010
## Benefits of Facebook Conversions API (Actions) vs Facebook Conversions API Classic

src/connections/destinations/catalog/actions-friendbuy-cloud/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ title: Friendbuy Cloud Mode (Actions) Destination
33
hide-boilerplate: true
44
hide-dossier: false
55
hidden: false
6+
id: 61dde0dc77eb0db0392649d3
67
---
7-
88
{% include content/plan-grid.md name="actions" %}
99

1010
[Friendbuy](https://www.friendbuy.com/){:target='_blank'} powers referral programs for e-commerce merchants of all sizes, providing an easy solution to launch Refer-a-Friend programs and accelerate growth through word of mouth.

src/connections/destinations/catalog/actions-friendbuy/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ title: Friendbuy Web Mode (Actions) Destination
33
hide-boilerplate: true
44
hide-dossier: false
55
hidden: false
6+
id: 6170a348128093cd0245e0ea
67
---
7-
88
<!-- The published version of this document is available at https://segment.com/docs/connections/destinations/catalog/actions-friendbuy/ -->
99

1010
{% include content/plan-grid.md name="actions" %}

src/connections/destinations/catalog/actions-fullstory/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: FullStory (Actions)
33
hide-boilerplate: true
44
hide-dossier: false
5+
id: 6141153ee7500f15d3838703
56
---
67
{% include content/plan-grid.md name="actions" %}
78

0 commit comments

Comments
 (0)