Skip to content

Instantly share code, notes, and snippets.

@fieldju
Created June 30, 2020 15:28
Show Gist options
  • Save fieldju/7cfde17356b15a1e2c9406326176db47 to your computer and use it in GitHub Desktop.
Save fieldju/7cfde17356b15a1e2c9406326176db47 to your computer and use it in GitHub Desktop.
import axios from 'axios'
import { logger } from '../utils';
import NewRelicDashboard from '../model/NewRelicDashboard'
import { CreateDashboardRequest } from '../model/newrelic'
const { debug, info, warn, error } = logger;
export class NewRelicService {
private newRelicApiKeyByAccountIdMap: { [key: string]: string } = {}
public setApiKeys(newRelicApiKeyByAccountIdMap: { [key: string]: string }) {
this.newRelicApiKeyByAccountIdMap = newRelicApiKeyByAccountIdMap;
}
public async createDashboard(accountId: string, dashboard: NewRelicDashboard) {
try {
const res = await axios.post(
`https://api.newrelic.com/v2/dashboards`,
{ dashboard } as CreateDashboardRequest,
{
headers: {
'X-Api-Key': this.newRelicApiKeyByAccountIdMap[accountId],
'Content-Type': 'application/json'
}
})
const savedDashboard = res.data
} catch (e) {
error(`Failed to create dashboard...`)
error(JSON.stringify(e.response.data))
}
}
}
const newRelicService = new NewRelicService()
export default newRelicService
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment