]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/jsonrpc/JsonRpcRequest.java
Extend updateContact command with nick given/family name and note
[signal-cli] / src / main / java / org / asamk / signal / jsonrpc / JsonRpcRequest.java
1 package org.asamk.signal.jsonrpc;
2
3 import com.fasterxml.jackson.annotation.JsonInclude;
4 import com.fasterxml.jackson.databind.node.ContainerNode;
5 import com.fasterxml.jackson.databind.node.ValueNode;
6
7 /**
8 * Represents a JSON-RPC request.
9 * <a href="https://www.jsonrpc.org/specification#request_object">https://www.jsonrpc.org/specification#request_object</a>
10 */
11 public final class JsonRpcRequest extends JsonRpcMessage {
12
13 /**
14 * A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
15 */
16 private String jsonrpc;
17
18 /**
19 * A String containing the name of the method to be invoked.
20 * Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46)
21 * are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else.
22 */
23 private String method;
24
25 /**
26 * A Structured value that holds the parameter values to be used during the invocation of the method.
27 * This member MAY be omitted.
28 */
29 @JsonInclude(JsonInclude.Include.NON_NULL)
30 private ContainerNode<?> params;
31
32 /**
33 * An identifier established by the Client that MUST contain a String, Number, or NULL value if included.
34 * If it is not included it is assumed to be a notification.
35 * The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts
36 */
37 @JsonInclude(JsonInclude.Include.NON_NULL)
38 private ValueNode id;
39
40 public static JsonRpcRequest forNotification(
41 final String method,
42 final ContainerNode<?> params,
43 final ValueNode id
44 ) {
45 return new JsonRpcRequest("2.0", method, params, id);
46 }
47
48 private JsonRpcRequest() {
49 }
50
51 private JsonRpcRequest(
52 final String jsonrpc,
53 final String method,
54 final ContainerNode<?> params,
55 final ValueNode id
56 ) {
57 this.jsonrpc = jsonrpc;
58 this.method = method;
59 this.params = params;
60 this.id = id;
61 }
62
63 public String getJsonrpc() {
64 return jsonrpc;
65 }
66
67 public String getMethod() {
68 return method;
69 }
70
71 public ContainerNode<?> getParams() {
72 return params;
73 }
74
75 public ValueNode getId() {
76 return id;
77 }
78 }