Skip to content

Commit

Permalink
expose analytics API functions
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed May 7, 2024
1 parent b7abdaa commit 78b537c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,40 @@ class SocketSdk {
}
}

/**
* @param {string} time
* @returns {Promise<SocketSdkResultType<'getOrgAnalytics'>>}
*/
async getOrgAnalytics (time) {
const timeParam = encodeURIComponent(time)

try {
const client = await this.#getClient()
const data = await client.get(`analytics/org/${timeParam}`).json()
return { success: true, status: 200, data }
} catch (err) {
return /** @type {SocketSdkErrorType<'getOrgAnalytics'>} */ (this.#handleApiError(err))
}
}

/**
* @param {string} repo
* @param {string} time
* @returns {Promise<SocketSdkResultType<'getRepoAnalytics'>>}
*/
async getRepoAnalytics (repo, time) {
const timeParam = encodeURIComponent(time)
const repoParam = encodeURIComponent(repo)

try {
const client = await this.#getClient()
const data = await client.get(`analytics/repo/${repoParam}/${timeParam}`).json()
return { success: true, status: 200, data }
} catch (err) {
return /** @type {SocketSdkErrorType<'getRepoAnalytics'>} */ (this.#handleApiError(err))
}
}

/**
* @param {Array<{ organization?: string }>} selectors
* @returns {Promise<SocketSdkResultType<'postSettings'>>}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78b537c

Please sign in to comment.