forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGHGistBuilder.java
More file actions
78 lines (70 loc) · 1.82 KB
/
Copy pathGHGistBuilder.java
File metadata and controls
78 lines (70 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.kohsuke.github;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import javax.annotation.Nonnull;
/**
* Builder pattern for creating a new Gist.
*
* @author Kohsuke Kawaguchi
* @see GitHub#createGist() GitHub#createGist()
*/
public class GHGistBuilder {
private final Requester req;
private final LinkedHashMap<String, Object> files = new LinkedHashMap<String, Object>();
/**
* Instantiates a new Gh gist builder.
*
* @param root
* the root
*/
public GHGistBuilder(GitHub root) {
req = root.createRequest().method("POST");
}
/**
* Description gh gist builder.
*
* @param desc
* the desc
* @return the gh gist builder
*/
public GHGistBuilder description(String desc) {
req.with("description", desc);
return this;
}
/**
* Public gh gist builder.
*
* @param v
* the v
* @return the gh gist builder
*/
public GHGistBuilder public_(boolean v) {
req.with("public", v);
return this;
}
/**
* File gh gist builder.
*
* @param fileName
* the file name
* @param content
* the content
* @return Adds a new file.
*/
public GHGistBuilder file(@Nonnull String fileName, @Nonnull String content) {
files.put(fileName, Collections.singletonMap("content", content));
return this;
}
/**
* Creates a Gist based on the parameters specified thus far.
*
* @return created Gist
* @throws IOException
* if Gist cannot be created.
*/
public GHGist create() throws IOException {
req.with("files", files);
return req.withUrlPath("/gists").fetch(GHGist.class);
}
}