本文整理汇总了Java中com.jcabi.http.response.JsonResponse类的典型用法代码示例。如果您正苦于以下问题:Java JsonResponse类的具体用法?Java JsonResponse怎么用?Java JsonResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonResponse类属于com.jcabi.http.response包,在下文中一共展示了JsonResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public List<Team> fetch() throws IOException {
final JsonArray array = this.req.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readArray();
final List<Team> teams = new ArrayList<>();
for(int idx=0; idx<array.size(); idx++) {
teams.add(
new RtTeam(
array.getJsonObject(idx),
this.orga,
this.versionEye
)
);
}
return teams;
}
示例2: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public List<Repository> fetch(final int page) throws IOException {
final JsonArray results = this.req.uri()
.queryParam("page", String.valueOf(page)).back().fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readObject()
.getJsonArray("repos");
final List<Repository> repositories = new ArrayList<>();
for(int idx=0; idx<results.size(); idx++) {
repositories.add(
new RtRepository(results.getJsonObject(idx), this.req)
);
}
return repositories;
}
示例3: repository
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public Repository repository(final String repositoryKey)
throws IOException {
return new RtRepository(
this.req.uri()
.path(repositoryKey.replace('.', '~').replace('/', ':'))
.back()
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readObject(),
this.req
);
}
示例4: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public List<Comment> fetch(final int page) throws IOException {
final JsonArray array = this.req.uri()
.queryParam("page", String.valueOf(page)).back().fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readObject()
.getJsonArray("comments");
final List<Comment> comments = new ArrayList<>();
for(int idx=0; idx<array.size(); idx++) {
comments.add(
new RtComment(array.getJsonObject(idx))
);
}
return comments;
}
示例5: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public List<Project> fetch() throws IOException {
final List<Project> projects = new ArrayList<>();
final JsonArray fetched = this.req.uri()
.queryParam("orga_name", this.team.organization().name())
.queryParam("team_name", this.team.name()).back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readArray();
for(int idx = 0; idx<fetched.size(); idx++) {
projects.add(
new RtProject(this.req, this.team, fetched.getJsonObject(idx))
);
}
return projects;
}
示例6: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public List<Favorite> fetch(final int page) throws IOException {
final JsonArray array = this.req.uri()
.queryParam("page", String.valueOf(page)).back().fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readObject()
.getJsonArray("favorites");
final List<Favorite> favorites = new ArrayList<>();
for(int idx=0; idx<array.size(); idx++) {
favorites.add(
new RtFavorite(array.getJsonObject(idx))
);
}
return favorites;
}
示例7: fetchOrgs
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
/**
* Fetches the organizations that the authenticated user
* has access to.
* @return List of organizations.
* @throws IOException If something goes wrong when
* making the HTTP call.
*/
private List<Organization> fetchOrgs() throws IOException {
final JsonArray orgs = this.req.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readArray();
final List<Organization> organizations = new ArrayList<>();
for(int idx=0; idx<orgs.size(); idx++) {
organizations.add(
new RtOrganization(
orgs.getJsonObject(idx), this.req, this.versionEye
)
);
}
return organizations;
}
示例8: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
/**
* Get json Array projects.
* @return Array projects
* @throws Exception If fails
*/
private JsonArray fetch() throws Exception {
if (this.response.get() != null) {
final Optional<Request> next = this.response
.get()
.as(PaginationResponse.class)
.next();
if (next.has()) {
this.response.set(
next.value().fetch()
);
} else {
throw new NoSuchElementException();
}
} else {
this.response.set(this.req.fetch());
}
return this.response.get()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readObject()
.getJsonArray(name);
}
示例9: follow
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
/**
* Follow link.
* @param pointer Page's pointer
* @return The same object
* @throws IOException If fails
*/
private Optional<Request> follow(final String pointer) throws IOException {
final String link = this.response
.as(JsonResponse.class)
.json()
.readObject()
.getString(pointer, "");
final Optional<Request> request;
if (link.isEmpty()) {
request = new Optional.Empty<>();
} else {
request = new Optional.Single<>(
new RestResponse(this).jump(URI.create(link))
);
}
return request;
}
示例10: fetch
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
public List<JsonObject> fetch() throws IOException {
List<JsonObject> filtered = new ArrayList<JsonObject>();
JsonArray notifications = this.request().fetch()
.as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class).json().readArray();
this.lastReadAt = DateFormatUtils.formatUTC(
new Date(System.currentTimeMillis()),
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
log.info("Found " + notifications.size() + " new notifications!");
if(notifications.size() > 0) {
List<JsonObject> unfiltered = new ArrayList<JsonObject>();
for(int i=0; i<notifications.size(); i++) {
unfiltered.add(notifications.getJsonObject(i));
}
filtered = this.reason.filter(unfiltered);
}
return filtered;
}
示例11: main
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
/**
* Main entry point.
* @param args Command line arguments
*/
public static void main(final String[] args) throws Exception {
final Github github = new RtGithub();
final JsonResponse resp = github.entry()
.uri().path("/search/repositories")
.queryParam("q", "java").back()
.fetch()
.as(JsonResponse.class);
final List<JsonObject> items = resp.json().readObject()
.getJsonArray("items")
.getValuesAs(JsonObject.class);
for (final JsonObject item : items) {
System.out.println(
String.format(
"repository found: %s",
item.get("full_name").toString()
)
);
}
}
示例12: create
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
@NotNull(message = "Hook is never NULL")
public Hook create(
@NotNull(message = "name can't be NULL") final String name,
@NotNull(message = "config can't be NULL")
final Map<String, String> config,
final boolean active
) throws IOException {
final JsonObjectBuilder builder = Json.createObjectBuilder();
for (final Map.Entry<String, String> entr : config.entrySet()) {
builder.add(entr.getKey(), entr.getValue());
}
final JsonStructure json = Json.createObjectBuilder()
.add("name", name)
.add("config", builder)
.add("active", active)
.build();
return this.get(
this.request.method(Request.POST)
.body().set(json).back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED)
.as(JsonResponse.class)
.json().readObject().getInt("id")
);
}
示例13: create
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
@NotNull(message = "release is never NULL")
public Release create(
@NotNull(message = "tag can't be NULL") final String tag
) throws IOException {
final JsonStructure json = Json.createObjectBuilder()
.add("tag_name", tag)
.build();
return this.get(
this.request.method(Request.POST)
.body().set(json).back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED)
.as(JsonResponse.class)
.json().readObject().getInt("id")
);
}
示例14: create
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
@NotNull(message = "DeployKey is never NULL")
public DeployKey create(
@NotNull(message = "title can't be NULL") final String title,
@NotNull(message = "key can't be NULL") final String key
)
throws IOException {
return this.get(
this.request.method(Request.POST)
.body().set(
Json.createObjectBuilder()
.add("title", title)
.add("key", key)
.build()
).back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED)
.as(JsonResponse.class)
.json().readObject().getInt("id")
);
}
示例15: create
import com.jcabi.http.response.JsonResponse; //导入依赖的package包/类
@Override
@NotNull(message = "public key is never NULL")
public PublicKey create(
@NotNull(message = "title key can't be NULL") final String title,
@NotNull(message = "key can't be NULL") final String key
) throws IOException {
return this.get(
this.request.method(Request.POST)
.body().set(
Json.createObjectBuilder()
.add("title", title)
.add("key", key)
.build()
).back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED)
.as(JsonResponse.class)
.json().readObject().getInt("id")
);
}