Skip to content

Instantly share code, notes, and snippets.

@thomasbaucom
Created August 2, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasbaucom/6fe7d1785729c1d81818ffa683ebb5bd to your computer and use it in GitHub Desktop.
Save thomasbaucom/6fe7d1785729c1d81818ffa683ebb5bd to your computer and use it in GitHub Desktop.
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.addNetworkDomain ("hooktheory.com");
pack.setUserAuthentication({
type: coda.AuthenticationType.HeaderBearerToken,
});
const ChordSchema = coda.makeObjectSchema({
properties: {
chord_ID: {description: "Chord Number", type: coda.ValueType.String,},
chord_HTML: {description: "Chord Numeral", type: coda.ValueType.String,},
probability: {description: "Probability", type: coda.ValueType.String,},
child_path: {description: "Chord path", type: coda.ValueType.String,},
},
displayProperty: "chord_ID"
});
const SongSchema = coda.makeObjectSchema({
properties: {
artist: {description: "Chord Number", type: coda.ValueType.String,},
song: {description: "Chord Numeral", type: coda.ValueType.String,},
section: {description: "Probability", type: coda.ValueType.String,},
url: {description: "Chord path", type: coda.ValueType.String,codaType: coda.ValueHintType.Url },
},
displayProperty: "song"
});
pack.addFormula({
name: "NextChord",
description: "Find next chord possibilities",
parameters: [
coda.makeParameter({
type:coda.ParameterType.String,
name: "chord",
description: "Chord number - (1 2 3 4)",
}),
],
resultType: coda.ValueType.Array,
items: ChordSchema,
execute: async function ([chord], context) {
let url = coda.withQueryParams("https://api.hooktheory.com/v1/trends/nodes", {
cp:chord
});
let response = await context.fetcher.fetch({
method: "GET",
url: url,
});
return response.body
},
});
pack.addFormula({
name: "FindSong",
description: "Find Songs with Chord Progression",
parameters: [
coda.makeParameter({
type:coda.ParameterType.String,
name: "chord",
description: "Chord number - (1 2 3 4)",
}),
],
resultType: coda.ValueType.Array,
items: SongSchema,
execute: async function ([chord], context) {
let url = coda.withQueryParams("https://api.hooktheory.com/v1/trends/songs", {
cp:chord
});
let response = await context.fetcher.fetch({
method: "GET",
url: url,
});
return response.body
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment