public Connection<Album> getAlbums(Optional<String> paginationToken) { ArrayList<Parameter> parameters = new ArrayList<>(); parameters.add(Parameter.with("fields", "description,name")); paginationToken.ifPresent(token -> parameters.add(Parameter.with("after", token))); return client.fetchConnection("me/albums", Album.class, parameters.toArray(new Parameter[0])); }
/** * Factory method which provides an instance with the given {@code name} and {@code value}, using the provided * {@code jsonMapper} to turn {@code value} into a JSON string. * <p> * The {@code value} parameter is often a {@link String} or primitive type like {@link Integer}, but you may pass in a * {@link java.util.List}, {@link java.util.Map}, or your own <tt>@Facebook</tt>-annotated Javabean and it will be * converted to JSON automatically. See the "attachment" section of * <a href="http://wiki.developers.facebook.com/index.php/Stream.publish">the stream.publish API documentation</a> for * an example of where this is useful. * * @param name * The parameter name. * @param value * The parameter value. * @param jsonMapper * The jsonMapper * @return A {@code Parameter} instance with the given {@code name} and {@code value}. * @throws IllegalArgumentException * If {@code name} or {@code value} is {@code null} or a blank string. * @throws FacebookJsonMappingException * If an error occurs when converting {@code value} to JSON. */ public static Parameter with(String name, Object value, JsonMapper jsonMapper) { return new Parameter(name, value, jsonMapper); }
/** * Factory method which provides an instance with the given {@code name} and * {@code value}, using the provided {@code jsonMapper} to turn {@code value} * into a JSON string. * <p/> * The {@code value} parameter is often a {@link String} or primitive type * like {@link Integer}, but you may pass in a {@link java.util.List}, * {@link java.util.Map}, or your own <tt>@Facebook</tt>-annotated Javabean * and it will be converted to JSON automatically. See the "attachment" * section of <a * href="http://wiki.developers.facebook.com/index.php/Stream.publish">the * stream.publish API documentation</a> for an example of where this is * useful. * * @param name The parameter name. * @param value The parameter value. * @return A {@code Parameter} instance with the given {@code name} and * {@code value}. * @throws IllegalArgumentException If {@code name} or {@code value} is {@code null} or a blank * string. * @throws com.restfb.exception.FacebookJsonMappingException * If an error occurs when converting {@code value} to JSON. */ public static Parameter with(String name, Object value, JsonMapper jsonMapper) { return new Parameter(name, value, jsonMapper); }
public Connection<Photo> getPhotos(String albumId, Optional<String> paginationToken) { ArrayList<Parameter> parameters = new ArrayList<>(); parameters.add(Parameter.with("fields", "name,images")); paginationToken.ifPresent(token -> parameters.add(Parameter.with("after", token))); return client.fetchConnection( String.format("%s/photos", albumId), Photo.class, parameters.toArray(new Parameter[0])); } }
@Override public void removeDomainWhitelisting(List<String> urls) throws FacebookException { requireNonNull(urls, "'urls' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.domain_whitelisting), Parameter.with(WHITELISTED_DOMAINS_PARAM_NAME, urls), Parameter.with(DOMAIN_ACTION_TYPE_PARAM_NAME, DomainActionTypeEnum.remove)); }
@Override public void addDomainWhitelisting(List<String> urls) throws FacebookException { requireNonNull(urls, "'urls' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.domain_whitelisting), Parameter.with(WHITELISTED_DOMAINS_PARAM_NAME, urls), Parameter.with(DOMAIN_ACTION_TYPE_PARAM_NAME, DomainActionTypeEnum.add)); }
@Override public void setPersistentMenu(List<CallToAction> callToActions) throws FacebookException { requireNonNull(callToActions, "'callToActions' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions), Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.existing_thread), Parameter.with(CALL_TO_ACTIONS_PARAM_NAME, callToActions)); }
@Override public void setGetStartedButton(CallToAction callToAction) throws FacebookException { requireNonNull(callToAction, "'callToAction' must not be null"); List<CallToAction> callToActions = Arrays.asList(callToAction); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions), Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.new_thread), Parameter.with(CALL_TO_ACTIONS_PARAM_NAME, callToActions)); }
@Override public void setAccountLinkingUrl(String url) throws FacebookException { requireNonNull(url, "'url' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.account_linking), Parameter.with(ACCOUNT_LINKING_URL_PARAM_NAME, url)); }
@Override public void setGreeting(Greeting greeting) throws FacebookException { requireNonNull(greeting, "'greeting' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.greeting), Parameter.with(GREETING_PARAM_NAME, greeting)); }
@Override public void removeGreeting() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.greeting)); }
@Override public SendResponse message(MessagingType type, MessageRecipient recipient, Message message, NotificationTypeEnum notificationType, MessageTag tag) throws FacebookException { requireNonNull(recipient, "'recipient' must not be null"); requireNonNull(message, "'message' must not be null"); return send(type, recipient, notificationType, tag, Parameter.with(MESSAGE_PARAM_NAME, message)); }
@Override public void removeAccountLinkingUrl() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.account_linking)); }
@Override public User getUserProfile(String userId, String fields) throws FacebookException { requireNonNull(userId, "'userId' must not be null"); return facebookClient.fetchObject(userId, User.class, Parameter.with(USER_FIELDS_PARAM_NAME, fields)); }
protected SendResponse send(MessageRecipient recipient, NotificationTypeEnum notificationType, MessageTag tag, Parameter... parameters) { requireNonNull(recipient, "'recipient' must not be null"); List<Parameter> params = new ArrayList<>(); params.add(Parameter.with(RECIPIENT_PARAM_NAME, recipient)); if (notificationType != null) { params.add(Parameter.with(NOTIFICATION_TYPE_PARAM_NAME, notificationType.name())); } if (tag != null) { params.add(Parameter.with(TAG_PARAM_NAME, tag.getTag())); } params.addAll(Arrays.asList(parameters)); return send(params.toArray(new Parameter[params.size()])); }
protected SendResponse send(MessagingType type, MessageRecipient recipient, NotificationTypeEnum notificationType, MessageTag tag, Parameter... parameters) { requireNonNull(type, "'type' must not be null"); requireNonNull(recipient, "'recipient' must not be null"); List<Parameter> params = new ArrayList<>(); params.add(Parameter.with(MESSAGING_TYPE_PARAM_NAME, type.toString())); params.add(Parameter.with(RECIPIENT_PARAM_NAME, recipient)); if (notificationType != null) { params.add(Parameter.with(NOTIFICATION_TYPE_PARAM_NAME, notificationType.name())); } if (tag != null) { params.add(Parameter.with(TAG_PARAM_NAME, tag.getTag())); } params.addAll(Arrays.asList(parameters)); return send(params.toArray(new Parameter[params.size()])); }
@Override public SendResponse senderAction(MessageRecipient recipient, SenderActionEnum senderAction, NotificationTypeEnum notificationType) throws FacebookException { requireNonNull(recipient, "'recipient' must not be null"); requireNonNull(senderAction, "'senderAction' must not be null"); return send(recipient, notificationType, null, Parameter.with(SENDER_ACTION_PARAM_NAME, senderAction.name())); }