forked from PipedreamHQ/pipedream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const strava = require("https://github.com/PipedreamHQ/pipedream/components/strava/strava.app.js"); | ||
|
||
module.exports = { | ||
name: "Activity Created", | ||
description: "Emits an event when a new activity is created", | ||
version: "0.0.1", | ||
props: { | ||
strava, | ||
stravaApphook: { | ||
type: "$.interface.apphook", | ||
appProp: "strava", | ||
eventNames: ["activity.create"], | ||
}, | ||
}, | ||
async run(event) { | ||
console.log(event); | ||
let details; | ||
try { | ||
details = await this.strava.getActivity(event.object_id); | ||
} catch (err) { | ||
console.log(`Error fetching activity details: ${err}`); | ||
} | ||
let summary = "Activity created"; | ||
if (details && details.name) { | ||
summary += `: ${details.name}`; | ||
} | ||
this.$emit( | ||
{ event, details }, | ||
{ | ||
summary, | ||
ts: event.event_time * 1000, | ||
} | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const strava = require("https://github.com/PipedreamHQ/pipedream/components/strava/strava.app.js"); | ||
|
||
module.exports = { | ||
name: "Activity Deleted", | ||
description: "Emits an event when an activity is deleted", | ||
version: "0.0.1", | ||
props: { | ||
strava, | ||
stravaApphook: { | ||
type: "$.interface.apphook", | ||
appProp: "strava", | ||
eventNames: ["activity.delete"], | ||
}, | ||
}, | ||
async run(event) { | ||
console.log(event); | ||
this.$emit( | ||
{ event }, | ||
{ | ||
summary: `Activity deleted: ${event.object_id}`, | ||
ts: event.event_time * 1000, | ||
} | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const strava = require("https://github.com/PipedreamHQ/pipedream/components/strava/strava.app.js"); | ||
|
||
module.exports = { | ||
name: "Activity Updated", | ||
description: "Emits an event when an activity is updated", | ||
version: "0.0.1", | ||
props: { | ||
strava, | ||
stravaApphook: { | ||
type: "$.interface.apphook", | ||
appProp: "strava", | ||
eventNames: ["activity.update"], | ||
}, | ||
}, | ||
async run(event) { | ||
console.log(event); | ||
let details; | ||
try { | ||
details = await this.strava.getActivity(event.object_id); | ||
} catch (err) { | ||
console.log(`Error fetching activity details: ${err}`); | ||
} | ||
let summary = "Activity updated"; | ||
if (details && details.name) { | ||
summary += `: ${details.name}`; | ||
} | ||
this.$emit( | ||
{ event, details }, | ||
{ | ||
summary, | ||
ts: event.event_time * 1000, | ||
} | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const strava = require("https://github.com/PipedreamHQ/pipedream/components/strava/strava.app.js"); | ||
|
||
module.exports = { | ||
name: "Strava Custom Events", | ||
description: | ||
"Emits an event when an activity is created, updated, or deleted", | ||
version: "0.0.1", | ||
props: { | ||
strava, | ||
eventNameOptions: { | ||
label: "Strava Events", | ||
type: "string[]", | ||
async options() { | ||
return ["activity.create", "activity.update", "activity.delete"]; | ||
}, | ||
}, | ||
stravaApphook: { | ||
type: "$.interface.apphook", | ||
appProp: "strava", | ||
async eventNames() { | ||
return this.eventNameOptions; | ||
}, | ||
}, | ||
}, | ||
async run(event) { | ||
console.log(event); | ||
const { object_type, object_id, event_time } = event; | ||
const ts = event_time * 1000; | ||
|
||
if (object_type === "activity") { | ||
let details; | ||
// Optimistically fetch activity details. When an event is deleted, this will fail | ||
try { | ||
details = await this.strava.getActivity(object_id); | ||
} catch (err) { | ||
console.log(`Error fetching activity details: ${err}`); | ||
} | ||
this.$emit( | ||
{ event, details }, | ||
{ | ||
summary: `Activity ${event.aspect_type}d`, | ||
ts, | ||
} | ||
); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Strava API app file | ||
const axios = require("axios"); | ||
|
||
module.exports = { | ||
type: "app", | ||
app: "strava", | ||
methods: { | ||
async _makeAPIRequest(opts) { | ||
if (!opts.headers) opts.headers = {}; | ||
opts.headers["Authorization"] = `Bearer ${this.$auth.oauth_access_token}`; | ||
opts.headers["Content-Type"] = "application/json"; | ||
opts.headers["user-agent"] = "@PipedreamHQ/pipedream v0.1"; | ||
const { path } = opts; | ||
delete opts.path; | ||
opts.url = `https://www.strava.com/api/v3${ | ||
path[0] === "/" ? "" : "/" | ||
}${path}`; | ||
return await axios(opts); | ||
}, | ||
async getActivity(id) { | ||
return ( | ||
await this._makeAPIRequest({ | ||
path: `/activities/${id}`, | ||
}) | ||
).data; | ||
}, | ||
async getAuthenticatedAthlete() { | ||
return ( | ||
await this._makeAPIRequest({ | ||
path: "/athlete", | ||
}) | ||
).data; | ||
}, | ||
}, | ||
}; |