Skip to content

Commit

Permalink
initial sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
ontl committed Nov 20, 2021
0 parents commit d35f3b8
Show file tree
Hide file tree
Showing 6 changed files with 13,481 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.coda.json
node_modules
.coda-pack.json
24 changes: 24 additions & 0 deletions helpers.ts
@@ -0,0 +1,24 @@
import type * as coda from "@codahq/packs-sdk";

// Config

export async function getMovie(context: coda.ExecutionContext, query: string) {
const url =
"https://imdb8.p.rapidapi.com/title/find?q=" + encodeURIComponent(query);
const response = await context.fetcher.fetch({
method: "GET",
headers: {
"x-rapidapi-host": "imdb8.p.rapidapi.com",
},
url: url,
});
const movie = response.body.results[0];
return {
// grab the ID (tt0109830) out of the API's id response (/title/tt0109830/)
IMDBId: movie.id.replace("/title/", "").replace("/", ""),
Title: movie.title,
Year: movie.year,
Runtime: movie.runningTimeInMinutes + " minutes",
Poster: movie.image.url,
};
}
50 changes: 50 additions & 0 deletions pack.ts
@@ -0,0 +1,50 @@
import * as coda from "@codahq/packs-sdk";
import * as helpers from "./helpers";
import * as schemas from "./schemas";

export const pack = coda.newPack({ version: "0.1.0" });

/* -------------------------------------------------------------------------- */
/* API */
/* -------------------------------------------------------------------------- */

pack.addNetworkDomain("rapidapi.com");
pack.setUserAuthentication({
type: coda.AuthenticationType.CustomHeaderToken,
headerName: "x-rapidapi-key",
instructionsUrl: "https://coda.io/@nickhe/imdb-pack",
});

/* -------------------------------------------------------------------------- */
/* Column Formats */
/* -------------------------------------------------------------------------- */

pack.addColumnFormat({
name: "IMDB Movie",
instructions: "Shows movie details from IMDB",
formulaName: "IMDBMovie",
formulaNamespace: "Deprecated",
});

/* -------------------------------------------------------------------------- */
/* Formulas */
/* -------------------------------------------------------------------------- */

pack.addFormula({
name: "IMDBMovie",
description: "Search for a movie title and get details about it from IMDB",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "query",
description: "Search IMDB (try movie name, or movie name and year)",
}),
],

resultType: coda.ValueType.Object,
schema: schemas.MovieSchema,

execute: async function ([query], context) {
return helpers.getMovie(context, query);
},
});

0 comments on commit d35f3b8

Please sign in to comment.