Skip to content

Commit

Permalink
Merge pull request MadKudu#296 from MadKudu/feature/webhooks
Browse files Browse the repository at this point in the history
init webhooks
  • Loading branch information
ksvirkou-hubspot authored Dec 29, 2020
2 parents 4eff9f8 + 4f21d85 commit da1661f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const OAuth = require('./oauth')
const Pipeline = require('./pipeline')
const Subscription = require('./subscription')
const Timeline = require('./timeline')
const Webhooks = require('./webhooks')
const Workflow = require('./workflow')
const MarketingEmail = require('./marketing_email')
const Ticket = require('./ticket')
Expand Down Expand Up @@ -60,6 +61,7 @@ const setInstances = (client) => {
client.pipelines = new Pipeline(client)
client.timelines = new Timeline(client)
client.subscriptions = new Subscription(client)
client.webhooks = new Webhooks(client)
client.workflows = new Workflow(client)
client.crm = new CRM(client)
client.marketingEmail = new MarketingEmail(client)
Expand Down
17 changes: 17 additions & 0 deletions lib/typescript/webhooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RequestPromise } from 'request-promise'

declare class Webhooks {
getSubscription(appId: number): RequestPromise

createSubscription(appId: number, subscription: {}): RequestPromise

updateSubscription(appId: number, subscriptionId: string, subscription: {}): RequestPromise

deleteSubscription(appId: number, subscriptionId: string): RequestPromise

viewSettings(appId: number): RequestPromise

updateSettings(appId: number, settings: {}): RequestPromise
}

export { Webhooks }
52 changes: 52 additions & 0 deletions lib/webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Webhooks {
constructor(client) {
this.client = client
}

getSubscription(appId) {
return this.client.apiRequest({
method: 'GET',
path: `/webhooks/v1/${appId}/subscriptions`,
})
}

createSubscription(appId, subscription) {
return this.client.apiRequest({
method: 'POST',
path: `/webhooks/v1/${appId}/subscriptions`,
body: subscription,
})
}

updateSubscription(appId, subscriptionId, subscription) {
return this.client.apiRequest({
method: 'PUT',
path: `/webhooks/v1/${appId}/subscriptions/${subscriptionId}`,
body: subscription,
})
}

deleteSubscription(appId, subscriptionId) {
return this.client.apiRequest({
method: 'DELETE',
path: `/webhooks/v1/${appId}/subscriptions/${subscriptionId}`,
})
}

viewSettings(appId) {
return this.client.apiRequest({
method: 'GET',
path: `/webhooks/v1/${appId}/settings`,
})
}

updateSettings(appId, settings) {
return this.client.apiRequest({
method: 'PUT',
path: `/webhooks/v1/${appId}/settings`,
body: settings,
})
}
}

module.exports = Webhooks
5 changes: 1 addition & 4 deletions test/typescript/hubspot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ const handleError = (requestError: RequestError) => {

const hubspot = new Hubspot(apiKeyOptions)

hubspot.companies
.get({ limit: 1 })
.then(handleResponse)
.catch(handleError)
hubspot.companies.get({ limit: 1 }).then(handleResponse).catch(handleError)

0 comments on commit da1661f

Please sign in to comment.