UNPKG

6.26 kBMarkdownView Raw
1# ADP Core API
2
3* [Core](#core)
4 * [consumerApplicationInstance](#consumerapplicationinstance)
5
6* [ConsumerApplicationInstance](#consumer-application-instance)
7 * [createEvent](#createevent)
8 * [exec](#exec)
9 * [getData](#getdata)
10 * [getEventRules](#geteventrules)
11 * [getNextEvent](#getnextevent)
12 * [getConnection](#getconnection)
13 * [getConsumerApplication](#getconsumerapplication)
14 * [saveEvent](#saveevent)
15
16# Core
17
18## consumerApplicationInstance
19---
20#### Description
21Create consumer application instance. This is the entry point for calling ADP APIs.
22
23#### Params
24* ADP Connection Instance {Object}
25* Configuration Path {String}
26
27#### Example
28
29```js
30import adpConnection from 'adp-connection';
31import adpCore from 'adp-core';
32import config from './config';
33
34const connectionOpts = config.get('connection');
35const conn = adpConnection.createConnection(connectionOpts);
36
37// conn.connect ...
38
39const configPath = __dirname + './config.zip';
40const app = adpCore.consumerApplicationInstance(conn, configPath);
41```
42
43---
44---
45---
46---
47# Consumer Application Instance
48
49## createEvent
50---
51#### Description
52Use this method to obtain a valid payload related to the requested methodName. The payload will be returned with an `eventId` property. *This property **must not** be deleted*. This payload will be returned with defaulted values -- some of which are `DEFAULT_STRING`, `DEFAULT_NUMBER`, `DEFAULT_BOOLEAN`. Properties which are contain these defalut values are **automatically** deleted upon save (`saveEvent`).
53
54#### Params
55* Options {Object} - Object containing `methodName` property.
56* Callback {Function} - Callback to be executed once event is initialized.
57
58#### Example
59
60```js
61const app = adpCore.consumerApplicationInstance(conn, configPath);
62const eventOpts = {
63 methodName: 'event.core.v1.legal.name.change'
64};
65const eventCreated = (err, payload) => {
66 // business logic.
67};
68app.createEvent(eventOpts, eventCreated);
69```
70
71## exec
72---
73###### alias: [getData](#getData)
74
75#### Description
76Use this method to execute non-event driven API requests. Ideal for HTTP `DELETE` requests.
77
78#### Params
79* MethodName {String} - API Method name property.
80* Options {Object} - Object literal containing key value pairs. Should contain any URI replacements or `payload` property in the case of saving an event.
81* Callback {Function} - Callback to be executed once response is received.
82
83#### Example
84
85```js
86const app = adpCore.consumerApplicationInstance(conn, configPath);
87const methodName = 'hr.v2.worker.associateoid';
88const execOpts = {
89 associateoid: '0000000000000000'
90};
91const handleResponse = (err, payload) => {
92 // business logic.
93};
94app.exec(methodName, execOpts, handleResponse);
95```
96
97## getData
98---
99#### Description
100Use this method to execute non-event driven API requests. Ideal for HTTP `GET` requests.
101
102#### Params
103* MethodName {String} - API Method name property.
104* Options {Object} - Object literal containing key value pairs. Should contain any URI replacements or `payload` property in the case of saving an event.
105* Callback {Function} - Callback to be executed once data is received.
106
107#### Example
108
109```js
110const app = adpCore.consumerApplicationInstance(conn, configPath);
111const methodName = 'hr.v2.worker.associateoid';
112const execOpts = {
113 associateoid: '0000000000000000'
114};
115const handleResponse = (err, payload) => {
116 // business logic.
117};
118app.getData(methodName, execOpts, handleResponse);
119```
120
121## getEventRules
122---
123
124#### Description
125Use this method to obtain validation rules for a given event (methodName). These event rules can be used to implement client validations.
126
127#### Params
128* Options {Object} - Object containing `methodName` property.
129* Callback {Function} - Callback to be executed once event rules are available.
130
131#### Example
132
133```js
134const app = adpCore.consumerApplicationInstance(conn, configPath);
135const eventOpts = {
136 methodName: 'event.core.v1.legal.name.change'
137};
138const rulesReceived = (err, rules) => {
139 // implement client validations.
140};
141app.getEventRules(eventOpts, rulesReceived);
142```
143
144## getNextEvent
145---
146#### Description
147Use this method to obtain the next event notification on your application message queue. The messages are returned as JSON.
148
149#### Params
150* Callback {Function} - Callback to be executed once event is initialized.
151
152#### Example
153
154```js
155const app = adpCore.consumerApplicationInstance(conn, configPath);
156const completed = (err, eventMessage) => {
157 // handle event notification message.
158};
159app.getNextEvent(eventOpts, completed);
160```
161
162## getConnection
163---
164#### Description
165Use this method to obtain the connection object used by the consumer application instance object.
166
167#### Params
168* None
169
170#### Example
171
172```js
173const app = adpCore.consumerApplicationInstance(conn, configPath);
174const conn = app.getConnection();
175```
176
177
178## getConsumerApplication
179-----------
180#### Description
181Use this method to obtain the consumer application instance config JSON object.
182
183#### Params
184* None
185
186### Returns
187* appConfig {Object} - Object representing the consumer application configuration object.
188
189#### Example
190
191```js
192const app = adpCore.consumerApplicationInstance(conn, configPath);
193const appConfig = app.getConsumerApplication();
194```
195
196## saveEvent
197---
198#### Description
199This is a companion method to `createEvent`. This method must use the `payload` returned by `createEvent` method. The payload object should be populated with desired fields and then passed to `saveEvent`.
200
201##### Examining results
202The result set will be either validation errors or a successful save body.
203
204#### Params
205* Payload {Object} - JSON Object returned by `createEvent` with desired updates.
206* Callback {Function} - Callback to be executed once event is saved.
207
208#### Example
209
210```js
211const app = adpCore.consumerApplicationInstance(conn, configPath);
212const eventCreated = (err, payload) => {
213 payload.events[0].data.eventContext.associateOID = '0000000000000000';
214 payload.events[0].data.transform.worker.person.legalName.givenName = 'Doe';
215 app.saveEvent(payload, eventSaved);
216};
217const eventSaved = (err, results) => {
218 // business logic.
219};
220const eventOpts = {
221 methodName: 'event.core.v1.legal.name.change'
222};
223app.createEvent(eventOpts, eventCreated)
224```
225