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
|
21 | Create 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
|
30 | import adpConnection from 'adp-connection';
|
31 | import adpCore from 'adp-core';
|
32 | import config from './config';
|
33 |
|
34 | const connectionOpts = config.get('connection');
|
35 | const conn = adpConnection.createConnection(connectionOpts);
|
36 |
|
37 | // conn.connect ...
|
38 |
|
39 | const configPath = __dirname + './config.zip';
|
40 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
41 | ```
|
42 |
|
43 | ---
|
44 | ---
|
45 | ---
|
46 | ---
|
47 | # Consumer Application Instance
|
48 |
|
49 | ## createEvent
|
50 | ---
|
51 | #### Description
|
52 | Use 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
|
61 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
62 | const eventOpts = {
|
63 | methodName: 'event.core.v1.legal.name.change'
|
64 | };
|
65 | const eventCreated = (err, payload) => {
|
66 | // business logic.
|
67 | };
|
68 | app.createEvent(eventOpts, eventCreated);
|
69 | ```
|
70 |
|
71 | ## exec
|
72 | ---
|
73 | ###### alias: [getData](#getData)
|
74 |
|
75 | #### Description
|
76 | Use 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
|
86 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
87 | const methodName = 'hr.v2.worker.associateoid';
|
88 | const execOpts = {
|
89 | associateoid: '0000000000000000'
|
90 | };
|
91 | const handleResponse = (err, payload) => {
|
92 | // business logic.
|
93 | };
|
94 | app.exec(methodName, execOpts, handleResponse);
|
95 | ```
|
96 |
|
97 | ## getData
|
98 | ---
|
99 | #### Description
|
100 | Use 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
|
110 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
111 | const methodName = 'hr.v2.worker.associateoid';
|
112 | const execOpts = {
|
113 | associateoid: '0000000000000000'
|
114 | };
|
115 | const handleResponse = (err, payload) => {
|
116 | // business logic.
|
117 | };
|
118 | app.getData(methodName, execOpts, handleResponse);
|
119 | ```
|
120 |
|
121 | ## getEventRules
|
122 | ---
|
123 |
|
124 | #### Description
|
125 | Use 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
|
134 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
135 | const eventOpts = {
|
136 | methodName: 'event.core.v1.legal.name.change'
|
137 | };
|
138 | const rulesReceived = (err, rules) => {
|
139 | // implement client validations.
|
140 | };
|
141 | app.getEventRules(eventOpts, rulesReceived);
|
142 | ```
|
143 |
|
144 | ## getNextEvent
|
145 | ---
|
146 | #### Description
|
147 | Use 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
|
155 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
156 | const completed = (err, eventMessage) => {
|
157 | // handle event notification message.
|
158 | };
|
159 | app.getNextEvent(eventOpts, completed);
|
160 | ```
|
161 |
|
162 | ## getConnection
|
163 | ---
|
164 | #### Description
|
165 | Use 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
|
173 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
174 | const conn = app.getConnection();
|
175 | ```
|
176 |
|
177 |
|
178 | ## getConsumerApplication
|
179 | -----------
|
180 | #### Description
|
181 | Use 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
|
192 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
193 | const appConfig = app.getConsumerApplication();
|
194 | ```
|
195 |
|
196 | ## saveEvent
|
197 | ---
|
198 | #### Description
|
199 | This 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
|
202 | The 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
|
211 | const app = adpCore.consumerApplicationInstance(conn, configPath);
|
212 | const 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 | };
|
217 | const eventSaved = (err, results) => {
|
218 | // business logic.
|
219 | };
|
220 | const eventOpts = {
|
221 | methodName: 'event.core.v1.legal.name.change'
|
222 | };
|
223 | app.createEvent(eventOpts, eventCreated)
|
224 | ```
|
225 |
|