Skip to content

Commit

Permalink
Fix errors when no response
Browse files Browse the repository at this point in the history
  • Loading branch information
pcothenet committed Dec 11, 2019
2 parents 162fd7a + a25a91f commit 03cb361
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 130 deletions.
37 changes: 37 additions & 0 deletions lib/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import EloquaClient from './client';
import Field from './field';

export default class Contact {
client: EloquaClient;
fields: any;
lists: any;

constructor (client: EloquaClient) {
this.client = client;
this.fields = new Field(this.client, 'account');
}

get (id: number, options?: any) {
return this.client._request({
method: 'GET',
url: `/api/REST/1.0/data/account/${id}`,
params: options
});
}

getAll (options?: any) {
return this.client._request({
method: 'GET',
url: '/api/REST/1.0/data/accounts',
params: options
});
}

update (id: number, data: any) {
return this.client._request({
data,
method: 'PUT',
url: `/api/REST/1.0/data/account/${id}`
});
}
}
18 changes: 9 additions & 9 deletions lib/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export default class List {
this.client = client;
}

createExport(name: string, fields: any, filter: string) {
createExport(objectName: string, exportName: string, fields: any, filter: string) {
return this.client._request({
method: 'POST',
url: '/api/bulk/2.0/activities/exports',
url: `/api/bulk/2.0/${objectName}/exports`,
data: {
name,
fields,
filter,
name: exportName,
areSystemTimestampsInUTC: true
}
});
Expand Down Expand Up @@ -58,25 +58,25 @@ export default class List {
});
}

async completeExport(name: string, fields: any, filter: string) {
const bulkExport = await this.createExport(name, fields, filter);
async completeExport(objectName: string, exportName: string, fields: any, filter: string) {
const bulkExport = await this.createExport(objectName, exportName, fields, filter);
const sync = await this.createSync(bulkExport.uri);
const syncUri = sync.uri;
const results = await this.pollSync(syncUri);
const { status } = results;
return { syncUri, status };
}

async runExport(name: string, fields: any, filter: string) {
const { status, syncUri } = await this.completeExport(name, fields, filter);
async runExport(objectName: string, exportName: string, fields: any, filter: string) {
const { status, syncUri } = await this.completeExport(objectName, exportName, fields, filter);
if (status === 'success') {
return this.getSyncData(syncUri);
}
return;
}

async getExportStream(name: string, fields: any, filter: string) {
const { status, syncUri } = await this.completeExport(name, fields, filter);
async getExportStream(objectName: string, exportName: string, fields: any, filter: string) {
const { status, syncUri } = await this.completeExport(objectName, exportName, fields, filter);
if (status === 'success') {
return new Stream(this.client, syncUri);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Debug from 'debug';
import * as EventEmitter from 'events';
import * as _ from 'lodash';
import Bulk from './bulk';
import Account from './account';
import Contact from './contact';
import EloquaError from './errors';

Expand All @@ -29,6 +30,7 @@ export default class EloquaClient extends EventEmitter {
loginUrl: string;
baseUrl: string;
apiCalls: number;
accounts: any;
contacts: any;
bulk: any;

Expand All @@ -47,6 +49,7 @@ export default class EloquaClient extends EventEmitter {
this.apiCalls += 1;
});

this.accounts = new Account(this);
this.contacts = new Contact(this);
this.bulk = new Bulk(this);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/contact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Field from './contact_field';
import Field from './field';
import List from './contact_list';
import Segment from './contact_segment';
import EloquaClient from './client';
Expand All @@ -11,7 +11,7 @@ export default class Contact {

constructor (client: EloquaClient) {
this.client = client;
this.fields = new Field(this.client);
this.fields = new Field(this.client, 'contact');
this.lists = new List(this.client);
this.segments = new Segment(this.client);
}
Expand Down
14 changes: 8 additions & 6 deletions lib/contact_field.ts → lib/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import EloquaClient from './client';

export default class Properties {
client: EloquaClient;
objectName: string;

constructor (client: EloquaClient) {
constructor (client: EloquaClient, objectName: string) {
this.client = client;
this.objectName = objectName;
}

getAll (options?: any) {
return this.client._request({
method: 'GET',
url: '/api/REST/1.0/assets/contact/fields',
url: `/api/REST/1.0/assets/${this.objectName}/fields`,
params: options
});
}

get (id: number, options?: any) {
return this.client._request({
method: 'GET',
url: `/api/REST/1.0/assets/contact/field/${id}`,
url: `/api/REST/1.0/assets/${this.objectName}/field/${id}`,
params: options
});
}
Expand All @@ -27,22 +29,22 @@ export default class Properties {
return this.client._request({
data,
method: 'POST',
url: '/api/REST/1.0/assets/contact/field'
url: `/api/REST/1.0/assets/${this.objectName}/field`
});
}

update (id: number, data: any) {
return this.client._request({
data,
method: 'PUT',
url: `/api/REST/1.0/assets/contact/field/${id}`
url: `/api/REST/1.0/assets/${this.objectName}/field/${id}`
});
}

delete (id: number) {
return this.client._request({
method: 'DELETE',
url: `/api/REST/1.0/assets/contact/field/${id}`
url: `/api/REST/1.0/assets/${this.objectName}/field/${id}`
});
}
}
Loading

0 comments on commit 03cb361

Please sign in to comment.