Skip to content

Commit

Permalink
[SE-231] Removing Injest related
Browse files Browse the repository at this point in the history
  • Loading branch information
sstaley-sparkpost committed Sep 26, 2019
1 parent 2e6fca5 commit e817882
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 117 deletions.
29 changes: 0 additions & 29 deletions examples/events/search_ingest.js

This file was deleted.

4 changes: 2 additions & 2 deletions examples/events/search_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var key = 'YOURAPIKEY'
// Returns 1000 message events for the last hour

// Promise
client.events.message.search({})
client.events.searchMessage({})
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
Expand All @@ -18,7 +18,7 @@ client.events.message.search({})
});

// Callback
client.events.message.search({}, function(err, data) {
client.events.searchMessage({}, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
Expand Down
53 changes: 23 additions & 30 deletions lib/events.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
'use strict';

let api = 'events';
const api = 'events';

/*
* "Class" declaration, Events API exposes one function:
* - search: retrieves list of events according to given params
* - search: retrieves list of message events according to given params
*/
module.exports = function(client) {

function search(parameters, callback) {
const options = {
uri: api
, qs: {}
};

Object.keys(parameters).forEach(function(paramname) {
if (Array.isArray(parameters[paramname])) {
options.qs[paramname] = parameters[paramname].join(',');
} else {
options.qs[paramname] = parameters[paramname];
}
});
return client.get(options, callback);
}

return {
message: {
search: function(parameters, callback) {
api += '/message';
return search(parameters, callback);
}
},
ingest: {
search: function(parameters, callback) {
api += '/ingest';
return search(parameters, callback);
}
/**
* Search for events using given parameters
*
* @param {Object} parameters
* @param {RequestCb} [callback]
* @returns {Promise}
*/
searchMessage: function(parameters, callback) {
const options = {
uri: `${api}/message`
, qs: {}
};

Object.keys(parameters).forEach(function(paramname) {
if (Array.isArray(parameters[paramname])) {
options.qs[paramname] = parameters[paramname].join(',');
} else {
options.qs[paramname] = parameters[paramname];
}
});
return client.get(options, callback);
}
};
};
59 changes: 3 additions & 56 deletions test/spec/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require('sinon-as-promised');
chai.use(require('sinon-chai'));
chai.use(require('chai-as-promised'));

describe('Message Events Library', function() {
describe('Events Library', function() {
let client, events, callback;

beforeEach(function() {
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Message Events Library', function() {
to: '2016-11-14T16:15',
transmission_ids: '65832150921904138'
};
return events.message.search(options, callback)
return events.searchMessage(options, callback)
.then(function() {
Object.keys(options).forEach(function(key) {
expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]);
Expand All @@ -65,7 +65,7 @@ describe('Message Events Library', function() {
per_page: 5,
timezone: 'America/New_York'
};
return events.message.search(arroptions)
return events.searchMessage(arroptions)
.then(function() {
Object.keys(arroptions).forEach(function(key) {
var opt = arroptions[key]
Expand All @@ -78,58 +78,5 @@ describe('Message Events Library', function() {
});
});
});

describe('Ingest Tests', function(){
describe('search Method', function() {
it('should call client get method with the appropriate parameters', function() {
var options = {
events: 'success,error',
event_ids: '1169451c-0958-4704-a89d-538d3ba55f09,0109c92a-1b3d-4ba2-a300-d057de905305',
from: '2015-11-14T16:15',
batch_ids: '0a0b1358-0293-410d-1b78-e6ac3922a87,38cd32c7-2677-4602-a0a5-a25312c006d4',
retryable: true,
cursor: 'initial',
page: 1,
per_page: 5,
timezone: 'America/New_York',
to: '2016-11-14T16:15',
subaccounts: '123,456'
};
return events.message.search(options, callback)
.then(function() {
Object.keys(options).forEach(function(key) {
expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]);
});
expect(client.get.firstCall.args[1]).to.equal(callback);
});
});

it('should accept arrays as parameters where appropriate', function() {
var arroptions = {
events: ['success','error'],
event_ids: ['1169451c-0958-4704-a89d-538d3ba55f09','0109c92a-1b3d-4ba2-a300-d057de905305'],
from: '2015-11-14T16:15',
batch_ids: ['0a0b1358-0293-410d-1b78-e6ac3922a87','38cd32c7-2677-4602-a0a5-a25312c006d4'],
retryable: true,
cursor: 'initial',
page: 1,
per_page: 5,
timezone: 'America/New_York',
to: '2016-11-14T16:15',
subaccounts: ['123','456']
};
return events.message.search(arroptions)
.then(function() {
Object.keys(arroptions).forEach(function(key) {
var opt = arroptions[key]
, firstCallQS = client.get.firstCall.args[0].qs;
if (Array.isArray(opt)) {
expect(firstCallQS).to.have.property(key).and.equal(opt.toString());
}
});
});
});
});
})

});

0 comments on commit e817882

Please sign in to comment.