foundrybot
Version:
Foundrybot API wrapper
81 lines (72 loc) • 1.85 kB
text/typescript
import * as Promise from 'bluebird';
import * as _ from 'lodash';
import {
FoundrybotCreateAttributes, FoundrybotSearchAttributes,
Resource
} from '../../resource';
export interface FoundrybotDomainCrawl {
id: number;
orgId: number;
domainHostname: string;
urlHref: string;
maxUrls: number;
maxAge: number;
createdAt: Date;
updatedAt: Date;
}
export interface FoundrybotDomainCrawlSearchAttributes extends FoundrybotSearchAttributes {
url: string;
}
export interface FoundrybotDomainCrawlCreateAttributes extends FoundrybotCreateAttributes {
url?: string;
maxUrls?: number;
maxAge?: number;
}
/**
* @class DomainCrawlResource
* @extends Resource
*/
export class DomainCrawlResource extends Resource {
/**
* @param secretKey {string}
*/
constructor (secretKey: string) {
super(secretKey);
this.resourceName = 'DomainCrawl';
}
/**
* @param id {string}
* @returns {Promise<FoundrybotDomainCrawl>}
*/
get (id: string) {
return this.makeRequest({
method: 'GET',
params: { id },
url: '/domain-crawls/{id}'
})
.then((result) => result.doc)
}
/**
* @param params {FoundrybotDomainCrawlSearchAttributes}
* @returns {Promise<{docs: FoundrybotDomainCrawl[], total: number}>}
*/
search (params: FoundrybotDomainCrawlSearchAttributes) {
return this.makeRequest({
method: 'GET',
query: _.pick(params, ['limit', 'offset', 'url']),
url: '/domain-crawls'
})
}
/**
* @param params {FoundrybotDomainCrawlCreateAttributes}
* @returns {Promise<FoundrybotDomainCrawl>}
*/
create (params: FoundrybotDomainCrawlCreateAttributes) {
return this.makeRequest({
method: 'POST',
data: _.pick(params, ['url', 'maxUrls', 'maxAge']),
url: '/domain-crawls'
})
.then((result) => result.doc)
}
}