Skip to content

Commit

Permalink
Implement support for async activities export (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Carney authored Jul 19, 2021
1 parent fa1fc3e commit eb89928
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ ChartMogul.Metrics.ltv(config, query)
ChartMogul.Metrics.Customer.activities(config, customerUuid, query)
ChartMogul.Metrics.Customer.subscriptions(config, customerUuid, query)
ChartMogul.Metrics.Activity.all(config, query)
ChartMogul.Metrics.ActivitiesExport.create(config, query)
ChartMogul.Metrics.ActivitiesExport.retrieve(config, id)
```

### Account
Expand Down
13 changes: 13 additions & 0 deletions lib/chartmogul/metrics/activities_export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const Resource = require('../resource.js');

class ActivitiesExport extends Resource {
static get path () {
return '/v1/activities_export/{activitiesExportUuid}';
}
}

ActivitiesExport.create = Resource._method('POST', '/v1/activities_export');

module.exports = ActivitiesExport;
2 changes: 2 additions & 0 deletions lib/chartmogul/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Resource = require('../resource.js');
const Customer = require('./customer');
const Activity = require('./activity');
const ActivitiesExport = require('./activities_export');
const util = require('../util');

class Metrics {
Expand Down Expand Up @@ -35,4 +36,5 @@ Object.keys(actions).forEach(method => {

Metrics.Customer = Customer;
Metrics.Activity = Activity;
Metrics.ActivitiesExport = ActivitiesExport;
module.exports = Metrics;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chartmogul-node",
"version": "1.4.0",
"version": "1.5.0",
"description": "Official Chartmogul API Node.js Client",
"main": "lib/chartmogul.js",
"scripts": {
Expand Down
68 changes: 68 additions & 0 deletions test/chartmogul/metrics/activities_export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const ChartMogul = require('../../../lib/chartmogul');
const config = new ChartMogul.Config('token', 'secret');
const expect = require('chai').expect;
const nock = require('nock');
const ActivitiesExport = ChartMogul.Metrics.ActivitiesExport;

describe('ActivitiesExport', () => {
it('should create an activities export', () => {
const pendingExport = {
id: '7f554dba-4a41-4cb2-9790-2045e4c3a5b1',
status: 'pending',
file_url: null,
params: {
kind: 'activities',
params: {
activity_type: 'contraction',
start_date: '2020-01-01',
end_date: '2020-12-31'
}
},
expires_at: null,
created_at: '2021-07-12T14:46:56+00:00'
};

const query = {
'start-date': '2020-01-01',
'end-date': '2020-12-31',
type: 'contraction'
};

nock(config.API_BASE)
.post('/v1/activities_export')
.reply(200, pendingExport);

return ActivitiesExport.create(config, query)
.then(res => {
expect(res).to.be.deep.equal(pendingExport);
});
});

it('should retrieve a successful activities export after a period of time', () => {
const succeededExport = {
id: '7f554dba-4a41-4cb2-9790-2045e4c3a5b1',
status: 'succeeded',
file_url: 'https://chartmogul-customer-export.s3.eu-west-1.amazonaws.com/activities-acme-corp-91e1ca88-d747-4e25-83d9-2b752033bdba.zip',
params: {
kind: 'activities',
params: {
activity_type: 'contraction',
start_date: '2020-01-01',
end_date: '2020-12-31'
}
},
expires_at: '2021-07-19T14:46:58+00:00',
created_at: '2021-07-12T14:46:56+00:00'
};
nock(config.API_BASE)
.get('/v1/activities_export/7f554dba-4a41-4cb2-9790-2045e4c3a5b1')
.reply(200, succeededExport);

return ActivitiesExport.retrieve(config, '7f554dba-4a41-4cb2-9790-2045e4c3a5b1')
.then(res => {
expect(res).to.be.deep.equal(succeededExport);
});
});
});

0 comments on commit eb89928

Please sign in to comment.