33[ ![ LGPL-2.1] ( https://img.shields.io/badge/License-LGPL--2.1-blue.svg )] ( https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt )
44[ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg )] ( https://search.maven.org/artifact/cn.vika/vika-client )
55[ ![ Build] ( https://www.travis-ci.com/vikadata/vika.java.svg?branch=master )] ( https://www.travis-ci.com/github/vikadata/vika.java )
6- [ ![ JavaDoc] ( https://javadoc.io/badge2/cn.vika/vika.java/javadoc.io.svg )] ( https://javadoc.io/doc/cn.vika/vika.java )
6+ [ ![ JavaDoc] ( https://javadoc.io/badge2/cn.vika/vika.java/javadoc.io.svg )] ( https://javadoc.io/doc/cn.vika/vika-client )
77
88[ github_issues ] :https://github.com/vikadata/vika.java/issues
99[ github_issues_new ] :https://github.com/vikadata/vika.java/issues/new
1515Vikadata&trade ; Java API (* vika.java* ) provides a full featured and easy to consume Java
1616library for working with vikadata via the Vikadata OpenAPI.<br />
1717
18- ---
18+ ---
1919
2020## Usage
2121
@@ -56,7 +56,7 @@ simple as:
5656First, you need to set api credential which belong your personal api key.
5757
5858``` java
59- ApiCredential credential= new ApiCredential (" Your API Key" );
59+ ApiCredential credential = new ApiCredential (" Your API Key" );
6060```
6161
6262Then, Init client instance
@@ -65,7 +65,7 @@ Then, Init client instance
6565VikaApiClient vikaApiClient = new VikaApiClient (credential);
6666```
6767
68- By default, the API client has been added for setting connect and read timeouts, you can also change:
68+ By default, the API client has been added for setting connect and read timeouts, you can also change:
6969
7070``` java
7171// Set the connect timeout to 8 second and the read timeout to 9 seconds
@@ -142,6 +142,9 @@ Pager<Record> pager = vikaApiClient.getRecordApi().getRecords("datasheet_id", qu
142142
143143Class `` RecordMap `` is a key-value structure like `` Map<String, Object> `` , all thing you do is converting json to map, you can use convert util from sdk provide which is named `` JacksonConverter `` , you also can use jackson api build json structure data, more detail please reference unit test.
144144
145+ you can add record through two difference way, ` id ` or ` name ` , default is ` name ` fieldKey.
146+
147+ using default fieldKey ` name ` example:
145148``` java
146149// Build Record Map by jackson api
147150ObjectNode fieldMap = JsonNodeFactory . instance. objectNode()
@@ -157,26 +160,74 @@ ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode().add(fields);
157160// convert json to Map List
158161List<RecordMap > recordMaps = JacksonConverter . unmarshalToList(RecordMap . class, arrayNode);
159162// create record request
160- CreateRecordRequest recordRequest = new CreateRecordRequest (). withRecords(recordMaps);
163+ CreateRecordRequest recordRequest = new CreateRecordRequest ()
164+ .withRecords(recordMaps);
165+ // ok
166+ List<Record > newRecords = vikaApiClient. getRecordApi(). addRecords(" datasheet_id" , recordRequest);
167+ ```
168+
169+ using fieldKey ` id ` example:
170+ ``` java
171+ // Build Record Map by jackson api
172+ ObjectNode fieldMap = JsonNodeFactory . instance. objectNode()
173+ // simple data
174+ .put(" fld_id" , " string" )
175+ .put(" fld_id" , 1234 );
176+ // sub tree node
177+ .set(" fld_id" , JsonNodeFactory . instance. arrayNode(). add(" NewYork" ). add(" Bejing" ));
178+ // put record map into fields key
179+ ObjectNode fields = JsonNodeFactory . instance. objectNode(). set(" fields" , fieldMap);
180+ // only one record, warp record into array node
181+ ArrayNode arrayNode = JsonNodeFactory . instance. arrayNode(). add(fields);
182+ // convert json to Map List
183+ List<RecordMap > recordMaps = JacksonConverter . unmarshalToList(RecordMap . class, arrayNode);
184+ // create record request
185+ CreateRecordRequest recordRequest = new CreateRecordRequest ()
186+ .withRecords(recordMaps)
187+ .withFieldKey(FieldKey . ID );
161188// ok
162189List<Record > newRecords = vikaApiClient. getRecordApi(). addRecords(" datasheet_id" , recordRequest);
163190```
164191
165192#### ** Update Record**
166193
194+ update record also provide two difference way to modifying data, using fieldKey ` id ` or ` name ` , default is ` name ` fieldKey.
195+
196+ using default fieldKey ` name ` example:
197+
167198``` java
168199// Build update record model
169200UpdateRecord record = new UpdateRecord ()
170201 // row record id from query result or add record result
171202 .withRecordId(" recXXXXX" )
172- // single-text type field cell
203+ // single-text type field cell
173204 .withField(" SingleText" , " ABC" )
174- // single-select type field cell,
205+ // single-select type field cell,
175206 // it can be set null or empty array if you want to clear field value: withField("Options", null)
176207 .withField(" Options" , Arrays . asList(" LL" , " NN" ));
177208// new Request model
178209UpdateRecordRequest updateRecordRequest = new UpdateRecordRequest ()
179- .withRecords(Collections . singletonList(record));
210+ .withRecords(Collections . singletonList(record));
211+ // request send
212+ List<Record > updateRecords = vikaApiClient. getRecordApi(). updateRecords(" datasheet_id" , updateRecordRequest);
213+ ```
214+
215+ using fieldKey ` id ` example:
216+
217+ ``` java
218+ // Build update record model
219+ UpdateRecord record = new UpdateRecord ()
220+ // row record id from query result or add record result
221+ .withRecordId(" recXXXXX" )
222+ // single-text type field cell
223+ .withField(" fld_id" , " ABC" )
224+ // single-select type field cell,
225+ // it can be set null or empty array if you want to clear field value: withField("Options", null)
226+ .withField(" fld_id" , Arrays . asList(" LL" , " NN" ));
227+ // new Request model
228+ UpdateRecordRequest updateRecordRequest = new UpdateRecordRequest ()
229+ .withRecords(Collections . singletonList(record))
230+ .withFieldKey(FieldKey . ID );
180231// request send
181232List<Record > updateRecords = vikaApiClient. getRecordApi(). updateRecords(" datasheet_id" , updateRecordRequest);
182233```
0 commit comments