Created
June 30, 2020 15:28
-
-
Save fieldju/7cfde17356b15a1e2c9406326176db47 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 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