Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
added builder for edit profile request (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taz03 authored Nov 12, 2023
1 parent bf9b6be commit 765a70e
Showing 1 changed file with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package io.github.taz03.jia.requests.accounts;

import java.util.HashMap;
import java.util.Map;

import io.github.taz03.jia.requests.InstagramPostRequest;
import io.github.taz03.jia.responses.users.UserResponse;

/**
* Represents an Instagram edit profile request, used to edit profile data such as username, phone number, etc.
* Represents an Instagram edit profile request, used to edit profile data such as username, bio, external url, etc.
*/
public final class EditProfileRequest extends InstagramPostRequest<UserResponse> {
/**
* Creates an Instagram edit profile request.
* <p>
* At least one connected contact is necessary to edit profile data.
* <br>
* At least one connected contact is necessary to edit profile data. Other values are optional, can be set to `null`.
*
* @param username New username to set
* @param name New display name to set
Expand All @@ -22,15 +23,63 @@ public final class EditProfileRequest extends InstagramPostRequest<UserResponse>
* @param phoneNumber Current phone number
* @param email Current email
*/
public EditProfileRequest(String username, String name, String biography, String externalUrl, boolean showFbLinkOnProfile, String phoneNumber, String email) {
super(UserResponse.class, "/api/v1/accounts/edit_profile/", null, Map.of(
"username", username,
"first_name", name,
"biography", biography,
"external_url", externalUrl,
"show_fb_link_on_profile", showFbLinkOnProfile,
"phone_number", phoneNumber,
"email", email
));
public EditProfileRequest(String username, String name, String biography, String externalUrl, Boolean showFbLinkOnProfile, String phoneNumber, String email) {
super(UserResponse.class, "/api/v1/accounts/edit_profile/", null, makePayload(username, name, biography, externalUrl, showFbLinkOnProfile, phoneNumber, email));
}

private static Map<String, Object> makePayload(String username, String name, String biography, String externalUrl, Boolean showFbLinkOnProfile, String phoneNumber, String email) {
Map<String, Object> payload = new HashMap<>();

if (username != null) payload.put("username", username);
if (name != null) payload.put("first_name", name);
if (biography != null) payload.put("biography", biography);
if (externalUrl != null) payload.put("external_url", externalUrl);
if (showFbLinkOnProfile != null) payload.put("show_fb_link_on_profile", showFbLinkOnProfile);
if (phoneNumber != null) payload.put("phone_number", phoneNumber);
if (email != null) payload.put("email", email);

return payload;
}

public static class EditProfileRequestBuilder {
private String username;
private String name;
private String biography;
private String externalUrl;
private Boolean showFbLinkOnProfile;
private String phoneNumber;
private String email;

public void setUsername(String username) {
this.username = username;
}

public void setName(String name) {
this.name = name;
}

public void setBiography(String biography) {
this.biography = biography;
}

public void setExternalUrl(String externalUrl) {
this.externalUrl = externalUrl;
}

public void setShowFbLinkOnProfile(Boolean showFbLinkOnProfile) {
this.showFbLinkOnProfile = showFbLinkOnProfile;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public void setEmail(String email) {
this.email = email;
}

public EditProfileRequest build() {
return new EditProfileRequest(username, name, biography, externalUrl, showFbLinkOnProfile, phoneNumber, email);
}
}
}

0 comments on commit 765a70e

Please sign in to comment.