@Override public Map<String, String> get() { ListLabelsResponse response = null; try { response = getOrCreateGmail(authData).users().labels().list(USER).execute(); } catch (IOException e) { throw new RuntimeException("Unable to list labels for user", e); } ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (Label label : response.getLabels()) { // TODO: remove system labels builder.put(label.getName(), label.getId()); } return builder.build(); } };
/** Creates the given {@code labelName} in the import service provider and returns the id. */ private String createImportedLabelId(TokensAndUrlAuthData authData, String labelName) throws IOException { Label newLabel = new Label() .setName(labelName) .setLabelListVisibility("labelShow") .setMessageListVisibility("show"); return getOrCreateGmail(authData).users().labels().create(USER, newLabel).execute().getId(); }
@Override public void onSuccess( Label label, HttpHeaders responseHeaders) throws IOException { labelIdToNameMap.put(label.getId(), label.getName()); } });
/** * Updates the specified label. * * Create a request for the method "labels.update". * * This request holds the parameters needed by the the gmail server. After setting any optional * parameters, call the {@link Update#execute()} method to invoke the remote operation. <p> {@link * Update#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must * be called to initialize this instance immediately after invoking the constructor. </p> * * @param userId The user's email address. The special value me can be used to indicate the authenticated user. * [default: me] * @param id The ID of the label to update. * @param content the {@link com.google.api.services.gmail.model.Label} * @since 1.13 */ protected Update(java.lang.String userId, java.lang.String id, com.google.api.services.gmail.model.Label content) { super(Gmail.this, "PUT", REST_PATH, content, com.google.api.services.gmail.model.Label.class); this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified."); this.id = com.google.api.client.util.Preconditions.checkNotNull(id, "Required parameter id must be specified."); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getId(), "Label.getId()"); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getLabelListVisibility(), "Label.getLabelListVisibility()"); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getMessageListVisibility(), "Label.getMessageListVisibility()"); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getName(), "Label.getName()"); }