@@ -910,27 +910,38 @@ your account, each with a user-specified name and a uniquely-assigned ID.
910910
911911Use ` createStyleRule() ` to create a new style rule. You must specify a name and
912912language code. You may optionally provide configured rules and custom
913- instructions:
913+ instructions. Configured rules are a ` Map<String, Map<String, String>> ` from
914+ category to rule to value, in the API's snake_case form (for example
915+ ` "dates_and_times" ` → ` "calendar_era" ` → ` "use_bc_and_ad" ` ), and are sent as
916+ given, so new categories and rules can be used as soon as the API supports
917+ them. The last argument is a ` CreateStyleRuleOptions ` object or ` null ` ; its
918+ ` setExtraBodyParameters() ` adds further body parameters, sent last. The
919+ overload taking a ` ConfiguredRules ` object is deprecated; use the ` Map `
920+ overload instead.
914921
915922``` java
916923class Example { // Continuing class Example from above
917924 public void createStyleRuleExample () throws Exception {
918925 // Create a simple style rule
919- StyleRuleInfo rule = client. createStyleRule(" My Style" , " en" , null , null );
926+ StyleRuleInfo rule = client. createStyleRule(" My Style" , " en" , null , null , null );
920927 System . out. println(" Created: " + rule. getStyleId());
921928
922- // Create with custom instructions
929+ // Create with configured rules and custom instructions
930+ Map<String , Map<String , String > > configuredRules = new HashMap<> ();
931+ configuredRules. put(" dates_and_times" ,
932+ Collections . singletonMap(" calendar_era" , " use_bc_and_ad" ));
923933 List<CustomInstruction > instructions = new ArrayList<> ();
924934 instructions. add(new CustomInstruction (" Formal tone" , " Use formal language" , null ));
925935 StyleRuleInfo ruleWithInstructions = client. createStyleRule(
926- " Formal Style" , " en" , null , instructions);
936+ " Formal Style" , " en" , configuredRules , instructions, null );
927937 }
928938}
929939```
930940
931941#### Retrieving and listing style rules
932942
933- ` getStyleRule() ` retrieves a single style rule by its ID. ` getAllStyleRules() `
943+ ` getStyleRule() ` retrieves a single style rule by its ID or ` StyleRuleInfo `
944+ object. ` getAllStyleRules() `
934945returns a list of ` StyleRuleInfo ` objects corresponding to all of your stored
935946style rules. The method accepts optional parameters: ` page ` (page number for
936947pagination, 0-indexed), ` pageSize ` (number of items per page), and ` detailed ` .
@@ -966,7 +977,18 @@ class Example { // Continuing class Example from above
966977#### Updating a style rule
967978
968979Use ` updateStyleRuleName() ` to rename a style rule, and
969- ` updateStyleRuleConfiguredRules() ` to replace its configured rules:
980+ ` updateStyleRuleConfiguredRules() ` to replace its configured rules. The
981+ configured rules are a ` Map<String, Map<String, String>> ` sent as given as the
982+ request body; the overload taking a ` ConfiguredRules ` object is deprecated.
983+ Both methods have overloads that take an options object
984+ (` UpdateStyleRuleNameOptions ` , ` UpdateStyleRuleConfiguredRulesOptions ` ) whose
985+ extra body parameters are sent last; for configured rules they are added to the
986+ body as further top-level keys.
987+
988+ Every method that takes a style rule ID (` getStyleRule() ` ,
989+ ` updateStyleRuleName() ` , ` updateStyleRuleConfiguredRules() ` , ` deleteStyleRule() `
990+ and the custom instruction methods) also accepts a ` StyleRuleInfo ` object. IDs
991+ are URL-encoded in the request path.
970992
971993``` java
972994class Example { // Continuing class Example from above
@@ -977,18 +999,31 @@ class Example { // Continuing class Example from above
977999 StyleRuleInfo updated = client. updateStyleRuleName(styleId, " New Name" );
9781000 System . out. println(" Updated name: " + updated. getName());
9791001
980- // Update configured rules
981- ConfiguredRules configuredRules = new ConfiguredRules ();
1002+ // Rename, passing the StyleRuleInfo object and extra body parameters
1003+ client. updateStyleRuleName(updated, " Newer Name" ,
1004+ new UpdateStyleRuleNameOptions (). setExtraBodyParameters(
1005+ Collections . singletonMap(" param" , " value" )));
1006+
1007+ // Replace the configured rules
1008+ Map<String , Map<String , String > > configuredRules = new HashMap<> ();
1009+ configuredRules. put(" punctuation" ,
1010+ Collections . singletonMap(" periods_in_academic_degrees" , " do_not_use" ));
9821011 StyleRuleInfo updatedRules = client. updateStyleRuleConfiguredRules(
983- styleId, configuredRules);
1012+ styleId, configuredRules, null );
9841013 }
9851014}
9861015```
9871016
9881017#### Managing custom instructions
9891018
9901019Custom instructions can be created, retrieved, updated, and deleted individually
991- within a style rule:
1020+ within a style rule. The style rule can be given as an ID or a ` StyleRuleInfo `
1021+ object, and the custom instruction as an ID or a ` CustomInstruction ` object.
1022+ ` createStyleRuleCustomInstruction() ` and ` updateStyleRuleCustomInstruction() `
1023+ have overloads that take an options object
1024+ (` CreateStyleRuleCustomInstructionOptions ` ,
1025+ ` UpdateStyleRuleCustomInstructionOptions ` ) whose extra body parameters are sent
1026+ last:
9921027
9931028``` java
9941029class Example { // Continuing class Example from above
@@ -1009,8 +1044,8 @@ class Example { // Continuing class Example from above
10091044 CustomInstruction updated = client. updateStyleRuleCustomInstruction(
10101045 styleId, instructionId, " Updated label" , " Updated prompt" , null );
10111046
1012- // Delete the custom instruction
1013- client. deleteStyleRuleCustomInstruction(styleId, instructionId );
1047+ // Delete the custom instruction, passing the object instead of its ID
1048+ client. deleteStyleRuleCustomInstruction(styleId, updated );
10141049 }
10151050}
10161051```
0 commit comments