-
-
Save thomasbaucom/6fe7d1785729c1d81818ffa683ebb5bd to your computer and use it in GitHub Desktop.
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
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