Skip to content

Commit

Permalink
Merge pull request #169 from SocketDev/cg/exposeAnalyticsAPI
Browse files Browse the repository at this point in the history
Expose analytics API functions
  • Loading branch information
charliegerard authored May 7, 2024
2 parents b7abdaa + 78b537c commit da5c20f
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 da5c20f

Please sign in to comment.