diff --git a/lib/client.js b/lib/client.js index 9a89239b..95b41ae3 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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') @@ -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) diff --git a/lib/typescript/webhooks.ts b/lib/typescript/webhooks.ts new file mode 100644 index 00000000..c0b52355 --- /dev/null +++ b/lib/typescript/webhooks.ts @@ -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 } diff --git a/lib/webhooks.js b/lib/webhooks.js new file mode 100644 index 00000000..6fbcb16c --- /dev/null +++ b/lib/webhooks.js @@ -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 diff --git a/test/typescript/hubspot.ts b/test/typescript/hubspot.ts index 8839a18a..3ab56eeb 100644 --- a/test/typescript/hubspot.ts +++ b/test/typescript/hubspot.ts @@ -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)