diff --git a/twidere/src/main/java/org/mariotaku/twidere/Constants.java b/twidere/src/main/java/org/mariotaku/twidere/Constants.java index dc344233b..312a74e97 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/Constants.java +++ b/twidere/src/main/java/org/mariotaku/twidere/Constants.java @@ -28,7 +28,7 @@ package org.mariotaku.twidere; public interface Constants extends TwidereConstants { public static final String DATABASES_NAME = "twidere.sqlite"; - public static final int DATABASES_VERSION = 69; + public static final int DATABASES_VERSION = 70; public static final int MENU_GROUP_STATUS_EXTENSION = 10; public static final int MENU_GROUP_COMPOSE_EXTENSION = 11; diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java index beed27ba0..c5e9d625f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java @@ -583,7 +583,7 @@ public class ComposeActivity extends BaseSupportDialogActivity implements TextWa mMenuBar.setOnMenuItemClickListener(this); mEditText.setOnEditorActionListener(mPreferences.getBoolean(KEY_QUICK_SEND, false) ? this : null); mEditText.addTextChangedListener(this); - final AccountSelectorAdapter accountAdapter = new AccountSelectorAdapter(this); + final AccountSelectorAdapter accountAdapter = new AccountSelectorAdapter(mMenuBar.getPopupContext()); accountAdapter.addAll(Account.getAccountsList(this, false)); mAccountSelectorPopup = IListPopupWindow.InstanceHelper.getInstance(mMenuBar.getPopupContext()); mAccountSelectorPopup.setInputMethodMode(IListPopupWindow.INPUT_METHOD_NOT_NEEDED); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java index 029673b44..be35d00fb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java @@ -19,12 +19,6 @@ package org.mariotaku.twidere.activity.support; -import static org.mariotaku.twidere.util.CustomTabUtils.findTabIconKey; -import static org.mariotaku.twidere.util.CustomTabUtils.getIconMap; -import static org.mariotaku.twidere.util.CustomTabUtils.getTabConfiguration; -import static org.mariotaku.twidere.util.CustomTabUtils.getTabTypeName; -import static org.mariotaku.twidere.util.UserColorNicknameUtils.getUserNickname; - import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; @@ -32,6 +26,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.graphics.PorterDuff.Mode; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.text.TextUtils; @@ -61,7 +56,6 @@ import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.util.ImageLoaderWrapper; import org.mariotaku.twidere.util.ParseUtils; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; import java.text.Collator; import java.util.Comparator; @@ -69,472 +63,483 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import static org.mariotaku.twidere.util.CustomTabUtils.findTabIconKey; +import static org.mariotaku.twidere.util.CustomTabUtils.getIconMap; +import static org.mariotaku.twidere.util.CustomTabUtils.getTabConfiguration; +import static org.mariotaku.twidere.util.CustomTabUtils.getTabTypeName; +import static org.mariotaku.twidere.util.UserColorNicknameUtils.getUserNickname; + public class CustomTabEditorActivity extends BaseSupportDialogActivity implements OnClickListener { - private ImageLoaderWrapper mImageLoader; - private SharedPreferences mPreferences; + private ImageLoaderWrapper mImageLoader; + private SharedPreferences mPreferences; - private AccountsSpinnerAdapter mAccountsAdapter; - private CustomTabIconsAdapter mTabIconsAdapter; + private AccountsSpinnerAdapter mAccountsAdapter; + private CustomTabIconsAdapter mTabIconsAdapter; - private View mAccountContainer, mSecondaryFieldContainer, mExtraConfigurationsContainer; - private Spinner mTabIconSpinner, mAccountSpinner; - private EditText mEditTabName; - private TextView mSecondaryFieldLabel; - private TextView mTabTypeName; - private LinearLayout mExtraConfigurationsContent; + private View mAccountContainer, mSecondaryFieldContainer, mExtraConfigurationsContainer; + private Spinner mTabIconSpinner, mAccountSpinner; + private EditText mEditTabName; + private TextView mSecondaryFieldLabel; + private TextView mTabTypeName; + private LinearLayout mExtraConfigurationsContent; - private long mTabId; - private String mTabType; - private CustomTabConfiguration mTabConfiguration; - private Object mSecondaryFieldValue; - private final Bundle mExtrasBundle = new Bundle(); + private long mTabId; + private String mTabType; + private CustomTabConfiguration mTabConfiguration; + private Object mSecondaryFieldValue; + private final Bundle mExtrasBundle = new Bundle(); - private final View.OnClickListener mOnExtraConfigurationClickListener = new View.OnClickListener() { + private final View.OnClickListener mOnExtraConfigurationClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - final Object tag = v.getTag(); - if (tag instanceof ExtraConfiguration) { - final ExtraConfiguration conf = (ExtraConfiguration) tag; - switch (conf.getType()) { - case BOOLEAN: { - final CheckBox checkBox = (CheckBox) v.findViewById(android.R.id.checkbox); - checkBox.toggle(); - mExtrasBundle.putBoolean(conf.getKey(), checkBox.isChecked()); - break; - } - default: { - break; - } - } - } - } - }; + @Override + public void onClick(final View v) { + final Object tag = v.getTag(); + if (tag instanceof ExtraConfiguration) { + final ExtraConfiguration conf = (ExtraConfiguration) tag; + switch (conf.getType()) { + case BOOLEAN: { + final CheckBox checkBox = (CheckBox) v.findViewById(android.R.id.checkbox); + checkBox.toggle(); + mExtrasBundle.putBoolean(conf.getKey(), checkBox.isChecked()); + break; + } + default: { + break; + } + } + } + } + }; - @Override - public void onClick(final View v) { - final CustomTabConfiguration conf = mTabConfiguration; - final Object value = mSecondaryFieldValue; - switch (v.getId()) { - case R.id.secondary_field: { - if (conf == null) return; - switch (conf.getSecondaryFieldType()) { - case CustomTabConfiguration.FIELD_TYPE_USER: { - final Intent intent = new Intent(this, UserListSelectorActivity.class); - intent.setAction(INTENT_ACTION_SELECT_USER); - intent.putExtra(EXTRA_ACCOUNT_ID, getAccountId()); - startActivityForResult(intent, REQUEST_SELECT_USER); - break; - } - case CustomTabConfiguration.FIELD_TYPE_USER_LIST: { - final Intent intent = new Intent(this, UserListSelectorActivity.class); - intent.setAction(INTENT_ACTION_SELECT_USER_LIST); - intent.putExtra(EXTRA_ACCOUNT_ID, getAccountId()); - startActivityForResult(intent, REQUEST_SELECT_USER_LIST); - break; - } - case CustomTabConfiguration.FIELD_TYPE_TEXT: { - final int title = conf.getSecondaryFieldTitle(); - SecondaryFieldEditTextDialogFragment.show(this, ParseUtils.parseString(value), - getString(title > 0 ? title : R.string.content)); - break; - } - } - break; - } - case R.id.save: { - if (!isEditMode()) { - if (conf == null) return; - final boolean account_id_required = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; - final boolean no_account_id = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE; - final boolean secondaryFieldRequired = conf.getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE; - final boolean account_id_invalid = getAccountId() <= 0; - final boolean secondary_field_invalid = mSecondaryFieldValue == null; - if (account_id_required && account_id_invalid || secondaryFieldRequired && secondary_field_invalid) { - Toast.makeText(this, R.string.invalid_settings, Toast.LENGTH_SHORT).show(); - return; - } - final Intent data = new Intent(); - final Bundle args = new Bundle(); - if (!no_account_id) { - args.putLong(EXTRA_ACCOUNT_ID, getAccountId()); - } - if (secondaryFieldRequired) { - addSecondaryFieldValueToArguments(args); - } - data.putExtra(EXTRA_TYPE, mTabType); - data.putExtra(EXTRA_NAME, ParseUtils.parseString(mEditTabName.getText())); - data.putExtra(EXTRA_ICON, getIconKey()); - data.putExtra(EXTRA_ARGUMENTS, ParseUtils.bundleToJSON(args)); - data.putExtra(EXTRA_EXTRAS, ParseUtils.bundleToJSON(mExtrasBundle)); - setResult(RESULT_OK, data); - finish(); - } else { - if (mTabId < 0) return; - final Intent data = new Intent(); - data.putExtra(EXTRA_NAME, ParseUtils.parseString(mEditTabName.getText())); - data.putExtra(EXTRA_ICON, getIconKey()); - data.putExtra(EXTRA_ID, mTabId); - data.putExtra(EXTRA_EXTRAS, ParseUtils.bundleToJSON(mExtrasBundle)); - setResult(RESULT_OK, data); - finish(); - } - break; - } - } - } + @Override + public void onClick(final View v) { + final CustomTabConfiguration conf = mTabConfiguration; + final Object value = mSecondaryFieldValue; + switch (v.getId()) { + case R.id.secondary_field: { + if (conf == null) return; + switch (conf.getSecondaryFieldType()) { + case CustomTabConfiguration.FIELD_TYPE_USER: { + final Intent intent = new Intent(this, UserListSelectorActivity.class); + intent.setAction(INTENT_ACTION_SELECT_USER); + intent.putExtra(EXTRA_ACCOUNT_ID, getAccountId()); + startActivityForResult(intent, REQUEST_SELECT_USER); + break; + } + case CustomTabConfiguration.FIELD_TYPE_USER_LIST: { + final Intent intent = new Intent(this, UserListSelectorActivity.class); + intent.setAction(INTENT_ACTION_SELECT_USER_LIST); + intent.putExtra(EXTRA_ACCOUNT_ID, getAccountId()); + startActivityForResult(intent, REQUEST_SELECT_USER_LIST); + break; + } + case CustomTabConfiguration.FIELD_TYPE_TEXT: { + final int title = conf.getSecondaryFieldTitle(); + SecondaryFieldEditTextDialogFragment.show(this, ParseUtils.parseString(value), + getString(title > 0 ? title : R.string.content)); + break; + } + } + break; + } + case R.id.save: { + if (!isEditMode()) { + if (conf == null) return; + final boolean account_id_required = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; + final boolean no_account_id = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE; + final boolean secondaryFieldRequired = conf.getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE; + final boolean account_id_invalid = getAccountId() <= 0; + final boolean secondary_field_invalid = mSecondaryFieldValue == null; + if (account_id_required && account_id_invalid || secondaryFieldRequired && secondary_field_invalid) { + Toast.makeText(this, R.string.invalid_settings, Toast.LENGTH_SHORT).show(); + return; + } + final Intent data = new Intent(); + final Bundle args = new Bundle(); + if (!no_account_id) { + args.putLong(EXTRA_ACCOUNT_ID, getAccountId()); + } + if (secondaryFieldRequired) { + addSecondaryFieldValueToArguments(args); + } + data.putExtra(EXTRA_TYPE, mTabType); + data.putExtra(EXTRA_NAME, ParseUtils.parseString(mEditTabName.getText())); + data.putExtra(EXTRA_ICON, getIconKey()); + data.putExtra(EXTRA_ARGUMENTS, ParseUtils.bundleToJSON(args)); + data.putExtra(EXTRA_EXTRAS, ParseUtils.bundleToJSON(mExtrasBundle)); + setResult(RESULT_OK, data); + finish(); + } else { + if (mTabId < 0) return; + final Intent data = new Intent(); + data.putExtra(EXTRA_NAME, ParseUtils.parseString(mEditTabName.getText())); + data.putExtra(EXTRA_ICON, getIconKey()); + data.putExtra(EXTRA_ID, mTabId); + data.putExtra(EXTRA_EXTRAS, ParseUtils.bundleToJSON(mExtrasBundle)); + setResult(RESULT_OK, data); + finish(); + } + break; + } + } + } - @Override - public void onContentChanged() { - super.onContentChanged(); - mAccountContainer = findViewById(R.id.account_container); - mSecondaryFieldContainer = findViewById(R.id.secondary_field_container); - mExtraConfigurationsContainer = findViewById(R.id.extra_configurations_container); - mTabTypeName = (TextView) findViewById(R.id.tab_type_name); - mEditTabName = (EditText) findViewById(R.id.tab_name); - mSecondaryFieldLabel = (TextView) findViewById(R.id.secondary_field_label); - mTabIconSpinner = (Spinner) findViewById(R.id.tab_icon_spinner); - mAccountSpinner = (Spinner) findViewById(R.id.account_spinner); - mExtraConfigurationsContent = (LinearLayout) findViewById(R.id.extra_configurations_content); - } + @Override + public void onContentChanged() { + super.onContentChanged(); + mAccountContainer = findViewById(R.id.account_container); + mSecondaryFieldContainer = findViewById(R.id.secondary_field_container); + mExtraConfigurationsContainer = findViewById(R.id.extra_configurations_container); + mTabTypeName = (TextView) findViewById(R.id.tab_type_name); + mEditTabName = (EditText) findViewById(R.id.tab_name); + mSecondaryFieldLabel = (TextView) findViewById(R.id.secondary_field_label); + mTabIconSpinner = (Spinner) findViewById(R.id.tab_icon_spinner); + mAccountSpinner = (Spinner) findViewById(R.id.account_spinner); + mExtraConfigurationsContent = (LinearLayout) findViewById(R.id.extra_configurations_content); + } - public void setExtraFieldSelectText(final View view, final int text) { - final TextView text1 = (TextView) view.findViewById(android.R.id.text1); - final TextView text2 = (TextView) view.findViewById(android.R.id.text2); - final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); - text1.setVisibility(View.VISIBLE); - text2.setVisibility(View.GONE); - icon.setVisibility(View.GONE); - text1.setText(text); - } + public void setExtraFieldSelectText(final View view, final int text) { + final TextView text1 = (TextView) view.findViewById(android.R.id.text1); + final TextView text2 = (TextView) view.findViewById(android.R.id.text2); + final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); + text1.setVisibility(View.VISIBLE); + text2.setVisibility(View.GONE); + icon.setVisibility(View.GONE); + text1.setText(text); + } - public void setExtraFieldView(final View view, final Object value) { - final TextView text1 = (TextView) view.findViewById(android.R.id.text1); - final TextView text2 = (TextView) view.findViewById(android.R.id.text2); - final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); - final boolean display_profile_image = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true); - final boolean nickname_only = mPreferences.getBoolean(KEY_NICKNAME_ONLY, false); - final boolean display_name = mPreferences.getBoolean(KEY_NAME_FIRST, true); - text1.setVisibility(View.VISIBLE); - text2.setVisibility(View.VISIBLE); - icon.setVisibility(display_profile_image ? View.VISIBLE : View.GONE); - if (value instanceof ParcelableUser) { - final ParcelableUser user = (ParcelableUser) value; - final String nick = getUserNickname(this, user.id); - text1.setText(TextUtils.isEmpty(nick) ? user.name : nickname_only ? nick : getString( - R.string.name_with_nickname, user.name, nick)); - text2.setText("@" + user.screen_name); - if (display_profile_image) { - mImageLoader.displayProfileImage(icon, user.profile_image_url); - } - } else if (value instanceof ParcelableUserList) { - final ParcelableUserList user_list = (ParcelableUserList) value; - final String created_by; - if (display_name) { - created_by = "@" + user_list.user_screen_name; - } else { - final String nick = getUserNickname(this, user_list.user_id); - created_by = TextUtils.isEmpty(nick) ? user_list.user_name : nickname_only ? nick : getString( - R.string.name_with_nickname, user_list.user_name, nick); - } - text1.setText(user_list.name); - text2.setText(getString(R.string.created_by, created_by)); - if (display_profile_image) { - mImageLoader.displayProfileImage(icon, user_list.user_profile_image_url); - } - } else if (value instanceof CharSequence) { - text2.setVisibility(View.GONE); - icon.setVisibility(View.GONE); - text1.setText((CharSequence) value); - } - } + public void setExtraFieldView(final View view, final Object value) { + final TextView text1 = (TextView) view.findViewById(android.R.id.text1); + final TextView text2 = (TextView) view.findViewById(android.R.id.text2); + final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); + final boolean display_profile_image = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true); + final boolean nickname_only = mPreferences.getBoolean(KEY_NICKNAME_ONLY, false); + final boolean display_name = mPreferences.getBoolean(KEY_NAME_FIRST, true); + text1.setVisibility(View.VISIBLE); + text2.setVisibility(View.VISIBLE); + icon.setVisibility(display_profile_image ? View.VISIBLE : View.GONE); + if (value instanceof ParcelableUser) { + final ParcelableUser user = (ParcelableUser) value; + final String nick = getUserNickname(this, user.id); + text1.setText(TextUtils.isEmpty(nick) ? user.name : nickname_only ? nick : getString( + R.string.name_with_nickname, user.name, nick)); + text2.setText("@" + user.screen_name); + if (display_profile_image) { + mImageLoader.displayProfileImage(icon, user.profile_image_url); + } + } else if (value instanceof ParcelableUserList) { + final ParcelableUserList user_list = (ParcelableUserList) value; + final String created_by; + if (display_name) { + created_by = "@" + user_list.user_screen_name; + } else { + final String nick = getUserNickname(this, user_list.user_id); + created_by = TextUtils.isEmpty(nick) ? user_list.user_name : nickname_only ? nick : getString( + R.string.name_with_nickname, user_list.user_name, nick); + } + text1.setText(user_list.name); + text2.setText(getString(R.string.created_by, created_by)); + if (display_profile_image) { + mImageLoader.displayProfileImage(icon, user_list.user_profile_image_url); + } + } else if (value instanceof CharSequence) { + text2.setVisibility(View.GONE); + icon.setVisibility(View.GONE); + text1.setText((CharSequence) value); + } + } - public void setSecondaryFieldValue(final Object value) { - mSecondaryFieldValue = value; - setExtraFieldView(mSecondaryFieldContainer, value); - } + public void setSecondaryFieldValue(final Object value) { + mSecondaryFieldValue = value; + setExtraFieldView(mSecondaryFieldContainer, value); + } - @Override - protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { - if (resultCode != RESULT_OK) return; - switch (requestCode) { - case REQUEST_SELECT_USER: { - setSecondaryFieldValue(data.getParcelableExtra(EXTRA_USER)); - break; - } - case REQUEST_SELECT_USER_LIST: { - setSecondaryFieldValue(data.getParcelableExtra(EXTRA_USER_LIST)); - break; - } - } - } + @Override + protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { + if (resultCode != RESULT_OK) return; + switch (requestCode) { + case REQUEST_SELECT_USER: { + setSecondaryFieldValue(data.getParcelableExtra(EXTRA_USER)); + break; + } + case REQUEST_SELECT_USER_LIST: { + setSecondaryFieldValue(data.getParcelableExtra(EXTRA_USER_LIST)); + break; + } + } + } - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); - mImageLoader = TwidereApplication.getInstance(this).getImageLoaderWrapper(); - final Intent intent = getIntent(); - final String type = mTabType = intent.getStringExtra(EXTRA_TYPE); - final CustomTabConfiguration conf = getTabConfiguration(type); - if (type == null || conf == null) { - finish(); - return; - } - mTabId = intent.getLongExtra(EXTRA_ID, -1); - setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab); - setContentView(R.layout.activity_custom_tab_editor); - mTabTypeName.setText(getTabTypeName(this, type)); - mTabIconsAdapter = new CustomTabIconsAdapter(this); - mTabIconsAdapter.setData(getIconMap()); - mAccountsAdapter = new AccountsSpinnerAdapter(this); - mAccountSpinner.setAdapter(mAccountsAdapter); - mTabIconSpinner.setAdapter(mTabIconsAdapter); - final String iconKey; - if (savedInstanceState != null) { - mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS)); - } - if (!isEditMode()) { - mTabConfiguration = conf; - final boolean has_secondary_field = conf.getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE; - final boolean account_id_none = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE; - mAccountContainer.setVisibility(account_id_none ? View.GONE : View.VISIBLE); - mSecondaryFieldContainer.setVisibility(has_secondary_field ? View.VISIBLE : View.GONE); - final boolean accountIdRequired = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; - if (!accountIdRequired) { - mAccountsAdapter.add(Account.dummyInstance()); - } - final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false); - mAccountsAdapter.addAll(Account.getAccountsList(this, false, officialKeyOnly)); - switch (conf.getSecondaryFieldType()) { - case CustomTabConfiguration.FIELD_TYPE_USER: { - mSecondaryFieldLabel.setText(R.string.user); - setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user); - break; - } - case CustomTabConfiguration.FIELD_TYPE_USER_LIST: { - mSecondaryFieldLabel.setText(R.string.user_list); - setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list); - break; - } - case CustomTabConfiguration.FIELD_TYPE_TEXT: { - mSecondaryFieldLabel.setText(R.string.content); - setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text); - break; - } - } - if (conf.getSecondaryFieldTitle() != 0) { - mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle()); - } - iconKey = findTabIconKey(conf.getDefaultIcon()); - mEditTabName.setText(mTabConfiguration.getDefaultTitle()); - } else { - if (mTabId < 0) { - finish(); - return; - } - mAccountContainer.setVisibility(View.GONE); - mSecondaryFieldContainer.setVisibility(View.GONE); - iconKey = intent.getStringExtra(EXTRA_ICON); - mEditTabName.setText(intent.getStringExtra(EXTRA_NAME)); - if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) { - mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS))); - } - } - final int selection = mTabIconsAdapter.getIconPosition(iconKey); - mTabIconSpinner.setSelection(selection > 0 ? selection : 0); - final LayoutInflater inflater = getLayoutInflater(); - final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations(); - if (extraConfigurations == null || extraConfigurations.length == 0) { - mExtraConfigurationsContainer.setVisibility(View.GONE); - } else { - mExtraConfigurationsContainer.setVisibility(View.VISIBLE); - for (final ExtraConfiguration config : extraConfigurations) { - final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN; - final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent, false); - final TextView title = (TextView) view.findViewById(android.R.id.title); - final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox); - title.setText(config.getTitleRes()); - checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE); - if (hasCheckBox) { - checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean())); - } - view.setTag(config); - view.setOnClickListener(mOnExtraConfigurationClickListener); - mExtraConfigurationsContent.addView(view); - } - } - } + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); + mImageLoader = TwidereApplication.getInstance(this).getImageLoaderWrapper(); + final Intent intent = getIntent(); + final String type = mTabType = intent.getStringExtra(EXTRA_TYPE); + final CustomTabConfiguration conf = getTabConfiguration(type); + if (type == null || conf == null) { + finish(); + return; + } + mTabId = intent.getLongExtra(EXTRA_ID, -1); + setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab); + setContentView(R.layout.activity_custom_tab_editor); + mTabTypeName.setText(getTabTypeName(this, type)); + mTabIconsAdapter = new CustomTabIconsAdapter(this); + mTabIconsAdapter.setData(getIconMap()); + mAccountsAdapter = new AccountsSpinnerAdapter(this); + mAccountSpinner.setAdapter(mAccountsAdapter); + mTabIconSpinner.setAdapter(mTabIconsAdapter); + final String iconKey; + if (savedInstanceState != null) { + mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS)); + } + if (!isEditMode()) { + mTabConfiguration = conf; + final boolean has_secondary_field = conf.getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE; + final boolean account_id_none = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE; + mAccountContainer.setVisibility(account_id_none ? View.GONE : View.VISIBLE); + mSecondaryFieldContainer.setVisibility(has_secondary_field ? View.VISIBLE : View.GONE); + final boolean accountIdRequired = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; + if (!accountIdRequired) { + mAccountsAdapter.add(Account.dummyInstance()); + } + final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false); + mAccountsAdapter.addAll(Account.getAccountsList(this, false, officialKeyOnly)); + switch (conf.getSecondaryFieldType()) { + case CustomTabConfiguration.FIELD_TYPE_USER: { + mSecondaryFieldLabel.setText(R.string.user); + setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user); + break; + } + case CustomTabConfiguration.FIELD_TYPE_USER_LIST: { + mSecondaryFieldLabel.setText(R.string.user_list); + setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list); + break; + } + case CustomTabConfiguration.FIELD_TYPE_TEXT: { + mSecondaryFieldLabel.setText(R.string.content); + setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text); + break; + } + } + if (conf.getSecondaryFieldTitle() != 0) { + mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle()); + } + iconKey = findTabIconKey(conf.getDefaultIcon()); + mEditTabName.setText(mTabConfiguration.getDefaultTitle()); + } else { + if (mTabId < 0) { + finish(); + return; + } + mAccountContainer.setVisibility(View.GONE); + mSecondaryFieldContainer.setVisibility(View.GONE); + iconKey = intent.getStringExtra(EXTRA_ICON); + mEditTabName.setText(intent.getStringExtra(EXTRA_NAME)); + if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) { + mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS))); + } + } + final int selection = mTabIconsAdapter.getIconPosition(iconKey); + mTabIconSpinner.setSelection(selection > 0 ? selection : 0); + final LayoutInflater inflater = getLayoutInflater(); + final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations(); + if (extraConfigurations == null || extraConfigurations.length == 0) { + mExtraConfigurationsContainer.setVisibility(View.GONE); + } else { + mExtraConfigurationsContainer.setVisibility(View.VISIBLE); + for (final ExtraConfiguration config : extraConfigurations) { + final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN; + final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent, false); + final TextView title = (TextView) view.findViewById(android.R.id.title); + final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox); + title.setText(config.getTitleRes()); + checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE); + if (hasCheckBox) { + checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean())); + } + view.setTag(config); + view.setOnClickListener(mOnExtraConfigurationClickListener); + mExtraConfigurationsContent.addView(view); + } + } + } - @Override - protected void onSaveInstanceState(final Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBundle(EXTRA_EXTRAS, mExtrasBundle); - } + @Override + protected void onSaveInstanceState(final Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBundle(EXTRA_EXTRAS, mExtrasBundle); + } - private void addFieldValueToArguments(final Object value, final Bundle args) { - final CustomTabConfiguration conf = mTabConfiguration; - if (value == null || args == null || conf == null) return; - if (value instanceof ParcelableUser) { - final ParcelableUser user = (ParcelableUser) value; - args.putLong(EXTRA_USER_ID, user.id); - args.putString(EXTRA_SCREEN_NAME, user.screen_name); - args.putString(EXTRA_NAME, user.name); - } else if (value instanceof ParcelableUserList) { - final ParcelableUserList user_list = (ParcelableUserList) value; - args.putLong(EXTRA_LIST_ID, user_list.id); - args.putString(EXTRA_LIST_NAME, user_list.name); - args.putLong(EXTRA_USER_ID, user_list.user_id); - args.putString(EXTRA_SCREEN_NAME, user_list.user_screen_name); - } else if (value instanceof CharSequence) { - final String key = conf.getSecondaryFieldTextKey(); - args.putString(TextUtils.isEmpty(key) ? EXTRA_TEXT : key, value.toString()); - } - } + private void addFieldValueToArguments(final Object value, final Bundle args) { + final CustomTabConfiguration conf = mTabConfiguration; + if (value == null || args == null || conf == null) return; + if (value instanceof ParcelableUser) { + final ParcelableUser user = (ParcelableUser) value; + args.putLong(EXTRA_USER_ID, user.id); + args.putString(EXTRA_SCREEN_NAME, user.screen_name); + args.putString(EXTRA_NAME, user.name); + } else if (value instanceof ParcelableUserList) { + final ParcelableUserList user_list = (ParcelableUserList) value; + args.putLong(EXTRA_LIST_ID, user_list.id); + args.putString(EXTRA_LIST_NAME, user_list.name); + args.putLong(EXTRA_USER_ID, user_list.user_id); + args.putString(EXTRA_SCREEN_NAME, user_list.user_screen_name); + } else if (value instanceof CharSequence) { + final String key = conf.getSecondaryFieldTextKey(); + args.putString(TextUtils.isEmpty(key) ? EXTRA_TEXT : key, value.toString()); + } + } - private void addSecondaryFieldValueToArguments(final Bundle args) { - final Object value = mSecondaryFieldValue; - addFieldValueToArguments(value, args); - } + private void addSecondaryFieldValueToArguments(final Bundle args) { + final Object value = mSecondaryFieldValue; + addFieldValueToArguments(value, args); + } - private long getAccountId() { - final int pos = mAccountSpinner.getSelectedItemPosition(); - if (mAccountSpinner.getCount() > pos && pos >= 0) return mAccountsAdapter.getItem(pos).account_id; - return -1; - } + private long getAccountId() { + final int pos = mAccountSpinner.getSelectedItemPosition(); + if (mAccountSpinner.getCount() > pos && pos >= 0) + return mAccountsAdapter.getItem(pos).account_id; + return -1; + } - private String getIconKey() { - final int pos = mTabIconSpinner.getSelectedItemPosition(); - if (mTabIconsAdapter.getCount() > pos && pos >= 0) return mTabIconsAdapter.getItem(pos).getKey(); - return null; - } + private String getIconKey() { + final int pos = mTabIconSpinner.getSelectedItemPosition(); + if (mTabIconsAdapter.getCount() > pos && pos >= 0) + return mTabIconsAdapter.getItem(pos).getKey(); + return null; + } - private boolean isEditMode() { - return INTENT_ACTION_EDIT_TAB.equals(getIntent().getAction()); - } + private boolean isEditMode() { + return INTENT_ACTION_EDIT_TAB.equals(getIntent().getAction()); + } - public static class SecondaryFieldEditTextDialogFragment extends BaseSupportDialogFragment implements - DialogInterface.OnClickListener { - private static final String FRAGMENT_TAG_EDIT_SECONDARY_FIELD = "edit_secondary_field"; - private EditText mEditText; + public static class SecondaryFieldEditTextDialogFragment extends BaseSupportDialogFragment implements + DialogInterface.OnClickListener { + private static final String FRAGMENT_TAG_EDIT_SECONDARY_FIELD = "edit_secondary_field"; + private EditText mEditText; - @Override - public void onClick(final DialogInterface dialog, final int which) { - final FragmentActivity activity = getActivity(); - if (activity instanceof CustomTabEditorActivity) { - ((CustomTabEditorActivity) activity) - .setSecondaryFieldValue(ParseUtils.parseString(mEditText.getText())); - } - } + @Override + public void onClick(final DialogInterface dialog, final int which) { + final FragmentActivity activity = getActivity(); + if (activity instanceof CustomTabEditorActivity) { + ((CustomTabEditorActivity) activity) + .setSecondaryFieldValue(ParseUtils.parseString(mEditText.getText())); + } + } - @Override - public Dialog onCreateDialog(final Bundle savedInstanceState) { - final Bundle args = getArguments(); - final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity()); - final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped); - builder.setTitle(args.getString(EXTRA_TITLE)); - builder.setPositiveButton(android.R.string.ok, this); - builder.setNegativeButton(android.R.string.cancel, null); - final FrameLayout view = new FrameLayout(getActivity()); - mEditText = new EditText(getActivity()); - final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, - FrameLayout.LayoutParams.WRAP_CONTENT); - lp.leftMargin = lp.topMargin = lp.bottomMargin = lp.rightMargin = getResources().getDimensionPixelSize( - R.dimen.element_spacing_normal); - view.addView(mEditText, lp); - builder.setView(view); - mEditText.setText(args.getString(EXTRA_TEXT)); - return builder.create(); - } + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + final Bundle args = getArguments(); + final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity()); + final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped); + builder.setTitle(args.getString(EXTRA_TITLE)); + builder.setPositiveButton(android.R.string.ok, this); + builder.setNegativeButton(android.R.string.cancel, null); + final FrameLayout view = new FrameLayout(getActivity()); + mEditText = new EditText(getActivity()); + final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.WRAP_CONTENT); + lp.leftMargin = lp.topMargin = lp.bottomMargin = lp.rightMargin = getResources().getDimensionPixelSize( + R.dimen.element_spacing_normal); + view.addView(mEditText, lp); + builder.setView(view); + mEditText.setText(args.getString(EXTRA_TEXT)); + return builder.create(); + } - public static SecondaryFieldEditTextDialogFragment show(final FragmentActivity activity, final String text, - final String title) { - final SecondaryFieldEditTextDialogFragment f = new SecondaryFieldEditTextDialogFragment(); - final Bundle args = new Bundle(); - args.putString(EXTRA_TEXT, text); - args.putString(EXTRA_TITLE, title); - f.setArguments(args); - f.show(activity.getSupportFragmentManager(), FRAGMENT_TAG_EDIT_SECONDARY_FIELD); - return f; - } - } + public static SecondaryFieldEditTextDialogFragment show(final FragmentActivity activity, final String text, + final String title) { + final SecondaryFieldEditTextDialogFragment f = new SecondaryFieldEditTextDialogFragment(); + final Bundle args = new Bundle(); + args.putString(EXTRA_TEXT, text); + args.putString(EXTRA_TITLE, title); + f.setArguments(args); + f.show(activity.getSupportFragmentManager(), FRAGMENT_TAG_EDIT_SECONDARY_FIELD); + return f; + } + } - static class CustomTabIconsAdapter extends ArrayAdapter> { + static class CustomTabIconsAdapter extends ArrayAdapter> { - private final Resources mResources; + private final Resources mResources; + private final int mIconColor; - public CustomTabIconsAdapter(final Context context) { - super(context, R.layout.spinner_item_custom_tab_icon); - setDropDownViewResource(R.layout.list_item_two_line_small); - mResources = context.getResources(); - } + public CustomTabIconsAdapter(final Context context) { + super(context, R.layout.spinner_item_custom_tab_icon); + setDropDownViewResource(R.layout.list_item_two_line_small); + mResources = context.getResources(); + mIconColor = ThemeUtils.getThemeForegroundColor(context); + } - @Override - public View getDropDownView(final int position, final View convertView, final ViewGroup parent) { - final View view = super.getDropDownView(position, convertView, parent); - view.findViewById(android.R.id.text2).setVisibility(View.GONE); - final TextView text1 = (TextView) view.findViewById(android.R.id.text1); - final Entry item = getItem(position); - final int value = item.getValue(); - if (value > 0) { - final String key = item.getKey(); - text1.setText(key.substring(0, 1).toUpperCase(Locale.US) + key.substring(1, key.length())); - } else { - text1.setText(R.string.customize); - } - bindView(position, item, view); - return view; - } + @Override + public View getDropDownView(final int position, final View convertView, final ViewGroup parent) { + final View view = super.getDropDownView(position, convertView, parent); + view.findViewById(android.R.id.text2).setVisibility(View.GONE); + final TextView text1 = (TextView) view.findViewById(android.R.id.text1); + final Entry item = getItem(position); + final int value = item.getValue(); + if (value > 0) { + final String key = item.getKey(); + text1.setText(key.substring(0, 1).toUpperCase(Locale.US) + key.substring(1, key.length())); + } else { + text1.setText(R.string.customize); + } + bindIconView(position, item, view); + return view; + } - public int getIconPosition(final String key) { - if (key == null) return -1; - for (int i = 0, j = getCount(); i < j; i++) { - if (key.equals(getItem(i).getKey())) return i; - } - return -1; - } + public int getIconPosition(final String key) { + if (key == null) return -1; + for (int i = 0, j = getCount(); i < j; i++) { + if (key.equals(getItem(i).getKey())) return i; + } + return -1; + } - @Override - public View getView(final int position, final View convertView, final ViewGroup parent) { - final View view = super.getView(position, convertView, parent); - bindView(position, getItem(position), view); - return view; - } + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + final View view = super.getView(position, convertView, parent); + bindIconView(position, getItem(position), view); + return view; + } - public void setData(final Map map) { - clear(); - if (map == null) return; - addAll(map.entrySet()); - sort(new LocationComparator(mResources)); - } + public void setData(final Map map) { + clear(); + if (map == null) return; + addAll(map.entrySet()); + sort(new LocationComparator(mResources)); + } - private void bindView(final int position, final Entry item, final View view) { - final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); - final int value = item.getValue(); - if (value > 0) { - ViewAccessor.setBackground(icon, mResources.getDrawable(value)); - } else { - ViewAccessor.setBackground(icon, null); - } - } + private void bindIconView(final int position, final Entry item, final View view) { + final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); + icon.setColorFilter(mIconColor, Mode.SRC_ATOP); + final int value = item.getValue(); + if (value > 0) { + icon.setImageResource(item.getValue()); + } else { + icon.setImageDrawable(null); + } + } - private static class LocationComparator implements Comparator> { - private final Collator mCollator; + private static class LocationComparator implements Comparator> { + private final Collator mCollator; - LocationComparator(final Resources res) { - mCollator = Collator.getInstance(res.getConfiguration().locale); - } + LocationComparator(final Resources res) { + mCollator = Collator.getInstance(res.getConfiguration().locale); + } - @Override - public int compare(final Entry object1, final Entry object2) { - if (object1.getValue() <= 0) return Integer.MAX_VALUE; - if (object2.getValue() <= 0) return Integer.MIN_VALUE; - return mCollator.compare(object1.getKey(), object2.getKey()); - } + @Override + public int compare(final Entry object1, final Entry object2) { + if (object1.getValue() <= 0) return Integer.MAX_VALUE; + if (object2.getValue() <= 0) return Integer.MIN_VALUE; + return mCollator.compare(object1.getKey(), object2.getKey()); + } - } + } - } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java index 80eb04379..7eb08eb7f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java @@ -455,6 +455,7 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener && mUpdateUnreadCountTask.getStatus() == AsyncTask.Status.RUNNING) return; mUpdateUnreadCountTask = new UpdateUnreadCountTask(mTabIndicator); mUpdateUnreadCountTask.execute(); + mTabIndicator.setDisplayBadge(mPreferences.getBoolean(KEY_UNREAD_COUNT, true)); } @Override @@ -536,7 +537,7 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener mTabIndicator.setDisplayLabel(false); mTabIndicator.setDisplayIcon(true); } - mTabIndicator.setDisplayBadge(mPreferences.getBoolean(KEY_UNREAD_COUNT, true)); +// mTabIndicator.setDisplayBadge(mPreferences.getBoolean(KEY_UNREAD_COUNT, true)); mActionsButton.setOnClickListener(this); mActionsButton.setOnLongClickListener(this); setTabPosition(initialTabPosition); diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AccountsSpinnerAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AccountsSpinnerAdapter.java index ca1997d14..8985b6ecb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AccountsSpinnerAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AccountsSpinnerAdapter.java @@ -20,6 +20,7 @@ package org.mariotaku.twidere.adapter; import android.content.Context; +import android.graphics.PorterDuff.Mode; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -30,59 +31,60 @@ import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.fragment.support.DirectMessagesConversationFragment; import org.mariotaku.twidere.model.Account; import org.mariotaku.twidere.util.ImageLoaderWrapper; +import org.mariotaku.twidere.util.ThemeUtils; import java.util.Collection; public class AccountsSpinnerAdapter extends ArrayAdapter { - private final ImageLoaderWrapper mImageLoader; - private final boolean mDisplayProfileImage; + private final ImageLoaderWrapper mImageLoader; + private final boolean mDisplayProfileImage; - public AccountsSpinnerAdapter(final Context context) { - super(context, R.layout.list_item_two_line_small); - setDropDownViewResource(R.layout.list_item_two_line_small); - mImageLoader = TwidereApplication.getInstance(context).getImageLoaderWrapper(); - mDisplayProfileImage = context.getSharedPreferences(DirectMessagesConversationFragment.SHARED_PREFERENCES_NAME, - Context.MODE_PRIVATE).getBoolean(DirectMessagesConversationFragment.KEY_DISPLAY_PROFILE_IMAGE, true); - } + public AccountsSpinnerAdapter(final Context context) { + super(context, R.layout.list_item_two_line_small); + setDropDownViewResource(R.layout.list_item_two_line_small); + mImageLoader = TwidereApplication.getInstance(context).getImageLoaderWrapper(); + mDisplayProfileImage = context.getSharedPreferences(DirectMessagesConversationFragment.SHARED_PREFERENCES_NAME, + Context.MODE_PRIVATE).getBoolean(DirectMessagesConversationFragment.KEY_DISPLAY_PROFILE_IMAGE, true); + } - public AccountsSpinnerAdapter(final Context context, final Collection accounts) { - this(context); - addAll(accounts); - } + public AccountsSpinnerAdapter(final Context context, final Collection accounts) { + this(context); + addAll(accounts); + } - @Override - public View getDropDownView(final int position, final View convertView, final ViewGroup parent) { - final View view = super.getDropDownView(position, convertView, parent); - bindView(view, getItem(position)); - return view; - } + @Override + public View getDropDownView(final int position, final View convertView, final ViewGroup parent) { + final View view = super.getDropDownView(position, convertView, parent); + bindView(view, getItem(position)); + return view; + } - @Override - public View getView(final int position, final View convertView, final ViewGroup parent) { - final View view = super.getView(position, convertView, parent); - bindView(view, getItem(position)); - return view; - } + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + final View view = super.getView(position, convertView, parent); + bindView(view, getItem(position)); + return view; + } - private void bindView(final View view, final Account item) { - final TextView text1 = (TextView) view.findViewById(android.R.id.text1); - final TextView text2 = (TextView) view.findViewById(android.R.id.text2); - final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); - text2.setVisibility(item.is_dummy ? View.GONE : View.VISIBLE); - icon.setVisibility(item.is_dummy ? View.GONE : View.VISIBLE); - if (!item.is_dummy) { - text1.setText(item.name); - text2.setText(String.format("@%s", item.screen_name)); - if (mDisplayProfileImage) { - mImageLoader.displayProfileImage(icon, item.profile_image_url); - } else { + private void bindView(final View view, final Account item) { + final TextView text1 = (TextView) view.findViewById(android.R.id.text1); + final TextView text2 = (TextView) view.findViewById(android.R.id.text2); + final ImageView icon = (ImageView) view.findViewById(android.R.id.icon); + text2.setVisibility(item.is_dummy ? View.GONE : View.VISIBLE); + icon.setVisibility(item.is_dummy ? View.GONE : View.VISIBLE); + if (!item.is_dummy) { + text1.setText(item.name); + text2.setText(String.format("@%s", item.screen_name)); + if (mDisplayProfileImage) { + mImageLoader.displayProfileImage(icon, item.profile_image_url); + } else { mImageLoader.cancelDisplayTask(icon); - icon.setImageResource(R.drawable.ic_profile_image_default); - } - } else { - text1.setText(R.string.none); - } - } + icon.setImageResource(R.drawable.ic_profile_image_default); + } + } else { + text1.setText(R.string.none); + } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java index 4d430a663..0cd8f6876 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java @@ -226,6 +226,7 @@ public class CursorStatusesAdapter extends BaseCursorAdapter implements IStatuse holder.image_preview.setImageDrawable(null); holder.image_preview.setBackgroundResource(R.drawable.image_preview_nsfw); holder.image_preview_progress.setVisibility(View.GONE); + mImageLoader.cancelDisplayTask(holder.image_preview); } else if (!firstMedia.equals(mImageLoadingHandler.getLoadingUri(holder.image_preview))) { holder.image_preview.setBackgroundResource(0); mImageLoader.displayPreviewImage(holder.image_preview, firstMedia, mImageLoadingHandler); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java index c2e7cee71..e6818b0cb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java @@ -201,6 +201,7 @@ public class AccountsManagerFragment extends BaseSupportListFragment implements mPreferences.registerOnSharedPreferenceChangeListener(this); mAdapter = new AccountsAdapter(activity); Utils.configBaseAdapter(activity, mAdapter); + mAdapter.setSortEnabled(true); setListAdapter(mAdapter); final DragSortListView listView = (DragSortListView) getListView(); listView.setDragEnabled(true); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java index f528030cc..b4fc339f5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java @@ -35,6 +35,7 @@ import android.location.Address; import android.location.Geocoder; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager; @@ -58,7 +59,6 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.webkit.URLUtil; import android.widget.AbsListView; -import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; @@ -100,8 +100,6 @@ import org.mariotaku.twidere.view.StatusTextView; import org.mariotaku.twidere.view.TwidereMenuBar; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Locale; @@ -162,8 +160,8 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On private AsyncTwitterWrapper mTwitterWrapper; private ImageLoaderWrapper mImageLoader; private Handler mHandler; - private TextView mNameView, mScreenNameView, mTimeSourceView, mInReplyToView, mLocationView, mRepliesView; - private TextView mRetweetsCountView, mFavoritesCountView; + private TextView mNameView, mScreenNameView, mTimeSourceView, mInReplyToView, mLocationView; + private TextView mRepliesCountView, mRetweetsCountView, mFavoritesCountView; private StatusTextView mTextView; private ImageView mProfileImageView, mMapView; @@ -176,7 +174,7 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On private LinearLayout mImagePreviewGrid; private View mHeaderView; private View mLoadImagesIndicator; - private View mRetweetsContainer, mFavoritesContainer; + private View mRepliesContainer, mRetweetsContainer, mFavoritesContainer; private ExtendedFrameLayout mDetailsContainer; private ListView mListView; @@ -395,6 +393,8 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On loadPreviewImages(); } mRetweetsContainer.setVisibility(!status.user_is_protected ? View.VISIBLE : View.GONE); + mRepliesContainer.setVisibility(status.reply_count < 0 ? View.GONE : View.VISIBLE); + mRepliesCountView.setText(getLocalizedNumber(mLocale, status.reply_count)); mRetweetsCountView.setText(getLocalizedNumber(mLocale, status.retweet_count)); mFavoritesCountView.setText(getLocalizedNumber(mLocale, status.favorite_count)); final ParcelableLocation location = status.location; @@ -438,7 +438,7 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On final int start = mTextView.getSelectionStart(), end = mTextView.getSelectionEnd(); final SpannableString string = SpannableString.valueOf(mTextView.getText()); final URLSpan[] spans = string.getSpans(start, end, URLSpan.class); - if (spans == null || spans.length != 1) return true; + if (spans.length != 1) return true; ClipboardUtils.setText(getActivity(), spans[0].getURL()); mode.finish(); return true; @@ -468,10 +468,10 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On mLoadMoreAutomatically = mPreferences.getBoolean(KEY_LOAD_MORE_AUTOMATICALLY, false); mLoadImagesIndicator.setOnClickListener(this); mInReplyToView.setOnClickListener(this); - mRepliesView.setOnClickListener(this); mFollowButton.setOnClickListener(this); mProfileView.setOnClickListener(this); mLocationContainer.setOnClickListener(this); + mRepliesContainer.setOnClickListener(this); mRetweetsContainer.setOnClickListener(this); mFavoritesContainer.setOnClickListener(this); mMenuBar.setVisibility(shouldUseNativeMenu() ? View.GONE : View.VISIBLE); @@ -524,7 +524,7 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On showConversation(); break; } - case R.id.replies_view: { + case R.id.replies_container: { openStatusReplies(getActivity(), status.account_id, status.id, status.user_screen_name); break; } @@ -580,12 +580,12 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.fragment_details_page, null, false); + final View view = inflater.inflate(R.layout.fragment_details_page, container, false); mMainContent = view.findViewById(R.id.content); mDetailsLoadProgress = (ProgressBar) view.findViewById(R.id.details_load_progress); mMenuBar = (TwidereMenuBar) view.findViewById(R.id.menu_bar); mDetailsContainer = (ExtendedFrameLayout) view.findViewById(R.id.details_container); - mDetailsContainer.addView(super.onCreateView(inflater, container, savedInstanceState)); + mDetailsContainer.addView(super.onCreateView(inflater, mDetailsContainer, savedInstanceState)); mHeaderView = inflater.inflate(R.layout.header_status, null, false); mImagePreviewContainer = mHeaderView.findViewById(R.id.image_preview); mLocationContainer = mHeaderView.findViewById(R.id.location_container); @@ -598,14 +598,15 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On mProfileImageView = (ImageView) mHeaderView.findViewById(R.id.profile_image); mTimeSourceView = (TextView) mHeaderView.findViewById(R.id.time_source); mInReplyToView = (TextView) mHeaderView.findViewById(R.id.in_reply_to); - mRepliesView = (TextView) mHeaderView.findViewById(R.id.replies_view); mFollowButton = (Button) mHeaderView.findViewById(R.id.follow); mFollowIndicator = mHeaderView.findViewById(R.id.follow_indicator); mFollowInfoProgress = (ProgressBar) mHeaderView.findViewById(R.id.follow_info_progress); mProfileView = (ColorLabelRelativeLayout) mHeaderView.findViewById(R.id.profile); mImagePreviewGrid = (LinearLayout) mHeaderView.findViewById(R.id.image_grid); + mRepliesContainer = mHeaderView.findViewById(R.id.replies_container); mRetweetsContainer = mHeaderView.findViewById(R.id.retweets_container); mFavoritesContainer = mHeaderView.findViewById(R.id.favorites_container); + mRepliesCountView = (TextView) mHeaderView.findViewById(R.id.replies_count); mRetweetsCountView = (TextView) mHeaderView.findViewById(R.id.retweets_count); mFavoritesCountView = (TextView) mHeaderView.findViewById(R.id.favorites_count); mLoadImagesIndicator = mHeaderView.findViewById(R.id.load_images); @@ -661,7 +662,7 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On final int start = mTextView.getSelectionStart(), end = mTextView.getSelectionEnd(); final SpannableString string = SpannableString.valueOf(mTextView.getText()); final URLSpan[] spans = string.getSpans(start, end, URLSpan.class); - final boolean avail = spans != null && spans.length == 1 && URLUtil.isValidUrl(spans[0].getURL()); + final boolean avail = spans.length == 1 && URLUtil.isValidUrl(spans[0].getURL()); Utils.setMenuItemAvailability(menu, android.R.id.copyUrl, avail); return false; } @@ -706,7 +707,6 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On mInReplyToView.setTextSize(text_size * 0.85f); mLocationView.setTextSize(text_size * 0.85f); // mRetweetView.setTextSize(text_size * 0.85f); - mRepliesView.setTextSize(text_size * 0.85f); } @Override @@ -1010,6 +1010,7 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On } + @NonNull @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity()); @@ -1078,56 +1079,6 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On } } - static class ImagesAdapter extends BaseAdapter { - - private final List mImages = new ArrayList(); - private final ImageLoaderWrapper mImageLoader; - private final LayoutInflater mInflater; - - public ImagesAdapter(final Context context) { - mImageLoader = TwidereApplication.getInstance(context).getImageLoaderWrapper(); - mInflater = LayoutInflater.from(context); - } - - public boolean addAll(final Collection images) { - final boolean ret = images != null && mImages.addAll(images); - notifyDataSetChanged(); - return ret; - } - - public void clear() { - mImages.clear(); - notifyDataSetChanged(); - } - - @Override - public int getCount() { - return mImages.size(); - } - - @Override - public ParcelableMedia getItem(final int position) { - return mImages.get(position); - } - - @Override - public long getItemId(final int position) { - final ParcelableMedia spec = getItem(position); - return spec != null ? spec.hashCode() : 0; - } - - @Override - public View getView(final int position, final View convertView, final ViewGroup parent) { - final View view = convertView != null ? convertView : mInflater.inflate( - R.layout.gallery_item_image_preview, null); - final ImageView image = (ImageView) view.findViewById(R.id.image); - final ParcelableMedia spec = getItem(position); - mImageLoader.displayPreviewImage(image, spec != null ? spec.media_url : null); - return view; - } - - } - static class LoadConversationTask extends AsyncTask> { final Handler handler; @@ -1143,7 +1094,7 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On @Override protected SingleResponse doInBackground(final ParcelableStatus... params) { if (params == null || params.length != 1) - return new SingleResponse(false, null); + return new SingleResponse<>(false, null); try { final long account_id = params[0].account_id; ParcelableStatus status = params[0]; @@ -1155,9 +1106,9 @@ public class StatusFragment extends ParcelableStatusesListFragment implements On handler.post(new AddStatusRunnable(status)); } } catch (final TwitterException e) { - return new SingleResponse(false, e); + return new SingleResponse<>(false, e); } - return new SingleResponse(true, null); + return new SingleResponse<>(true, null); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java b/twidere/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java index 63e6bf316..d6cc89fa2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java @@ -93,7 +93,8 @@ public class ParcelableStatus implements TwidereParcelable, Comparable 0 && o.outWidth > 0; - } - - public static boolean isValidImage(final InputStream is) { - if (is == null) return false; - final BitmapFactory.Options o = new BitmapFactory.Options(); - o.inJustDecodeBounds = true; - BitmapFactory.decodeStream(is, new Rect(), o); - return o.outHeight > 0 && o.outWidth > 0; - } - - public static boolean isValidUrl(final CharSequence text) { - if (TextUtils.isEmpty(text)) return false; - return URLUtil.isValidUrl(text.toString()); - } - public static final int matcherEnd(final Matcher matcher, final int group) { try { return matcher.end(group); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java index eea1625f6..716d0d5ae 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java @@ -19,18 +19,22 @@ package org.mariotaku.twidere.view; +import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Outline; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; +import android.os.Build; import android.support.annotation.NonNull; import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.View; +import android.view.ViewOutlineProvider; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.view.iface.IExtendedView; public class ProfileBannerImageView extends ForegroundImageView implements IExtendedView, Constants { @@ -52,15 +56,19 @@ public class ProfileBannerImageView extends ForegroundImageView implements IExte public ProfileBannerImageView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; - ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); setScaleType(ScaleType.CENTER_CROP); -// setForeground(ThemeUtils.getImageHighlightDrawable(context)); mClipPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); + } else { + setOutlineProvider(new CropOutlineProvider(this)); + setClipToOutline(true); + } } @Override public boolean hasOverlappingRendering() { - return true; + return Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP; } @Override @@ -109,7 +117,7 @@ public class ProfileBannerImageView extends ForegroundImageView implements IExte @Override protected void dispatchDraw(final Canvas canvas) { super.dispatchDraw(canvas); - if (mBottomClip != 0) { + if (mBottomClip != 0 && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { canvas.drawRect(getLeft(), getBottom() - mBottomClip - getTranslationY(), getRight(), getBottom(), mClipPaint); } } @@ -117,5 +125,27 @@ public class ProfileBannerImageView extends ForegroundImageView implements IExte public void setBottomClip(int bottom) { mBottomClip = bottom; invalidate(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + invalidateOutline(); + } + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private static class CropOutlineProvider extends ViewOutlineProvider { + + private final ProfileBannerImageView mImageView; + + CropOutlineProvider(ProfileBannerImageView imageView) { + mImageView = imageView; + } + + @Override + public void getOutline(View view, Outline outline) { + final int left = view.getLeft(); + final int top = view.getTop(); + final int right = view.getRight(); + final int bottom = Math.round(view.getBottom() - mImageView.mBottomClip - view.getTranslationY()); + outline.setRect(left, top, right, bottom); + } } } diff --git a/twidere/src/main/java/twitter4j/Status.java b/twidere/src/main/java/twitter4j/Status.java index 350fb3a7f..b62f48209 100644 --- a/twidere/src/main/java/twitter4j/Status.java +++ b/twidere/src/main/java/twitter4j/Status.java @@ -21,147 +21,151 @@ import java.util.Date; /** * A data interface representing one single status of a user. - * + * * @author Yusuke Yamamoto - yusuke at mac.com */ public interface Status extends Comparable, TwitterResponse, ExtendedEntitySupport, Serializable { - /** - * Returns an array of contributors, or null if no contributor is associated - * with this status. - * - * @since Twitter4J 2.2.3 - */ - long[] getContributors(); + /** + * Returns an array of contributors, or null if no contributor is associated + * with this status. + * + * @since Twitter4J 2.2.3 + */ + long[] getContributors(); - /** - * returns the created_at - * - * @return the created_at - */ - Date getCreatedAt(); + long getReplyCount(); - long getCurrentUserRetweet(); + long getDescendentReplyCount(); - long getFavoriteCount(); + /** + * returns the created_at + * + * @return the created_at + */ + Date getCreatedAt(); - /** - * Returns The location that this tweet refers to if available. - * - * @return returns The location that this tweet refers to if available (can - * be null) - */ - GeoLocation getGeoLocation(); + long getCurrentUserRetweet(); - /** - * returns the status id of the tweet - * - * @return the status id - */ - long getId(); + long getFavoriteCount(); - /** - * Returns the in_reply_to_screen_name - * - * @return the in_in_reply_to_screen_name - * @since Twitter4J 2.0.4 - */ - String getInReplyToScreenName(); + /** + * Returns The location that this tweet refers to if available. + * + * @return returns The location that this tweet refers to if available (can + * be null) + */ + GeoLocation getGeoLocation(); - /** - * Returns the in_reply_tostatus_id - * - * @return the in_reply_tostatus_id - */ - long getInReplyToStatusId(); + /** + * returns the status id of the tweet + * + * @return the status id + */ + long getId(); - /** - * Returns the in_reply_user_id - * - * @return the in_reply_tostatus_id - * @since Twitter4J 1.0.4 - */ - long getInReplyToUserId(); + /** + * Returns the in_reply_to_screen_name + * + * @return the in_in_reply_to_screen_name + * @since Twitter4J 2.0.4 + */ + String getInReplyToScreenName(); - /** - * Returns the place associated with the Tweet. - * - * @return The place associated with the Tweet - */ - Place getPlace(); + /** + * Returns the in_reply_tostatus_id + * + * @return the in_reply_tostatus_id + */ + long getInReplyToStatusId(); - /** - * returns the raw text - * - * @return the raw text - */ - String getRawText(); + /** + * Returns the in_reply_user_id + * + * @return the in_reply_tostatus_id + * @since Twitter4J 1.0.4 + */ + long getInReplyToUserId(); - /** - * Returns the number of times this tweet has been retweeted, or -1 when the - * tweet was created before this feature was enabled. - * - * @return the retweet count. - */ - long getRetweetCount(); + /** + * Returns the place associated with the Tweet. + * + * @return The place associated with the Tweet + */ + Place getPlace(); - /** - * @since Twitter4J 2.1.0 - */ - Status getRetweetedStatus(); + /** + * returns the raw text + * + * @return the raw text + */ + String getRawText(); - /** - * returns the source of the tweet - * - * @return the source of the tweet - */ - String getSource(); + /** + * Returns the number of times this tweet has been retweeted, or -1 when the + * tweet was created before this feature was enabled. + * + * @return the retweet count. + */ + long getRetweetCount(); - /** - * returns the text - * - * @return the text - */ - String getText(); + /** + * @since Twitter4J 2.1.0 + */ + Status getRetweetedStatus(); - /** - * Return the user associated with the status.
- * This can be null if the instance if from User.getStatus(). - * - * @return the user - */ - User getUser(); + /** + * returns the source of the tweet + * + * @return the source of the tweet + */ + String getSource(); - /** - * Test if the status is favorited - * - * @return true if favorited - * @since Twitter4J 1.0.4 - */ - boolean isFavorited(); + /** + * returns the text + * + * @return the text + */ + String getText(); - boolean isPossiblySensitive(); + /** + * Return the user associated with the status.
+ * This can be null if the instance if from User.getStatus(). + * + * @return the user + */ + User getUser(); - /** - * @since Twitter4J 2.0.10 - */ - boolean isRetweet(); + /** + * Test if the status is favorited + * + * @return true if favorited + * @since Twitter4J 1.0.4 + */ + boolean isFavorited(); - /** - * Returns true if the authenticating user has retweeted this tweet, or - * false when the tweet was created before this feature was enabled. - * - * @return whether the authenticating user has retweeted this tweet. - * @since Twitter4J 2.1.4 - */ - boolean isRetweetedByMe(); + boolean isPossiblySensitive(); - /** - * Test if the status is truncated - * - * @return true if truncated - * @since Twitter4J 1.0.4 - */ - boolean isTruncated(); + /** + * @since Twitter4J 2.0.10 + */ + boolean isRetweet(); + + /** + * Returns true if the authenticating user has retweeted this tweet, or + * false when the tweet was created before this feature was enabled. + * + * @return whether the authenticating user has retweeted this tweet. + * @since Twitter4J 2.1.4 + */ + boolean isRetweetedByMe(); + + /** + * Test if the status is truncated + * + * @return true if truncated + * @since Twitter4J 1.0.4 + */ + boolean isTruncated(); } diff --git a/twidere/src/main/java/twitter4j/TwitterImpl.java b/twidere/src/main/java/twitter4j/TwitterImpl.java index ea5476b39..d7b5b4a39 100644 --- a/twidere/src/main/java/twitter4j/TwitterImpl.java +++ b/twidere/src/main/java/twitter4j/TwitterImpl.java @@ -17,16 +17,8 @@ package twitter4j; -import static twitter4j.http.HttpParameter.getParameterArray; - import org.json.JSONException; -import twitter4j.auth.Authorization; -import twitter4j.conf.Configuration; -import twitter4j.http.HttpParameter; -import twitter4j.http.HttpResponse; -import twitter4j.internal.util.InternalStringUtil; - import java.io.File; import java.io.InputStream; import java.util.ArrayList; @@ -34,1629 +26,1664 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import twitter4j.auth.Authorization; +import twitter4j.conf.Configuration; +import twitter4j.http.HttpParameter; +import twitter4j.http.HttpResponse; +import twitter4j.internal.util.InternalStringUtil; + +import static twitter4j.http.HttpParameter.getParameterArray; + /** * A java representation of the Twitter REST API
* This class is thread safe and can be cached/re-used and used concurrently.
* Currently this class is not carefully designed to be extended. It is * suggested to extend this class only for mock testing purpose.
- * + * * @author Yusuke Yamamoto - yusuke at mac.com */ final class TwitterImpl extends TwitterBaseImpl implements Twitter { - private final HttpParameter INCLUDE_ENTITIES; - - private final HttpParameter INCLUDE_RTS; - - private final HttpParameter INCLUDE_MY_RETWEET; - - /* package */ - TwitterImpl(final Configuration conf, final Authorization auth) { - super(conf, auth); - INCLUDE_ENTITIES = new HttpParameter("include_entities", conf.isIncludeEntitiesEnabled()); - INCLUDE_RTS = new HttpParameter("include_rts", conf.isIncludeRTsEnabled()); - INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", 1); - } - - @Override - public User acceptFriendship(final long userId) throws TwitterException { - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId))); - } - - @Override - public User acceptFriendship(final String screenName) throws TwitterException { - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName))); - } - - @Override - public UserList addUserListMember(final long listId, final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, new HttpParameter("list_id", listId), - new HttpParameter("list_id", listId))); - } - - @Override - public UserList addUserListMember(final long listId, final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, new HttpParameter("list_id", listId), - new HttpParameter("screen_name", screenName))); - } - - @Override - public UserList addUserListMembers(final long listId, final long[] userIds) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, new HttpParameter("list_id", listId), - new HttpParameter("user_id", InternalStringUtil.join(userIds)))); - } - - @Override - public UserList addUserListMembers(final long listId, final String[] screenNames) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, new HttpParameter("list_id", listId), - new HttpParameter("screen_name", InternalStringUtil.join(screenNames)))); - } - - @Override - public User createBlock(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public User createBlock(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); - } - - @Override - public Status createFavorite(final long id) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_CREATE; - return factory.createStatus(post(url, signUrl, new HttpParameter("id", id), INCLUDE_ENTITIES)); - } - - @Override - public User createFriendship(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId))); - } - - @Override - public User createFriendship(final long userId, final boolean follow) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), new HttpParameter("follow", - follow))); - } - - @Override - public User createFriendship(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName))); - } - - @Override - public User createFriendship(final String screenName, final boolean follow) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), new HttpParameter( - "follow", follow))); - } - - @Override - public User createMute(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public User createMute(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); - } - - @Override - public Place createPlace(final String name, final String containedWithin, final String token, - final GeoLocation location, final String streetAddress) throws TwitterException { - ensureAuthorizationEnabled(); - final List params = new ArrayList(6); - addParameterToList(params, "name", name); - addParameterToList(params, "contained_within", containedWithin); - addParameterToList(params, "token", token); - addParameterToList(params, "lat", location.getLatitude()); - addParameterToList(params, "long", location.getLongitude()); - addParameterToList(params, "attribute:street_address", streetAddress); - return factory.createPlace(post(conf.getRestBaseURL() + ENDPOINT_GEO_PLACE, conf.getSigningRestBaseURL() - + ENDPOINT_GEO_PLACE, params.toArray(new HttpParameter[params.size()]))); - } - - @Override - public SavedSearch createSavedSearch(final String query) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createSavedSearch(post(conf.getRestBaseURL() + ENDPOINT_SAVED_SEARCHES_CREATE, - conf.getSigningRestBaseURL() + ENDPOINT_SAVED_SEARCHES_CREATE, new HttpParameter("query", query))); - } - - @Override - public UserList createUserList(final String listName, final boolean isPublicList, final String description) - throws TwitterException { - ensureAuthorizationEnabled(); - final List params = new ArrayList(); - addParameterToList(params, "name", listName); - addParameterToList(params, "mode", isPublicList ? "public" : "private"); - addParameterToList(params, "description", description); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_CREATE, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_CREATE, params.toArray(new HttpParameter[params.size()]))); - } - - @Override - public UserList createUserListSubscription(final long listId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory - .createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_CREATE, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_CREATE, new HttpParameter("list_id", - listId))); - } - - @Override - public UserList deleteUserListMember(final long listId, final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, new HttpParameter("list_id", listId), - new HttpParameter("user_id", userId))); - } - - @Override - public UserList deleteUserListMember(final long listId, final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, new HttpParameter("list_id", listId), - new HttpParameter("screen_name", screenName))); - } - - @Override - public UserList deleteUserListMembers(final long listId, final long[] userIds) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, - new HttpParameter("list_id", listId), new HttpParameter("user_id", InternalStringUtil.join(userIds)))); - } - - @Override - public UserList deleteUserListMembers(final long listId, final String[] screenNames) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, - new HttpParameter("list_id", listId), - new HttpParameter("screen_name", InternalStringUtil.join(screenNames)))); - } - - @Override - public User denyFriendship(final long userId) throws TwitterException { - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId))); - } - - @Override - public User denyFriendship(final String screenName) throws TwitterException { - final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName))); - } - - @Override - public User destroyBlock(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_BLOCKS_DESTROY, conf.getSigningRestBaseURL() - + ENDPOINT_BLOCKS_DESTROY, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public User destroyBlock(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_BLOCKS_DESTROY, conf.getSigningRestBaseURL() - + ENDPOINT_BLOCKS_DESTROY, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); - } - - @Override - public DirectMessage destroyDirectMessage(final long id) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_DESTROY, new HttpParameter("id", id), - INCLUDE_ENTITIES)); - } - - @Override - public Status destroyFavorite(final long id) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatus(post(conf.getRestBaseURL() + ENDPOINT_FAVORITES_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_DESTROY, new HttpParameter("id", id), - INCLUDE_ENTITIES)); - } - - @Override - public User destroyFriendship(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, new HttpParameter("user_id", userId))); - } - - @Override - public User destroyFriendship(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, new HttpParameter("screen_name", - screenName))); - } - - @Override - public User destroyMute(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; - return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public User destroyMute(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; - return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); - } - - @Override - public SavedSearch destroySavedSearch(final int id) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createSavedSearch(post(conf.getRestBaseURL() + "saved_searches/destroy/" + id + ".json", - conf.getSigningRestBaseURL() + "saved_searches/destroy/" + id + ".json")); - } - - @Override - public Status destroyStatus(final long statusId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatus(post(conf.getRestBaseURL() + "statuses/destroy/" + statusId + ".json", - conf.getSigningRestBaseURL() + "statuses/destroy/" + statusId + ".json", INCLUDE_ENTITIES)); - } - - @Override - public UserList destroyUserList(final long listId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_DESTROY, new HttpParameter("list_id", listId))); - } - - @Override - public UserList destroyUserListSubscription(final long listId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory - .createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_DESTROY, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_DESTROY, new HttpParameter("list_id", - listId))); - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - - final TwitterImpl twitter = (TwitterImpl) o; - - if (!INCLUDE_ENTITIES.equals(twitter.INCLUDE_ENTITIES)) return false; - if (!INCLUDE_RTS.equals(twitter.INCLUDE_RTS)) return false; - - return true; - } - - @Override - public AccountSettings getAccountSettings() throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createAccountSettings(get(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS)); - } - - @Override - public ResponseList getActivitiesAboutMe() throws TwitterException { - return getActivitiesAboutMe(null); - } - - @Override - public ResponseList getActivitiesAboutMe(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createActivityList(get(conf.getRestBaseURL() + ENDPOINT_ACTIVITY_ABOUT_ME, - conf.getSigningRestBaseURL() + ENDPOINT_ACTIVITY_ABOUT_ME, - mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); - } - - @Override - public ResponseList getActivitiesByFriends() throws TwitterException { - return getActivitiesByFriends(null); - } - - @Override - public ResponseList getActivitiesByFriends(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createActivityList(get(conf.getRestBaseURL() + ENDPOINT_ACTIVITY_BY_FRIENDS, - conf.getSigningRestBaseURL() + ENDPOINT_ACTIVITY_BY_FRIENDS, - mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); - } - - @Override - public TwitterAPIConfiguration getAPIConfiguration() throws TwitterException { - return factory.createTwitterAPIConfiguration(get(conf.getRestBaseURL() + ENDPOINT_HELP_CONFIGURATION, - conf.getSigningRestBaseURL() + ENDPOINT_HELP_CONFIGURATION)); - } - - @Override - public ResponseList getAvailableTrends() throws TwitterException { - return factory.createLocationList(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE, - conf.getSigningRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE)); - } - - @Override - public ResponseList getAvailableTrends(final GeoLocation location) throws TwitterException { - return factory.createLocationList(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE, - conf.getSigningRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE, - new HttpParameter("lat", location.getLatitude()), new HttpParameter("long", location.getLongitude()))); - } - - @Override - public IDs getBlocksIDs() throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_IDS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_IDS; - return factory.createIDs(get(url, signUrl)); - } - - @Override - public IDs getBlocksIDs(final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_IDS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_IDS; - return factory.createIDs(get(url, signUrl, paging.asPostParameterArray())); - } - - @Override - public PagableResponseList getBlocksList() throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_LIST; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_LIST; - return factory.createPagableUserList(get(url, signUrl, INCLUDE_ENTITIES)); - } - - @Override - public PagableResponseList getBlocksList(final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_LIST; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_LIST; - final HttpParameter[] params = mergeParameters(paging.asPostParameterArray(), INCLUDE_ENTITIES); - return factory.createPagableUserList(get(url, signUrl, params)); - } - - @Override - public ResponseList getClosestTrends(final GeoLocation location) throws TwitterException { - return factory.createLocationList(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_CLOSEST, - conf.getSigningRestBaseURL() + ENDPOINT_TRENDS_CLOSEST, - new HttpParameter("lat", location.getLatitude()), new HttpParameter("long", location.getLongitude()))); - } - - @Override - public ResponseList getDirectMessages() throws TwitterException { - return getDirectMessages(null); - } - - @Override - public ResponseList getDirectMessages(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessageList(get(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES, - mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); - } - - @Override - public ResponseList getFavorites() throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, INCLUDE_ENTITIES)); - } - - @Override - public ResponseList getFavorites(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, new HttpParameter("user_id", userId), - INCLUDE_ENTITIES)); - } - - @Override - public ResponseList getFavorites(final long userId, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory - .createStatusList(get( - conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId), - INCLUDE_ENTITIES))); - } - - @Override - public ResponseList getFavorites(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, - mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); - } - - @Override - public ResponseList getFavorites(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, new HttpParameter("screen_name", screenName), - INCLUDE_ENTITIES)); - } - - @Override - public ResponseList getFavorites(final String screenName, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get( - conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName), - INCLUDE_ENTITIES))); - } - - @Override - public IDs getFollowersIDs(final CursorPaging paging) throws TwitterException { - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_IDS, conf.getSigningRestBaseURL() - + ENDPOINT_FOLLOWERS_IDS, paging.asPostParameterArray())); - } - - @Override - public IDs getFollowersIDs(final long userId, final CursorPaging paging) throws TwitterException { - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_IDS, conf.getSigningRestBaseURL() - + ENDPOINT_FOLLOWERS_IDS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); - } - - @Override - public IDs getFollowersIDs(final String screenName, final CursorPaging paging) throws TwitterException { - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_IDS, conf.getSigningRestBaseURL() - + ENDPOINT_FOLLOWERS_IDS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); - } - - @Override - public PagableResponseList getFollowersList(final CursorPaging paging) throws TwitterException { - return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, paging.asPostParameterArray())); - } - - @Override - public PagableResponseList getFollowersList(final long userId, final CursorPaging paging) - throws TwitterException { - return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); - } - - @Override - public PagableResponseList getFollowersList(final String screenName, final CursorPaging paging) - throws TwitterException { - return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); - } - - @Override - public IDs getFriendsIDs(final CursorPaging paging) throws TwitterException { - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_IDS, conf.getSigningRestBaseURL() - + ENDPOINT_FRIENDS_IDS, paging.asPostParameterArray())); - } - - @Override - public IDs getFriendsIDs(final long userId, final CursorPaging paging) throws TwitterException { - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_IDS, conf.getSigningRestBaseURL() - + ENDPOINT_FRIENDS_IDS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); - } - - @Override - public IDs getFriendsIDs(final String screenName, final CursorPaging paging) throws TwitterException { - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_IDS, conf.getSigningRestBaseURL() - + ENDPOINT_FRIENDS_IDS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); - } - - @Override - public PagableResponseList getFriendsList(final CursorPaging paging) throws TwitterException { - return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDS_LIST, paging.asPostParameterArray())); - } - - @Override - public PagableResponseList getFriendsList(final long userId, final CursorPaging paging) - throws TwitterException { - return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDS_LIST, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); - } - - @Override - public PagableResponseList getFriendsList(final String screenName, final CursorPaging paging) - throws TwitterException { - return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDS_LIST, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); - } - - @Override - public Place getGeoDetails(final String id) throws TwitterException { - return factory.createPlace(get(conf.getRestBaseURL() + "geo/id/" + id + ".json", conf.getSigningRestBaseURL() - + "geo/id/" + id + ".json")); - } - - @Override - public ResponseList getHomeTimeline() throws TwitterException { - return getHomeTimeline(null); - } - - @Override - public ResponseList getHomeTimeline(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_HOME_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_HOME_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public IDs getIncomingFriendships(final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_INCOMING, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_INCOMING, paging.asPostParameterArray())); - } - - @Override - public ResponseList getLanguages() throws TwitterException { - return factory.createLanguageList(get(conf.getRestBaseURL() + ENDPOINT_HELP_LANGUAGES, - conf.getSigningRestBaseURL() + ENDPOINT_HELP_LANGUAGES)); - } - - @Override - public Trends getLocationTrends(final int woeid) throws TwitterException { - return getPlaceTrends(woeid); - } - - @Override - public ResponseList getMediaTimeline() throws TwitterException { - return getMediaTimeline(new Paging()); - } - - @Override - public ResponseList getMediaTimeline(final long userId) throws TwitterException { - return getMediaTimeline(userId, null); - } - - @Override - public ResponseList getMediaTimeline(final long userId, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - paramsList.add(new HttpParameter("user_id", userId)); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public ResponseList getMediaTimeline(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public ResponseList getMediaTimeline(final String screenName) throws TwitterException { - return getMediaTimeline(screenName, null); - } - - @Override - public ResponseList getMediaTimeline(final String screenName, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - paramsList.add(new HttpParameter("screen_name", screenName)); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public ResponseList getMemberSuggestions(final String categorySlug) throws TwitterException { - final HttpResponse res = get(conf.getRestBaseURL() + "users/suggestions/" + categorySlug + "/members.json", - conf.getSigningRestBaseURL() + "users/suggestions/" + categorySlug + "/members.json"); - return factory.createUserListFromJSONArray(res); - } - - @Override - public ResponseList getMentionsTimeline() throws TwitterException { - ensureAuthorizationEnabled(); - return getMentionsTimeline(null); - } - - @Override - public ResponseList getMentionsTimeline(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MENTIONS_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MENTIONS_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public IDs getMutesUsersIDs() throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; - return factory.createIDs(get(url, signUrl)); - } - - @Override - public IDs getMutesUsersIDs(final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; - return factory.createIDs(get(url, signUrl, paging.asPostParameterArray())); - } - - @Override - public PagableResponseList getMutesUsersList() throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; - return factory.createPagableUserList(get(url, signUrl, INCLUDE_ENTITIES)); - } - - @Override - public PagableResponseList getMutesUsersList(final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; - final HttpParameter[] params = mergeParameters(paging.asPostParameterArray(), INCLUDE_ENTITIES); - return factory.createPagableUserList(get(url, signUrl, params)); - } - - @Override - public OEmbed getOEmbed(final OEmbedRequest req) throws TwitterException { - return factory.createOEmbed(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_OEMBED, conf.getRestBaseURL() - + ENDPOINT_STATUSES_OEMBED, req.asHttpParameterArray())); - } - - @Override - public IDs getOutgoingFriendships(final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_OUTGOING, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_OUTGOING, paging.asPostParameterArray())); - } - - @Override - public Trends getPlaceTrends(final int woeid) throws TwitterException { - return factory.createTrends(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_PLACE, conf.getSigningRestBaseURL() - + ENDPOINT_TRENDS_PLACE, new HttpParameter("id", woeid))); - } - - @Override - public String getPrivacyPolicy() throws TwitterException { - try { - return get(conf.getRestBaseURL() + ENDPOINT_LEGAL_PRIVACY, - conf.getSigningRestBaseURL() + ENDPOINT_LEGAL_PRIVACY).asJSONObject().getString("privacy"); - } catch (final JSONException e) { - throw new TwitterException(e); - } - } - - @Override - public Map getRateLimitStatus() throws TwitterException { - return factory.createRateLimitStatus(get(conf.getRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS, - conf.getSigningRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS)); - } - - @Override - public Map getRateLimitStatus(final String... resources) throws TwitterException { - return factory.createRateLimitStatus(get(conf.getRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS, - conf.getSigningRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS, new HttpParameter("resources", - InternalStringUtil.join(resources)))); - } - - @Override - public IDs getRetweetersIDs(final long statusId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, - conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, new HttpParameter("id", statusId))); - } - - @Override - public IDs getRetweetersIDs(final long statusId, final CursorPaging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, - conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("id", statusId)))); - } - - @Override - public ResponseList getRetweets(final long statusId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + "statuses/retweets/" + statusId + ".json", - conf.getSigningRestBaseURL() + "statuses/retweets/" + statusId + ".json", INCLUDE_ENTITIES)); - } - - @Override - public ResponseList getRetweets(final long statusId, final int count) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + "statuses/retweets/" + statusId + ".json", - conf.getSigningRestBaseURL() + "statuses/retweets/" + statusId + ".json", new HttpParameter("count", - count), INCLUDE_ENTITIES)); - } - - @Override - public ResponseList getRetweetsOfMe() throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, - conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, INCLUDE_ENTITIES, INCLUDE_RTS)); - } - - @Override - public ResponseList getRetweetsOfMe(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, - conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, - mergeParameters(paging.asPostParameterArray(), INCLUDE_RTS, INCLUDE_ENTITIES))); - } - - @Override - public ResponseList getSavedSearches() throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createSavedSearchList(get(conf.getRestBaseURL() + ENDPOINT_SAVED_SEARCHES_LIST, - conf.getSigningRestBaseURL() + ENDPOINT_SAVED_SEARCHES_LIST)); - } - - @Override - public ResponseList getSentDirectMessages() throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessageList(get(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, INCLUDE_ENTITIES)); - } - - @Override - public ResponseList getSentDirectMessages(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessageList(get(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, - mergeParameters(paging.asPostParameterArray(), INCLUDE_ENTITIES))); - } - - @Override - public SimilarPlaces getSimilarPlaces(final GeoLocation location, final String name, final String containedWithin, - final String streetAddress) throws TwitterException { - final List params = new ArrayList(3); - params.add(new HttpParameter("lat", location.getLatitude())); - params.add(new HttpParameter("long", location.getLongitude())); - params.add(new HttpParameter("name", name)); - if (containedWithin != null) { - params.add(new HttpParameter("contained_within", containedWithin)); - } - if (streetAddress != null) { - params.add(new HttpParameter("attribute:street_address", streetAddress)); - } - return factory.createSimilarPlaces(get(conf.getRestBaseURL() + ENDPOINT_GEO_SIMILAR_PLACES, - conf.getSigningRestBaseURL() + ENDPOINT_GEO_SIMILAR_PLACES, - params.toArray(new HttpParameter[params.size()]))); - } - - @Override - public StatusActivitySummary getStatusActivitySummary(final long statusId) throws TwitterException { - return getStatusActivitySummary(statusId, false); - } - - @Override - public StatusActivitySummary getStatusActivitySummary(final long statusId, final boolean includeDescendentReplyCount) - throws TwitterException { - final String endpoint = String.format(Locale.ROOT, "statuses/%d/activity/summary.json", statusId); - final String url = conf.getRestBaseURL() + endpoint; - final String signUrl = conf.getSigningRestBaseURL() + endpoint; - final HttpParameter paramIncludeDescendentReplyCount = new HttpParameter("include_descendent_reply_count", - includeDescendentReplyCount); - return factory.createStatusActivitySummary(get(url, signUrl, paramIncludeDescendentReplyCount)); - } - - @Override - public ResponseList getSuggestedUserCategories() throws TwitterException { - return factory.createCategoryList(get(conf.getRestBaseURL() + ENDPOINT_USERS_SUGGESTIONS, - conf.getSigningRestBaseURL() + ENDPOINT_USERS_SUGGESTIONS)); - } - - @Override - public String getTermsOfService() throws TwitterException { - try { - return get(conf.getRestBaseURL() + ENDPOINT_LEGAL_TOS, conf.getSigningRestBaseURL() + ENDPOINT_LEGAL_TOS) - .asJSONObject().getString("tos"); - } catch (final JSONException e) { - throw new TwitterException(e); - } - } - - @Override - public PagableResponseList getUserListMembers(final long listId, final CursorPaging paging) - throws TwitterException { - return factory - .createPagableUserList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("list_id", listId), - INCLUDE_ENTITIES))); - } - - @Override - public PagableResponseList getUserListMembers(final String slug, final long ownerId, final CursorPaging paging) - throws TwitterException { - return factory.createPagableUserList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( - "owner_id", ownerId), INCLUDE_ENTITIES))); - } - - @Override - public PagableResponseList getUserListMembers(final String slug, final String ownerScreenName, - final CursorPaging paging) throws TwitterException { - return factory.createPagableUserList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( - "owner_screen_name", ownerScreenName), INCLUDE_ENTITIES))); - } - - @Override - public PagableResponseList getUserListMemberships(final long cursor) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, new HttpParameter("cursor", cursor))); - - } - - @Override - public PagableResponseList getUserListMemberships(final long listMemberId, final long cursor) - throws TwitterException { - return getUserListMemberships(listMemberId, cursor, false); - } - - @Override - public PagableResponseList getUserListMemberships(final long listMemberId, final long cursor, - final boolean filterToOwnedLists) throws TwitterException { - if (filterToOwnedLists) { - ensureAuthorizationEnabled(); - } - return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, new HttpParameter("user_id", listMemberId), - new HttpParameter("cursor", cursor), new HttpParameter("filter_to_owned_lists", filterToOwnedLists))); - } - - @Override - public PagableResponseList getUserListMemberships(final String listMemberScreenName, final long cursor) - throws TwitterException { - return getUserListMemberships(listMemberScreenName, cursor, false); - } - - @Override - public PagableResponseList getUserListMemberships(final String listMemberScreenName, final long cursor, - final boolean filterToOwnedLists) throws TwitterException { - if (filterToOwnedLists) { - ensureAuthorizationEnabled(); - } - return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, new HttpParameter("screen_name", - listMemberScreenName), new HttpParameter("cursor", cursor), new HttpParameter( - "filter_to_owned_lists", filterToOwnedLists))); - } - - @Override - public PagableResponseList getUserListOwnerships(final long cursor) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; - return factory.createPagableUserListList(get(url, signUrl, new HttpParameter("cursor", cursor))); - - } - - @Override - public PagableResponseList getUserListOwnerships(final long listMemberId, final long cursor) - throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; - return factory.createPagableUserListList(get(url, signUrl, new HttpParameter("user_id", listMemberId), - new HttpParameter("cursor", cursor))); - } - - @Override - public PagableResponseList getUserListOwnerships(final String listMemberScreenName, final long cursor) - throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; - return factory.createPagableUserListList(get(url, signUrl, new HttpParameter("screen_name", - listMemberScreenName), new HttpParameter("cursor", cursor))); - } - - @Override - public ResponseList getUserLists(final long listOwnerUserId) throws TwitterException { - return factory.createUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_LIST, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_LIST, new HttpParameter("user_id", listOwnerUserId))); - } - - @Override - public ResponseList getUserLists(final String listOwnerScreenName) throws TwitterException { - return factory.createUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_LIST, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_LIST, new HttpParameter("screen_name", listOwnerScreenName))); - } - - @Override - public ResponseList getUserListStatuses(final long listId, final Paging paging) throws TwitterException { - return factory.createStatusList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_STATUSES, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_STATUSES, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("list_id", listId), INCLUDE_ENTITIES, - INCLUDE_RTS))); - } - - @Override - public ResponseList getUserListStatuses(final String slug, final long ownerId, final Paging paging) - throws TwitterException { - return factory.createStatusList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_STATUSES, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_STATUSES, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( - "owner_id", ownerId), INCLUDE_ENTITIES, INCLUDE_RTS))); - - } - - @Override - public ResponseList getUserListStatuses(final String slug, final String ownerScreenName, final Paging paging) - throws TwitterException { - return factory.createStatusList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_STATUSES, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_STATUSES, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( - "owner_screen_name", ownerScreenName), INCLUDE_ENTITIES, INCLUDE_RTS))); - } - - @Override - public PagableResponseList getUserListSubscribers(final long listId, final CursorPaging paging) - throws TwitterException { - return factory - .createPagableUserList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("list_id", listId), - INCLUDE_ENTITIES))); - } - - @Override - public PagableResponseList getUserListSubscribers(final String slug, final long ownerId, - final CursorPaging paging) throws TwitterException { - return factory.createPagableUserList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( - "owner_id", ownerId), INCLUDE_ENTITIES))); - } - - @Override - public PagableResponseList getUserListSubscribers(final String slug, final String ownerScreenName, - final CursorPaging paging) throws TwitterException { - return factory.createPagableUserList(get( - conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, - mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( - "owner_screen_name", ownerScreenName), INCLUDE_ENTITIES))); - } - - @Override - public PagableResponseList getUserListSubscriptions(final String listOwnerScreenName, final long cursor) - throws TwitterException { - return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIPTIONS, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIPTIONS, new HttpParameter("screen_name", - listOwnerScreenName), new HttpParameter("cursor", cursor))); - } - - @Override - public ResponseList getUserSuggestions(final String categorySlug) throws TwitterException { - final HttpResponse res = get(conf.getRestBaseURL() + "users/suggestions/" + categorySlug + ".json", - conf.getSigningRestBaseURL() + "users/suggestions/" + categorySlug + ".json"); - return factory.createUserListFromJSONArray_Users(res); - } - - @Override - public ResponseList getUserTimeline() throws TwitterException { - return getUserTimeline(new Paging()); - } - - @Override - public ResponseList getUserTimeline(final long userId) throws TwitterException { - return getUserTimeline(userId, null); - } - - @Override - public ResponseList getUserTimeline(final long userId, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - paramsList.add(new HttpParameter("user_id", userId)); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public ResponseList getUserTimeline(final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public ResponseList getUserTimeline(final String screenName) throws TwitterException { - return getUserTimeline(screenName, null); - } - - @Override - public ResponseList getUserTimeline(final String screenName, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - paramsList.add(new HttpParameter("screen_name", screenName)); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + INCLUDE_ENTITIES.hashCode(); - result = 31 * result + INCLUDE_RTS.hashCode(); - return result; - } - - @Override - public ResponseList lookupFriendships(final long[] ids) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createFriendshipList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, new HttpParameter("user_id", - InternalStringUtil.join(ids)))); - } - - @Override - public ResponseList lookupFriendships(final String[] screenNames) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createFriendshipList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, new HttpParameter("screen_name", - InternalStringUtil.join(screenNames)))); - } - - @Override - public ResponseList lookupUsers(final long[] ids) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUserList(get(conf.getRestBaseURL() + ENDPOINT_USERS_LOOKUP, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_LOOKUP, new HttpParameter("user_id", InternalStringUtil.join(ids)), INCLUDE_ENTITIES)); - } - - @Override - public ResponseList lookupUsers(final String[] screenNames) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUserList(get(conf.getRestBaseURL() + ENDPOINT_USERS_LOOKUP, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_LOOKUP, new HttpParameter("screen_name", InternalStringUtil.join(screenNames)), - INCLUDE_ENTITIES)); - } - - @Override - public void removeProfileBannerImage() throws TwitterException { - ensureAuthorizationEnabled(); - post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_REMOVE_PROFILE_BANNER, conf.getSigningRestBaseURL() - + ENDPOINT_ACCOUNT_REMOVE_PROFILE_BANNER); - - } - - @Override - public User reportSpam(final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_USERS_REPORT_SPAM, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_REPORT_SPAM, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public int reportSpam(final long statusId, final ReportAs reportAs, final boolean blockUser) - throws TwitterException { - ensureAuthorizationEnabled(); - final HttpParameter[] params = { new HttpParameter("status_id", statusId), - new HttpParameter("report_as", reportAs.value()), new HttpParameter("block_user", blockUser) }; - return post(conf.getRestBaseURL() + ENDPOINT_STATUSES_REPORT_SPAM, - conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_REPORT_SPAM, params).getStatusCode(); - } - - @Override - public User reportSpam(final String screenName) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_USERS_REPORT_SPAM, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_REPORT_SPAM, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); - } - - @Override - public Status retweetStatus(final long statusId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatus(post(conf.getRestBaseURL() + "statuses/retweet/" + statusId + ".json", - conf.getSigningRestBaseURL() + "statuses/retweet/" + statusId + ".json", INCLUDE_ENTITIES)); - } - - @Override - public ResponseList reverseGeoCode(final GeoQuery query) throws TwitterException { - try { - return factory.createPlaceList(get(conf.getRestBaseURL() + ENDPOINT_GEO_REVERSE_GEOCODE, - conf.getSigningRestBaseURL() + ENDPOINT_GEO_REVERSE_GEOCODE, query.asHttpParameterArray())); - } catch (final TwitterException te) { - if (te.getStatusCode() == 404) - return factory.createEmptyResponseList(); - else - throw te; - } - } - - @Override - public QueryResult search(final Query query) throws TwitterException { - return factory.createQueryResult( - get(conf.getRestBaseURL() + ENDPOINT_SEARCH_TWEETS, conf.getSigningRestBaseURL() - + ENDPOINT_SEARCH_TWEETS, query.asHttpParameterArray(INCLUDE_ENTITIES, INCLUDE_RTS)), query); - } - - @Override - public ResponseList searchPlaces(final GeoQuery query) throws TwitterException { - return factory.createPlaceList(get(conf.getRestBaseURL() + ENDPOINT_GEO_SEARCH, conf.getSigningRestBaseURL() - + ENDPOINT_GEO_SEARCH, query.asHttpParameterArray())); - } - - @Override - public ResponseList searchUsers(final String query, final int page) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUserList(get(conf.getRestBaseURL() + ENDPOINT_USERS_SEARCH, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_SEARCH, new HttpParameter("q", query), new HttpParameter("per_page", 20), - new HttpParameter("page", page), INCLUDE_ENTITIES)); - } - - @Override - public DirectMessage sendDirectMessage(final long userId, final String text) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("user_id", userId), - new HttpParameter("text", text), INCLUDE_ENTITIES)); - } - - @Override - public DirectMessage sendDirectMessage(final long userId, final String text, final long mediaId) - throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("user_id", userId), - new HttpParameter("text", text), new HttpParameter("media_id", mediaId), INCLUDE_ENTITIES)); - } - - @Override - public DirectMessage sendDirectMessage(final String screenName, final String text) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("screen_name", - screenName), new HttpParameter("text", text), INCLUDE_ENTITIES)); - } - - @Override - public DirectMessage sendDirectMessage(final String screenName, final String text, final long mediaId) - throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, - conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("screen_name", - screenName), new HttpParameter("text", text), new HttpParameter("media_id", mediaId), - INCLUDE_ENTITIES)); - - } - - @Override - public ResponseList showConversation(final long statusId) throws TwitterException { - return showConversation(statusId, null); - } - - @Override - public ResponseList showConversation(final long statusId, final Paging paging) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_CONVERSATION_SHOW; - final String sign_url = conf.getSigningRestBaseURL() + ENDPOINT_CONVERSATION_SHOW; - final List paramsList = new ArrayList(); - paramsList.add(INCLUDE_ENTITIES); - paramsList.add(INCLUDE_MY_RETWEET); - paramsList.add(new HttpParameter("id", statusId)); - if (paging != null) { - paramsList.addAll(paging.asPostParameterList()); - } - return factory.createStatusList(get(url, sign_url, paramsList.toArray(new HttpParameter[paramsList.size()]))); - } - - @Override - public DirectMessage showDirectMessage(final long id) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SHOW; - final String sign_url = conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SHOW; - return factory.createDirectMessage(get(url, sign_url, new HttpParameter("id", id), INCLUDE_ENTITIES)); - } - - @Override - public Relationship showFriendship(final long sourceId, final long targetId) throws TwitterException { - return factory.createRelationship(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, new HttpParameter("source_id", sourceId), - new HttpParameter("target_id", targetId))); - } - - @Override - public Relationship showFriendship(final String sourceScreenName, final String targetScreenName) - throws TwitterException { - return factory.createRelationship(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, - getParameterArray("source_screen_name", sourceScreenName, "target_screen_name", targetScreenName))); - } - - @Override - public SavedSearch showSavedSearch(final int id) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createSavedSearch(get(conf.getRestBaseURL() + "saved_searches/show/" + id + ".json", - conf.getSigningRestBaseURL() + "saved_searches/show/" + id + ".json")); - } - - @Override - public Status showStatus(final long statusId) throws TwitterException { - final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_SHOW; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_SHOW; - final HttpParameter paramStatus = new HttpParameter("id", statusId); - return factory.createStatus(get(url, signUrl, paramStatus, INCLUDE_ENTITIES, INCLUDE_MY_RETWEET)); - } - - @Override - public TranslationResult showTranslation(final long statusId, final String dest) throws TwitterException { - final String url = conf.getRestBaseURL() + ENDPOINT_TRANSLATIONS_SHOW; - final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_TRANSLATIONS_SHOW; - final HttpParameter paramStatus = new HttpParameter("id", statusId); - final HttpParameter paramDest = new HttpParameter("dest", dest); - return factory.createTranslationResult(get(url, signUrl, paramStatus, paramDest)); - } - - @Override - public User showUser(final long userId) throws TwitterException { - return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_USERS_SHOW, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_SHOW, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public User showUser(final String screenName) throws TwitterException { - return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_USERS_SHOW, conf.getSigningRestBaseURL() - + ENDPOINT_USERS_SHOW, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); - } - - @Override - public UserList showUserList(final long listId) throws TwitterException { - return factory.createAUserList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SHOW, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_SHOW, new HttpParameter("list_id", listId))); - } - - @Override - public UserList showUserList(final String slug, final long ownerId) throws TwitterException { - return factory.createAUserList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SHOW, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_SHOW, new HttpParameter("slug", slug), new HttpParameter("owner_id", ownerId))); - } - - @Override - public UserList showUserList(final String slug, final String ownerScreenName) throws TwitterException { - return factory.createAUserList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SHOW, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_SHOW, new HttpParameter("slug", slug), new HttpParameter("owner_screen_name", - ownerScreenName))); - } - - @Override - public User showUserListMembership(final long listId, final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_SHOW, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_MEMBERS_SHOW, new HttpParameter("list_id", listId), new HttpParameter("user_id", - userId), INCLUDE_ENTITIES)); - } - - @Override - public User showUserListSubscription(final long listId, final long userId) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_SHOW, - conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_SHOW, new HttpParameter("list_id", listId), - new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); - } - - @Override - public String toString() { - return "TwitterImpl{" + "INCLUDE_ENTITIES=" + INCLUDE_ENTITIES + ", INCLUDE_RTS=" + INCLUDE_RTS + '}'; - } - - @Override - public AccountSettings updateAccountSettings(final Integer trend_locationWoeid, final Boolean sleep_timeEnabled, - final String start_sleepTime, final String end_sleepTime, final String time_zone, final String lang) - throws TwitterException { - - ensureAuthorizationEnabled(); - - final List params = new ArrayList(6); - addParameterToList(params, "trend_location_woeid", trend_locationWoeid); - addParameterToList(params, "sleep_time_enabled", sleep_timeEnabled); - addParameterToList(params, "start_sleep_time", start_sleepTime); - addParameterToList(params, "end_sleep_time", end_sleepTime); - addParameterToList(params, "time_zone", time_zone); - addParameterToList(params, "lang", lang); - params.add(INCLUDE_ENTITIES); - return factory.createAccountSettings(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS, - params.toArray(new HttpParameter[params.size()]))); - } - - @Override - public Relationship updateFriendship(final long userId, final boolean enableDeviceNotification, - final boolean retweets) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createRelationship(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, new HttpParameter("user_id", userId), - new HttpParameter("device", enableDeviceNotification), new HttpParameter("retweets", - enableDeviceNotification))); - } - - @Override - public Relationship updateFriendship(final String screenName, final boolean enableDeviceNotification, - final boolean retweets) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createRelationship(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, - conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, - new HttpParameter("screen_name", screenName), new HttpParameter("device", enableDeviceNotification), - new HttpParameter("retweets", enableDeviceNotification))); - } - - @Override - public User updateProfile(final String name, final String url, final String location, final String description) - throws TwitterException { - ensureAuthorizationEnabled(); - final ArrayList params = new ArrayList(); - addParameterToList(params, "name", name); - addParameterToList(params, "url", url); - addParameterToList(params, "location", location); - addParameterToList(params, "description", description); - params.add(INCLUDE_ENTITIES); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE, - params.toArray(new HttpParameter[params.size()]))); - } - - @Override - public User updateProfileBackgroundImage(final File image, final boolean tile) throws TwitterException { - ensureAuthorizationEnabled(); - checkFileValidity(image); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, new HttpParameter( - "image", image), new HttpParameter("tile", tile), INCLUDE_ENTITIES)); - } - - @Override - public User updateProfileBackgroundImage(final InputStream image, final boolean tile) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, new HttpParameter( - "image", "image", image), new HttpParameter("tile", tile), INCLUDE_ENTITIES)); - } - - @Override - public void updateProfileBannerImage(final File banner) throws TwitterException { - ensureAuthorizationEnabled(); - checkFileValidity(banner); - post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() - + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, new HttpParameter("banner", banner)); - } - - @Override - public void updateProfileBannerImage(final File banner, final int width, final int height, final int offsetLeft, - final int offsetTop) throws TwitterException { - ensureAuthorizationEnabled(); - checkFileValidity(banner); - final List params = new ArrayList(5); - addParameterToList(params, "width", width); - addParameterToList(params, "height", height); - addParameterToList(params, "offset_left", offsetLeft); - addParameterToList(params, "offset_top", offsetTop); - params.add(new HttpParameter("banner", banner)); - post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() - + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, params.toArray(new HttpParameter[params.size()])); - - } - - @Override - public void updateProfileBannerImage(final InputStream banner) throws TwitterException { - ensureAuthorizationEnabled(); - post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() - + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, new HttpParameter("banner", "banner", banner)); - } - - @Override - public void updateProfileBannerImage(final InputStream banner, final int width, final int height, - final int offsetLeft, final int offsetTop) throws TwitterException { - ensureAuthorizationEnabled(); - final List params = new ArrayList(5); - addParameterToList(params, "width", width); - addParameterToList(params, "height", height); - addParameterToList(params, "offset_left", offsetLeft); - addParameterToList(params, "offset_top", offsetTop); - params.add(new HttpParameter("banner", "banner", banner)); - post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() - + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, params.toArray(new HttpParameter[params.size()])); - } - - @Override - public User updateProfileColors(final String profileBackgroundColor, final String profileTextColor, - final String profileLinkColor, final String profileSidebarFillColor, final String profileSidebarBorderColor) - throws TwitterException { - ensureAuthorizationEnabled(); - final List params = new ArrayList(6); - addParameterToList(params, "profile_background_color", profileBackgroundColor); - addParameterToList(params, "profile_text_color", profileTextColor); - addParameterToList(params, "profile_link_color", profileLinkColor); - addParameterToList(params, "profile_sidebar_fill_color", profileSidebarFillColor); - addParameterToList(params, "profile_sidebar_border_color", profileSidebarBorderColor); - params.add(INCLUDE_ENTITIES); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_COLORS, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_COLORS, - params.toArray(new HttpParameter[params.size()]))); - } - - @Override - public User updateProfileImage(final File image) throws TwitterException { - checkFileValidity(image); - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, - new HttpParameter("image", image), INCLUDE_ENTITIES)); - } - - @Override - public User updateProfileImage(final InputStream image) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, - conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, new HttpParameter("image", - "image", image), INCLUDE_ENTITIES)); - } - - @Override - public Status updateStatus(final StatusUpdate status) throws TwitterException { - ensureAuthorizationEnabled(); - final String url = conf.getRestBaseURL() - + (status.isWithMedia() ? ENDPOINT_STATUSES_UPDATE_WITH_MEDIA : ENDPOINT_STATUSES_UPDATE); - final String signUrl = conf.getSigningRestBaseURL() - + (status.isWithMedia() ? ENDPOINT_STATUSES_UPDATE_WITH_MEDIA : ENDPOINT_STATUSES_UPDATE); - return factory.createStatus(post(url, signUrl, status.asHttpParameterArray(INCLUDE_ENTITIES))); - } - - @Override - public Status updateStatus(final String status) throws TwitterException { - ensureAuthorizationEnabled(); - return factory.createStatus(post(conf.getRestBaseURL() + ENDPOINT_STATUSES_UPDATE, conf.getSigningRestBaseURL() - + ENDPOINT_STATUSES_UPDATE, new HttpParameter("status", status), INCLUDE_ENTITIES)); - } - - @Override - public UserList updateUserList(final long listId, final String newListName, final boolean isPublicList, - final String newDescription) throws TwitterException { - ensureAuthorizationEnabled(); - final List httpParams = new ArrayList(); - httpParams.add(new HttpParameter("list_id", listId)); - if (newListName != null) { - httpParams.add(new HttpParameter("name", newListName)); - } - httpParams.add(new HttpParameter("mode", isPublicList ? "public" : "private")); - if (newDescription != null) { - httpParams.add(new HttpParameter("description", newDescription)); - } - return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_UPDATE, conf.getSigningRestBaseURL() - + ENDPOINT_LISTS_UPDATE, httpParams.toArray(new HttpParameter[httpParams.size()]))); - } - - @Override - public MediaUploadResponse uploadMedia(final File file) throws TwitterException { - final String url = conf.getUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; - final String signUrl = conf.getSigningUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; - return factory.createMediaUploadResponse(post(url, signUrl, new HttpParameter("media", file))); - } - - @Override - public MediaUploadResponse uploadMedia(final String fileName, final InputStream fileBody, final String fileType) - throws TwitterException { - final String url = conf.getUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; - final String signUrl = conf.getSigningUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; - return factory.createMediaUploadResponse(post(url, signUrl, new HttpParameter("media", fileName, fileBody, - fileType))); - } - - @Override - public User verifyCredentials() throws TwitterException { - return super.fillInIDAndScreenName(); - } + private final HttpParameter INCLUDE_ENTITIES; + + private final HttpParameter INCLUDE_RTS; + + private final HttpParameter INCLUDE_MY_RETWEET; + + private final HttpParameter INCLUDE_REPLY_COUNT; + + private final HttpParameter INCLUDE_DESCENDENT_REPLY_COUNT; + + /* package */ + TwitterImpl(final Configuration conf, final Authorization auth) { + super(conf, auth); + INCLUDE_ENTITIES = new HttpParameter("include_entities", conf.isIncludeEntitiesEnabled()); + INCLUDE_RTS = new HttpParameter("include_rts", conf.isIncludeRTsEnabled()); + INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", 1); + INCLUDE_REPLY_COUNT = new HttpParameter("include_reply_count", conf.isIncludeReplyCountEnabled()); + INCLUDE_DESCENDENT_REPLY_COUNT = new HttpParameter("include_descendent_reply_count", conf.isIncludeDescendentReplyCountEnabled()); + } + + @Override + public User acceptFriendship(final long userId) throws TwitterException { + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId))); + } + + @Override + public User acceptFriendship(final String screenName) throws TwitterException { + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_ACCEPT; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName))); + } + + @Override + public UserList addUserListMember(final long listId, final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, new HttpParameter("list_id", listId), + new HttpParameter("list_id", listId))); + } + + @Override + public UserList addUserListMember(final long listId, final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE, new HttpParameter("list_id", listId), + new HttpParameter("screen_name", screenName))); + } + + @Override + public UserList addUserListMembers(final long listId, final long[] userIds) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, new HttpParameter("list_id", listId), + new HttpParameter("user_id", InternalStringUtil.join(userIds)))); + } + + @Override + public UserList addUserListMembers(final long listId, final String[] screenNames) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_CREATE_ALL, new HttpParameter("list_id", listId), + new HttpParameter("screen_name", InternalStringUtil.join(screenNames)))); + } + + @Override + public User createBlock(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public User createBlock(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); + } + + @Override + public Status createFavorite(final long id) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_CREATE; + return factory.createStatus(post(url, signUrl, new HttpParameter("id", id), INCLUDE_ENTITIES)); + } + + @Override + public User createFriendship(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId))); + } + + @Override + public User createFriendship(final long userId, final boolean follow) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), new HttpParameter("follow", + follow))); + } + + @Override + public User createFriendship(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName))); + } + + @Override + public User createFriendship(final String screenName, final boolean follow) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), new HttpParameter( + "follow", follow))); + } + + @Override + public User createMute(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public User createMute(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_CREATE; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); + } + + @Override + public Place createPlace(final String name, final String containedWithin, final String token, + final GeoLocation location, final String streetAddress) throws TwitterException { + ensureAuthorizationEnabled(); + final List params = new ArrayList(6); + addParameterToList(params, "name", name); + addParameterToList(params, "contained_within", containedWithin); + addParameterToList(params, "token", token); + addParameterToList(params, "lat", location.getLatitude()); + addParameterToList(params, "long", location.getLongitude()); + addParameterToList(params, "attribute:street_address", streetAddress); + return factory.createPlace(post(conf.getRestBaseURL() + ENDPOINT_GEO_PLACE, conf.getSigningRestBaseURL() + + ENDPOINT_GEO_PLACE, params.toArray(new HttpParameter[params.size()]))); + } + + @Override + public SavedSearch createSavedSearch(final String query) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createSavedSearch(post(conf.getRestBaseURL() + ENDPOINT_SAVED_SEARCHES_CREATE, + conf.getSigningRestBaseURL() + ENDPOINT_SAVED_SEARCHES_CREATE, new HttpParameter("query", query))); + } + + @Override + public UserList createUserList(final String listName, final boolean isPublicList, final String description) + throws TwitterException { + ensureAuthorizationEnabled(); + final List params = new ArrayList(); + addParameterToList(params, "name", listName); + addParameterToList(params, "mode", isPublicList ? "public" : "private"); + addParameterToList(params, "description", description); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_CREATE, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_CREATE, params.toArray(new HttpParameter[params.size()]))); + } + + @Override + public UserList createUserListSubscription(final long listId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory + .createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_CREATE, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_CREATE, new HttpParameter("list_id", + listId))); + } + + @Override + public UserList deleteUserListMember(final long listId, final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, new HttpParameter("list_id", listId), + new HttpParameter("user_id", userId))); + } + + @Override + public UserList deleteUserListMember(final long listId, final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY, new HttpParameter("list_id", listId), + new HttpParameter("screen_name", screenName))); + } + + @Override + public UserList deleteUserListMembers(final long listId, final long[] userIds) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, + new HttpParameter("list_id", listId), new HttpParameter("user_id", InternalStringUtil.join(userIds)))); + } + + @Override + public UserList deleteUserListMembers(final long listId, final String[] screenNames) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS_DESTROY_ALL, + new HttpParameter("list_id", listId), + new HttpParameter("screen_name", InternalStringUtil.join(screenNames)))); + } + + @Override + public User denyFriendship(final long userId) throws TwitterException { + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId))); + } + + @Override + public User denyFriendship(final String screenName) throws TwitterException { + final String url = conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DENY; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName))); + } + + @Override + public User destroyBlock(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_BLOCKS_DESTROY, conf.getSigningRestBaseURL() + + ENDPOINT_BLOCKS_DESTROY, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public User destroyBlock(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_BLOCKS_DESTROY, conf.getSigningRestBaseURL() + + ENDPOINT_BLOCKS_DESTROY, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); + } + + @Override + public DirectMessage destroyDirectMessage(final long id) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_DESTROY, new HttpParameter("id", id), + INCLUDE_ENTITIES)); + } + + @Override + public Status destroyFavorite(final long id) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatus(post(conf.getRestBaseURL() + ENDPOINT_FAVORITES_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_DESTROY, new HttpParameter("id", id), + INCLUDE_ENTITIES)); + } + + @Override + public User destroyFriendship(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, new HttpParameter("user_id", userId))); + } + + @Override + public User destroyFriendship(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_DESTROY, new HttpParameter("screen_name", + screenName))); + } + + @Override + public User destroyMute(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; + return factory.createUser(post(url, signUrl, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public User destroyMute(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_DESTROY; + return factory.createUser(post(url, signUrl, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); + } + + @Override + public SavedSearch destroySavedSearch(final int id) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createSavedSearch(post(conf.getRestBaseURL() + "saved_searches/destroy/" + id + ".json", + conf.getSigningRestBaseURL() + "saved_searches/destroy/" + id + ".json")); + } + + @Override + public Status destroyStatus(final long statusId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatus(post(conf.getRestBaseURL() + "statuses/destroy/" + statusId + ".json", + conf.getSigningRestBaseURL() + "statuses/destroy/" + statusId + ".json", INCLUDE_ENTITIES)); + } + + @Override + public UserList destroyUserList(final long listId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_DESTROY, new HttpParameter("list_id", listId))); + } + + @Override + public UserList destroyUserListSubscription(final long listId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory + .createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_DESTROY, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_DESTROY, new HttpParameter("list_id", + listId))); + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + final TwitterImpl twitter = (TwitterImpl) o; + + if (!INCLUDE_ENTITIES.equals(twitter.INCLUDE_ENTITIES)) return false; + if (!INCLUDE_RTS.equals(twitter.INCLUDE_RTS)) return false; + + return true; + } + + @Override + public AccountSettings getAccountSettings() throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createAccountSettings(get(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS)); + } + + @Override + public ResponseList getActivitiesAboutMe() throws TwitterException { + return getActivitiesAboutMe(null); + } + + @Override + public ResponseList getActivitiesAboutMe(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createActivityList(get(conf.getRestBaseURL() + ENDPOINT_ACTIVITY_ABOUT_ME, + conf.getSigningRestBaseURL() + ENDPOINT_ACTIVITY_ABOUT_ME, + mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); + } + + @Override + public ResponseList getActivitiesByFriends() throws TwitterException { + return getActivitiesByFriends(null); + } + + @Override + public ResponseList getActivitiesByFriends(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createActivityList(get(conf.getRestBaseURL() + ENDPOINT_ACTIVITY_BY_FRIENDS, + conf.getSigningRestBaseURL() + ENDPOINT_ACTIVITY_BY_FRIENDS, + mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); + } + + @Override + public TwitterAPIConfiguration getAPIConfiguration() throws TwitterException { + return factory.createTwitterAPIConfiguration(get(conf.getRestBaseURL() + ENDPOINT_HELP_CONFIGURATION, + conf.getSigningRestBaseURL() + ENDPOINT_HELP_CONFIGURATION)); + } + + @Override + public ResponseList getAvailableTrends() throws TwitterException { + return factory.createLocationList(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE, + conf.getSigningRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE)); + } + + @Override + public ResponseList getAvailableTrends(final GeoLocation location) throws TwitterException { + return factory.createLocationList(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE, + conf.getSigningRestBaseURL() + ENDPOINT_TRENDS_AVAILABLE, + new HttpParameter("lat", location.getLatitude()), new HttpParameter("long", location.getLongitude()))); + } + + @Override + public IDs getBlocksIDs() throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_IDS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_IDS; + return factory.createIDs(get(url, signUrl)); + } + + @Override + public IDs getBlocksIDs(final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_IDS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_IDS; + return factory.createIDs(get(url, signUrl, paging.asPostParameterArray())); + } + + @Override + public PagableResponseList getBlocksList() throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_LIST; + return factory.createPagableUserList(get(url, signUrl, INCLUDE_ENTITIES)); + } + + @Override + public PagableResponseList getBlocksList(final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_BLOCKS_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_BLOCKS_LIST; + final HttpParameter[] params = mergeParameters(paging.asPostParameterArray(), INCLUDE_ENTITIES); + return factory.createPagableUserList(get(url, signUrl, params)); + } + + @Override + public ResponseList getClosestTrends(final GeoLocation location) throws TwitterException { + return factory.createLocationList(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_CLOSEST, + conf.getSigningRestBaseURL() + ENDPOINT_TRENDS_CLOSEST, + new HttpParameter("lat", location.getLatitude()), new HttpParameter("long", location.getLongitude()))); + } + + @Override + public ResponseList getDirectMessages() throws TwitterException { + return getDirectMessages(null); + } + + @Override + public ResponseList getDirectMessages(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessageList(get(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES, + mergeParameters(paging != null ? paging.asPostParameterArray() : null, INCLUDE_ENTITIES))); + } + + @Override + public ResponseList getFavorites() throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST, INCLUDE_ENTITIES, + INCLUDE_REPLY_COUNT, INCLUDE_DESCENDENT_REPLY_COUNT)); + } + + @Override + public ResponseList getFavorites(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST; + return factory.createStatusList(get(url, signUrl, new HttpParameter("user_id", userId), + INCLUDE_ENTITIES, INCLUDE_REPLY_COUNT, INCLUDE_DESCENDENT_REPLY_COUNT)); + } + + @Override + public ResponseList getFavorites(final long userId, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST; + return factory.createStatusList(get(url, signUrl, mergeParameters(paging.asPostParameterArray(), + new HttpParameter("user_id", userId), INCLUDE_ENTITIES, INCLUDE_REPLY_COUNT, + INCLUDE_DESCENDENT_REPLY_COUNT))); + } + + @Override + public ResponseList getFavorites(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST; + return factory.createStatusList(get(url, signUrl, mergeParameters( + paging != null ? paging.asPostParameterArray() : null, + INCLUDE_ENTITIES, INCLUDE_REPLY_COUNT, INCLUDE_DESCENDENT_REPLY_COUNT))); + } + + @Override + public ResponseList getFavorites(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST; + return factory.createStatusList(get(url, signUrl, new HttpParameter("screen_name", screenName), + INCLUDE_ENTITIES, INCLUDE_REPLY_COUNT, INCLUDE_DESCENDENT_REPLY_COUNT)); + } + + @Override + public ResponseList getFavorites(final String screenName, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_FAVORITES_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_FAVORITES_LIST; + return factory.createStatusList(get(url, signUrl, mergeParameters(paging.asPostParameterArray(), + new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES, INCLUDE_REPLY_COUNT, + INCLUDE_DESCENDENT_REPLY_COUNT))); + } + + @Override + public IDs getFollowersIDs(final CursorPaging paging) throws TwitterException { + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_IDS, conf.getSigningRestBaseURL() + + ENDPOINT_FOLLOWERS_IDS, paging.asPostParameterArray())); + } + + @Override + public IDs getFollowersIDs(final long userId, final CursorPaging paging) throws TwitterException { + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_IDS, conf.getSigningRestBaseURL() + + ENDPOINT_FOLLOWERS_IDS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); + } + + @Override + public IDs getFollowersIDs(final String screenName, final CursorPaging paging) throws TwitterException { + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_IDS, conf.getSigningRestBaseURL() + + ENDPOINT_FOLLOWERS_IDS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); + } + + @Override + public PagableResponseList getFollowersList(final CursorPaging paging) throws TwitterException { + return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, paging.asPostParameterArray())); + } + + @Override + public PagableResponseList getFollowersList(final long userId, final CursorPaging paging) + throws TwitterException { + return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); + } + + @Override + public PagableResponseList getFollowersList(final String screenName, final CursorPaging paging) + throws TwitterException { + return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FOLLOWERS_LIST, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); + } + + @Override + public IDs getFriendsIDs(final CursorPaging paging) throws TwitterException { + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_IDS, conf.getSigningRestBaseURL() + + ENDPOINT_FRIENDS_IDS, paging.asPostParameterArray())); + } + + @Override + public IDs getFriendsIDs(final long userId, final CursorPaging paging) throws TwitterException { + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_IDS, conf.getSigningRestBaseURL() + + ENDPOINT_FRIENDS_IDS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); + } + + @Override + public IDs getFriendsIDs(final String screenName, final CursorPaging paging) throws TwitterException { + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_IDS, conf.getSigningRestBaseURL() + + ENDPOINT_FRIENDS_IDS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); + } + + @Override + public PagableResponseList getFriendsList(final CursorPaging paging) throws TwitterException { + return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDS_LIST, paging.asPostParameterArray())); + } + + @Override + public PagableResponseList getFriendsList(final long userId, final CursorPaging paging) + throws TwitterException { + return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDS_LIST, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("user_id", userId)))); + } + + @Override + public PagableResponseList getFriendsList(final String screenName, final CursorPaging paging) + throws TwitterException { + return factory.createPagableUserList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDS_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDS_LIST, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("screen_name", screenName)))); + } + + @Override + public Place getGeoDetails(final String id) throws TwitterException { + return factory.createPlace(get(conf.getRestBaseURL() + "geo/id/" + id + ".json", conf.getSigningRestBaseURL() + + "geo/id/" + id + ".json")); + } + + @Override + public ResponseList getHomeTimeline() throws TwitterException { + return getHomeTimeline(null); + } + + @Override + public ResponseList getHomeTimeline(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_HOME_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_HOME_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_MY_RETWEET); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public IDs getIncomingFriendships(final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_INCOMING, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_INCOMING, paging.asPostParameterArray())); + } + + @Override + public ResponseList getLanguages() throws TwitterException { + return factory.createLanguageList(get(conf.getRestBaseURL() + ENDPOINT_HELP_LANGUAGES, + conf.getSigningRestBaseURL() + ENDPOINT_HELP_LANGUAGES)); + } + + @Override + public Trends getLocationTrends(final int woeid) throws TwitterException { + return getPlaceTrends(woeid); + } + + @Override + public ResponseList getMediaTimeline() throws TwitterException { + return getMediaTimeline(new Paging()); + } + + @Override + public ResponseList getMediaTimeline(final long userId) throws TwitterException { + return getMediaTimeline(userId, null); + } + + @Override + public ResponseList getMediaTimeline(final long userId, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_MY_RETWEET); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(new HttpParameter("user_id", userId)); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public ResponseList getMediaTimeline(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(INCLUDE_MY_RETWEET); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public ResponseList getMediaTimeline(final String screenName) throws TwitterException { + return getMediaTimeline(screenName, null); + } + + @Override + public ResponseList getMediaTimeline(final String screenName, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MEDIA_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_MY_RETWEET); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(new HttpParameter("screen_name", screenName)); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public ResponseList getMemberSuggestions(final String categorySlug) throws TwitterException { + final HttpResponse res = get(conf.getRestBaseURL() + "users/suggestions/" + categorySlug + "/members.json", + conf.getSigningRestBaseURL() + "users/suggestions/" + categorySlug + "/members.json"); + return factory.createUserListFromJSONArray(res); + } + + @Override + public ResponseList getMentionsTimeline() throws TwitterException { + ensureAuthorizationEnabled(); + return getMentionsTimeline(null); + } + + @Override + public ResponseList getMentionsTimeline(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_MENTIONS_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_MENTIONS_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(INCLUDE_MY_RETWEET); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public IDs getMutesUsersIDs() throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; + return factory.createIDs(get(url, signUrl)); + } + + @Override + public IDs getMutesUsersIDs(final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_IDS; + return factory.createIDs(get(url, signUrl, paging.asPostParameterArray())); + } + + @Override + public PagableResponseList getMutesUsersList() throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; + return factory.createPagableUserList(get(url, signUrl, INCLUDE_ENTITIES)); + } + + @Override + public PagableResponseList getMutesUsersList(final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_MUTES_USERS_LIST; + final HttpParameter[] params = mergeParameters(paging.asPostParameterArray(), INCLUDE_ENTITIES); + return factory.createPagableUserList(get(url, signUrl, params)); + } + + @Override + public OEmbed getOEmbed(final OEmbedRequest req) throws TwitterException { + return factory.createOEmbed(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_OEMBED, conf.getRestBaseURL() + + ENDPOINT_STATUSES_OEMBED, req.asHttpParameterArray())); + } + + @Override + public IDs getOutgoingFriendships(final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_OUTGOING, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_OUTGOING, paging.asPostParameterArray())); + } + + @Override + public Trends getPlaceTrends(final int woeid) throws TwitterException { + return factory.createTrends(get(conf.getRestBaseURL() + ENDPOINT_TRENDS_PLACE, conf.getSigningRestBaseURL() + + ENDPOINT_TRENDS_PLACE, new HttpParameter("id", woeid))); + } + + @Override + public String getPrivacyPolicy() throws TwitterException { + try { + return get(conf.getRestBaseURL() + ENDPOINT_LEGAL_PRIVACY, + conf.getSigningRestBaseURL() + ENDPOINT_LEGAL_PRIVACY).asJSONObject().getString("privacy"); + } catch (final JSONException e) { + throw new TwitterException(e); + } + } + + @Override + public Map getRateLimitStatus() throws TwitterException { + return factory.createRateLimitStatus(get(conf.getRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS, + conf.getSigningRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS)); + } + + @Override + public Map getRateLimitStatus(final String... resources) throws TwitterException { + return factory.createRateLimitStatus(get(conf.getRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS, + conf.getSigningRestBaseURL() + ENDPOINT_RATE_LIMIT_STATUS, new HttpParameter("resources", + InternalStringUtil.join(resources)))); + } + + @Override + public IDs getRetweetersIDs(final long statusId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, + conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, new HttpParameter("id", statusId))); + } + + @Override + public IDs getRetweetersIDs(final long statusId, final CursorPaging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createIDs(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, + conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETERS_IDS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("id", statusId)))); + } + + @Override + public ResponseList getRetweets(final long statusId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatusList(get(conf.getRestBaseURL() + "statuses/retweets/" + statusId + ".json", + conf.getSigningRestBaseURL() + "statuses/retweets/" + statusId + ".json", INCLUDE_ENTITIES)); + } + + @Override + public ResponseList getRetweets(final long statusId, final int count) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatusList(get(conf.getRestBaseURL() + "statuses/retweets/" + statusId + ".json", + conf.getSigningRestBaseURL() + "statuses/retweets/" + statusId + ".json", new HttpParameter("count", + count), INCLUDE_ENTITIES)); + } + + @Override + public ResponseList getRetweetsOfMe() throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, + conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, INCLUDE_ENTITIES, INCLUDE_RTS)); + } + + @Override + public ResponseList getRetweetsOfMe(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatusList(get(conf.getRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, + conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_RETWEETS_OF_ME, + mergeParameters(paging.asPostParameterArray(), INCLUDE_RTS, INCLUDE_ENTITIES))); + } + + @Override + public ResponseList getSavedSearches() throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createSavedSearchList(get(conf.getRestBaseURL() + ENDPOINT_SAVED_SEARCHES_LIST, + conf.getSigningRestBaseURL() + ENDPOINT_SAVED_SEARCHES_LIST)); + } + + @Override + public ResponseList getSentDirectMessages() throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessageList(get(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, INCLUDE_ENTITIES)); + } + + @Override + public ResponseList getSentDirectMessages(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessageList(get(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SENT, + mergeParameters(paging.asPostParameterArray(), INCLUDE_ENTITIES))); + } + + @Override + public SimilarPlaces getSimilarPlaces(final GeoLocation location, final String name, final String containedWithin, + final String streetAddress) throws TwitterException { + final List params = new ArrayList(3); + params.add(new HttpParameter("lat", location.getLatitude())); + params.add(new HttpParameter("long", location.getLongitude())); + params.add(new HttpParameter("name", name)); + if (containedWithin != null) { + params.add(new HttpParameter("contained_within", containedWithin)); + } + if (streetAddress != null) { + params.add(new HttpParameter("attribute:street_address", streetAddress)); + } + return factory.createSimilarPlaces(get(conf.getRestBaseURL() + ENDPOINT_GEO_SIMILAR_PLACES, + conf.getSigningRestBaseURL() + ENDPOINT_GEO_SIMILAR_PLACES, + params.toArray(new HttpParameter[params.size()]))); + } + + @Override + public StatusActivitySummary getStatusActivitySummary(final long statusId) throws TwitterException { + return getStatusActivitySummary(statusId, false); + } + + @Override + public StatusActivitySummary getStatusActivitySummary(final long statusId, final boolean includeDescendentReplyCount) + throws TwitterException { + final String endpoint = String.format(Locale.ROOT, "statuses/%d/activity/summary.json", statusId); + final String url = conf.getRestBaseURL() + endpoint; + final String signUrl = conf.getSigningRestBaseURL() + endpoint; + final HttpParameter paramIncludeDescendentReplyCount = new HttpParameter("include_descendent_reply_count", + includeDescendentReplyCount); + return factory.createStatusActivitySummary(get(url, signUrl, paramIncludeDescendentReplyCount)); + } + + @Override + public ResponseList getSuggestedUserCategories() throws TwitterException { + return factory.createCategoryList(get(conf.getRestBaseURL() + ENDPOINT_USERS_SUGGESTIONS, + conf.getSigningRestBaseURL() + ENDPOINT_USERS_SUGGESTIONS)); + } + + @Override + public String getTermsOfService() throws TwitterException { + try { + return get(conf.getRestBaseURL() + ENDPOINT_LEGAL_TOS, conf.getSigningRestBaseURL() + ENDPOINT_LEGAL_TOS) + .asJSONObject().getString("tos"); + } catch (final JSONException e) { + throw new TwitterException(e); + } + } + + @Override + public PagableResponseList getUserListMembers(final long listId, final CursorPaging paging) + throws TwitterException { + return factory + .createPagableUserList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("list_id", listId), + INCLUDE_ENTITIES))); + } + + @Override + public PagableResponseList getUserListMembers(final String slug, final long ownerId, final CursorPaging paging) + throws TwitterException { + return factory.createPagableUserList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( + "owner_id", ownerId), INCLUDE_ENTITIES))); + } + + @Override + public PagableResponseList getUserListMembers(final String slug, final String ownerScreenName, + final CursorPaging paging) throws TwitterException { + return factory.createPagableUserList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( + "owner_screen_name", ownerScreenName), INCLUDE_ENTITIES))); + } + + @Override + public PagableResponseList getUserListMemberships(final long cursor) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, new HttpParameter("cursor", cursor))); + + } + + @Override + public PagableResponseList getUserListMemberships(final long listMemberId, final long cursor) + throws TwitterException { + return getUserListMemberships(listMemberId, cursor, false); + } + + @Override + public PagableResponseList getUserListMemberships(final long listMemberId, final long cursor, + final boolean filterToOwnedLists) throws TwitterException { + if (filterToOwnedLists) { + ensureAuthorizationEnabled(); + } + return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, new HttpParameter("user_id", listMemberId), + new HttpParameter("cursor", cursor), new HttpParameter("filter_to_owned_lists", filterToOwnedLists))); + } + + @Override + public PagableResponseList getUserListMemberships(final String listMemberScreenName, final long cursor) + throws TwitterException { + return getUserListMemberships(listMemberScreenName, cursor, false); + } + + @Override + public PagableResponseList getUserListMemberships(final String listMemberScreenName, final long cursor, + final boolean filterToOwnedLists) throws TwitterException { + if (filterToOwnedLists) { + ensureAuthorizationEnabled(); + } + return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_MEMBERSHIPS, new HttpParameter("screen_name", + listMemberScreenName), new HttpParameter("cursor", cursor), new HttpParameter( + "filter_to_owned_lists", filterToOwnedLists))); + } + + @Override + public PagableResponseList getUserListOwnerships(final long cursor) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; + return factory.createPagableUserListList(get(url, signUrl, new HttpParameter("cursor", cursor))); + + } + + @Override + public PagableResponseList getUserListOwnerships(final long listMemberId, final long cursor) + throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; + return factory.createPagableUserListList(get(url, signUrl, new HttpParameter("user_id", listMemberId), + new HttpParameter("cursor", cursor))); + } + + @Override + public PagableResponseList getUserListOwnerships(final String listMemberScreenName, final long cursor) + throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_LISTS_OWNERSHIPS; + return factory.createPagableUserListList(get(url, signUrl, new HttpParameter("screen_name", + listMemberScreenName), new HttpParameter("cursor", cursor))); + } + + @Override + public ResponseList getUserLists(final long listOwnerUserId) throws TwitterException { + return factory.createUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_LIST, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_LIST, new HttpParameter("user_id", listOwnerUserId))); + } + + @Override + public ResponseList getUserLists(final String listOwnerScreenName) throws TwitterException { + return factory.createUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_LIST, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_LIST, new HttpParameter("screen_name", listOwnerScreenName))); + } + + @Override + public ResponseList getUserListStatuses(final long listId, final Paging paging) throws TwitterException { + return factory.createStatusList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_STATUSES, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_STATUSES, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("list_id", listId), INCLUDE_ENTITIES, + INCLUDE_RTS))); + } + + @Override + public ResponseList getUserListStatuses(final String slug, final long ownerId, final Paging paging) + throws TwitterException { + return factory.createStatusList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_STATUSES, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_STATUSES, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( + "owner_id", ownerId), INCLUDE_ENTITIES, INCLUDE_RTS))); + + } + + @Override + public ResponseList getUserListStatuses(final String slug, final String ownerScreenName, final Paging paging) + throws TwitterException { + return factory.createStatusList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_STATUSES, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_STATUSES, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( + "owner_screen_name", ownerScreenName), INCLUDE_ENTITIES, INCLUDE_RTS))); + } + + @Override + public PagableResponseList getUserListSubscribers(final long listId, final CursorPaging paging) + throws TwitterException { + return factory + .createPagableUserList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("list_id", listId), + INCLUDE_ENTITIES))); + } + + @Override + public PagableResponseList getUserListSubscribers(final String slug, final long ownerId, + final CursorPaging paging) throws TwitterException { + return factory.createPagableUserList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( + "owner_id", ownerId), INCLUDE_ENTITIES))); + } + + @Override + public PagableResponseList getUserListSubscribers(final String slug, final String ownerScreenName, + final CursorPaging paging) throws TwitterException { + return factory.createPagableUserList(get( + conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS, + mergeParameters(paging.asPostParameterArray(), new HttpParameter("slug", slug), new HttpParameter( + "owner_screen_name", ownerScreenName), INCLUDE_ENTITIES))); + } + + @Override + public PagableResponseList getUserListSubscriptions(final String listOwnerScreenName, final long cursor) + throws TwitterException { + return factory.createPagableUserListList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIPTIONS, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIPTIONS, new HttpParameter("screen_name", + listOwnerScreenName), new HttpParameter("cursor", cursor))); + } + + @Override + public ResponseList getUserSuggestions(final String categorySlug) throws TwitterException { + final HttpResponse res = get(conf.getRestBaseURL() + "users/suggestions/" + categorySlug + ".json", + conf.getSigningRestBaseURL() + "users/suggestions/" + categorySlug + ".json"); + return factory.createUserListFromJSONArray_Users(res); + } + + @Override + public ResponseList getUserTimeline() throws TwitterException { + return getUserTimeline(new Paging()); + } + + @Override + public ResponseList getUserTimeline(final long userId) throws TwitterException { + return getUserTimeline(userId, null); + } + + @Override + public ResponseList getUserTimeline(final long userId, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(INCLUDE_MY_RETWEET); + paramsList.add(new HttpParameter("user_id", userId)); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public ResponseList getUserTimeline(final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(INCLUDE_MY_RETWEET); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public ResponseList getUserTimeline(final String screenName) throws TwitterException { + return getUserTimeline(screenName, null); + } + + @Override + public ResponseList getUserTimeline(final String screenName, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_USER_TIMELINE; + final List paramsList = new ArrayList<>(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_REPLY_COUNT); + paramsList.add(INCLUDE_DESCENDENT_REPLY_COUNT); + paramsList.add(INCLUDE_MY_RETWEET); + paramsList.add(new HttpParameter("screen_name", screenName)); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, signUrl, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + INCLUDE_ENTITIES.hashCode(); + result = 31 * result + INCLUDE_RTS.hashCode(); + return result; + } + + @Override + public ResponseList lookupFriendships(final long[] ids) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createFriendshipList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, new HttpParameter("user_id", + InternalStringUtil.join(ids)))); + } + + @Override + public ResponseList lookupFriendships(final String[] screenNames) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createFriendshipList(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_LOOKUP, new HttpParameter("screen_name", + InternalStringUtil.join(screenNames)))); + } + + @Override + public ResponseList lookupUsers(final long[] ids) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUserList(get(conf.getRestBaseURL() + ENDPOINT_USERS_LOOKUP, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_LOOKUP, new HttpParameter("user_id", InternalStringUtil.join(ids)), INCLUDE_ENTITIES)); + } + + @Override + public ResponseList lookupUsers(final String[] screenNames) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUserList(get(conf.getRestBaseURL() + ENDPOINT_USERS_LOOKUP, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_LOOKUP, new HttpParameter("screen_name", InternalStringUtil.join(screenNames)), + INCLUDE_ENTITIES)); + } + + @Override + public void removeProfileBannerImage() throws TwitterException { + ensureAuthorizationEnabled(); + post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_REMOVE_PROFILE_BANNER, conf.getSigningRestBaseURL() + + ENDPOINT_ACCOUNT_REMOVE_PROFILE_BANNER); + + } + + @Override + public User reportSpam(final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_USERS_REPORT_SPAM, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_REPORT_SPAM, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public int reportSpam(final long statusId, final ReportAs reportAs, final boolean blockUser) + throws TwitterException { + ensureAuthorizationEnabled(); + final HttpParameter[] params = {new HttpParameter("status_id", statusId), + new HttpParameter("report_as", reportAs.value()), new HttpParameter("block_user", blockUser)}; + return post(conf.getRestBaseURL() + ENDPOINT_STATUSES_REPORT_SPAM, + conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_REPORT_SPAM, params).getStatusCode(); + } + + @Override + public User reportSpam(final String screenName) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_USERS_REPORT_SPAM, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_REPORT_SPAM, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); + } + + @Override + public Status retweetStatus(final long statusId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatus(post(conf.getRestBaseURL() + "statuses/retweet/" + statusId + ".json", + conf.getSigningRestBaseURL() + "statuses/retweet/" + statusId + ".json", INCLUDE_ENTITIES)); + } + + @Override + public ResponseList reverseGeoCode(final GeoQuery query) throws TwitterException { + try { + return factory.createPlaceList(get(conf.getRestBaseURL() + ENDPOINT_GEO_REVERSE_GEOCODE, + conf.getSigningRestBaseURL() + ENDPOINT_GEO_REVERSE_GEOCODE, query.asHttpParameterArray())); + } catch (final TwitterException te) { + if (te.getStatusCode() == 404) + return factory.createEmptyResponseList(); + else + throw te; + } + } + + @Override + public QueryResult search(final Query query) throws TwitterException { + return factory.createQueryResult( + get(conf.getRestBaseURL() + ENDPOINT_SEARCH_TWEETS, conf.getSigningRestBaseURL() + + ENDPOINT_SEARCH_TWEETS, query.asHttpParameterArray(INCLUDE_ENTITIES, INCLUDE_RTS)), query); + } + + @Override + public ResponseList searchPlaces(final GeoQuery query) throws TwitterException { + return factory.createPlaceList(get(conf.getRestBaseURL() + ENDPOINT_GEO_SEARCH, conf.getSigningRestBaseURL() + + ENDPOINT_GEO_SEARCH, query.asHttpParameterArray())); + } + + @Override + public ResponseList searchUsers(final String query, final int page) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUserList(get(conf.getRestBaseURL() + ENDPOINT_USERS_SEARCH, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_SEARCH, new HttpParameter("q", query), new HttpParameter("per_page", 20), + new HttpParameter("page", page), INCLUDE_ENTITIES)); + } + + @Override + public DirectMessage sendDirectMessage(final long userId, final String text) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("user_id", userId), + new HttpParameter("text", text), INCLUDE_ENTITIES)); + } + + @Override + public DirectMessage sendDirectMessage(final long userId, final String text, final long mediaId) + throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("user_id", userId), + new HttpParameter("text", text), new HttpParameter("media_id", mediaId), INCLUDE_ENTITIES)); + } + + @Override + public DirectMessage sendDirectMessage(final String screenName, final String text) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("screen_name", + screenName), new HttpParameter("text", text), INCLUDE_ENTITIES)); + } + + @Override + public DirectMessage sendDirectMessage(final String screenName, final String text, final long mediaId) + throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createDirectMessage(post(conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, + conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_NEW, new HttpParameter("screen_name", + screenName), new HttpParameter("text", text), new HttpParameter("media_id", mediaId), + INCLUDE_ENTITIES)); + + } + + @Override + public ResponseList showConversation(final long statusId) throws TwitterException { + return showConversation(statusId, null); + } + + @Override + public ResponseList showConversation(final long statusId, final Paging paging) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_CONVERSATION_SHOW; + final String sign_url = conf.getSigningRestBaseURL() + ENDPOINT_CONVERSATION_SHOW; + final List paramsList = new ArrayList(); + paramsList.add(INCLUDE_ENTITIES); + paramsList.add(INCLUDE_MY_RETWEET); + paramsList.add(new HttpParameter("id", statusId)); + if (paging != null) { + paramsList.addAll(paging.asPostParameterList()); + } + return factory.createStatusList(get(url, sign_url, paramsList.toArray(new HttpParameter[paramsList.size()]))); + } + + @Override + public DirectMessage showDirectMessage(final long id) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SHOW; + final String sign_url = conf.getSigningRestBaseURL() + ENDPOINT_DIRECT_MESSAGES_SHOW; + return factory.createDirectMessage(get(url, sign_url, new HttpParameter("id", id), INCLUDE_ENTITIES)); + } + + @Override + public Relationship showFriendship(final long sourceId, final long targetId) throws TwitterException { + return factory.createRelationship(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, new HttpParameter("source_id", sourceId), + new HttpParameter("target_id", targetId))); + } + + @Override + public Relationship showFriendship(final String sourceScreenName, final String targetScreenName) + throws TwitterException { + return factory.createRelationship(get(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_SHOW, + getParameterArray("source_screen_name", sourceScreenName, "target_screen_name", targetScreenName))); + } + + @Override + public SavedSearch showSavedSearch(final int id) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createSavedSearch(get(conf.getRestBaseURL() + "saved_searches/show/" + id + ".json", + conf.getSigningRestBaseURL() + "saved_searches/show/" + id + ".json")); + } + + @Override + public Status showStatus(final long statusId) throws TwitterException { + final String url = conf.getRestBaseURL() + ENDPOINT_STATUSES_SHOW; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_STATUSES_SHOW; + final HttpParameter paramStatus = new HttpParameter("id", statusId); + return factory.createStatus(get(url, signUrl, paramStatus, INCLUDE_ENTITIES, + INCLUDE_MY_RETWEET, INCLUDE_REPLY_COUNT, INCLUDE_DESCENDENT_REPLY_COUNT)); + } + + @Override + public TranslationResult showTranslation(final long statusId, final String dest) throws TwitterException { + final String url = conf.getRestBaseURL() + ENDPOINT_TRANSLATIONS_SHOW; + final String signUrl = conf.getSigningRestBaseURL() + ENDPOINT_TRANSLATIONS_SHOW; + final HttpParameter paramStatus = new HttpParameter("id", statusId); + final HttpParameter paramDest = new HttpParameter("dest", dest); + return factory.createTranslationResult(get(url, signUrl, paramStatus, paramDest)); + } + + @Override + public User showUser(final long userId) throws TwitterException { + return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_USERS_SHOW, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_SHOW, new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public User showUser(final String screenName) throws TwitterException { + return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_USERS_SHOW, conf.getSigningRestBaseURL() + + ENDPOINT_USERS_SHOW, new HttpParameter("screen_name", screenName), INCLUDE_ENTITIES)); + } + + @Override + public UserList showUserList(final long listId) throws TwitterException { + return factory.createAUserList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SHOW, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_SHOW, new HttpParameter("list_id", listId))); + } + + @Override + public UserList showUserList(final String slug, final long ownerId) throws TwitterException { + return factory.createAUserList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SHOW, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_SHOW, new HttpParameter("slug", slug), new HttpParameter("owner_id", ownerId))); + } + + @Override + public UserList showUserList(final String slug, final String ownerScreenName) throws TwitterException { + return factory.createAUserList(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SHOW, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_SHOW, new HttpParameter("slug", slug), new HttpParameter("owner_screen_name", + ownerScreenName))); + } + + @Override + public User showUserListMembership(final long listId, final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_LISTS_MEMBERS_SHOW, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_MEMBERS_SHOW, new HttpParameter("list_id", listId), new HttpParameter("user_id", + userId), INCLUDE_ENTITIES)); + } + + @Override + public User showUserListSubscription(final long listId, final long userId) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(get(conf.getRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_SHOW, + conf.getSigningRestBaseURL() + ENDPOINT_LISTS_SUBSCRIBERS_SHOW, new HttpParameter("list_id", listId), + new HttpParameter("user_id", userId), INCLUDE_ENTITIES)); + } + + @Override + public String toString() { + return "TwitterImpl{" + "INCLUDE_ENTITIES=" + INCLUDE_ENTITIES + ", INCLUDE_RTS=" + INCLUDE_RTS + '}'; + } + + @Override + public AccountSettings updateAccountSettings(final Integer trend_locationWoeid, final Boolean sleep_timeEnabled, + final String start_sleepTime, final String end_sleepTime, final String time_zone, final String lang) + throws TwitterException { + + ensureAuthorizationEnabled(); + + final List params = new ArrayList(6); + addParameterToList(params, "trend_location_woeid", trend_locationWoeid); + addParameterToList(params, "sleep_time_enabled", sleep_timeEnabled); + addParameterToList(params, "start_sleep_time", start_sleepTime); + addParameterToList(params, "end_sleep_time", end_sleepTime); + addParameterToList(params, "time_zone", time_zone); + addParameterToList(params, "lang", lang); + params.add(INCLUDE_ENTITIES); + return factory.createAccountSettings(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_SETTINGS, + params.toArray(new HttpParameter[params.size()]))); + } + + @Override + public Relationship updateFriendship(final long userId, final boolean enableDeviceNotification, + final boolean retweets) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createRelationship(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, new HttpParameter("user_id", userId), + new HttpParameter("device", enableDeviceNotification), new HttpParameter("retweets", + enableDeviceNotification))); + } + + @Override + public Relationship updateFriendship(final String screenName, final boolean enableDeviceNotification, + final boolean retweets) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createRelationship(post(conf.getRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, + conf.getSigningRestBaseURL() + ENDPOINT_FRIENDSHIPS_UPDATE, + new HttpParameter("screen_name", screenName), new HttpParameter("device", enableDeviceNotification), + new HttpParameter("retweets", enableDeviceNotification))); + } + + @Override + public User updateProfile(final String name, final String url, final String location, final String description) + throws TwitterException { + ensureAuthorizationEnabled(); + final ArrayList params = new ArrayList(); + addParameterToList(params, "name", name); + addParameterToList(params, "url", url); + addParameterToList(params, "location", location); + addParameterToList(params, "description", description); + params.add(INCLUDE_ENTITIES); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE, + params.toArray(new HttpParameter[params.size()]))); + } + + @Override + public User updateProfileBackgroundImage(final File image, final boolean tile) throws TwitterException { + ensureAuthorizationEnabled(); + checkFileValidity(image); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, new HttpParameter( + "image", image), new HttpParameter("tile", tile), INCLUDE_ENTITIES)); + } + + @Override + public User updateProfileBackgroundImage(final InputStream image, final boolean tile) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE, new HttpParameter( + "image", "image", image), new HttpParameter("tile", tile), INCLUDE_ENTITIES)); + } + + @Override + public void updateProfileBannerImage(final File banner) throws TwitterException { + ensureAuthorizationEnabled(); + checkFileValidity(banner); + post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() + + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, new HttpParameter("banner", banner)); + } + + @Override + public void updateProfileBannerImage(final File banner, final int width, final int height, final int offsetLeft, + final int offsetTop) throws TwitterException { + ensureAuthorizationEnabled(); + checkFileValidity(banner); + final List params = new ArrayList(5); + addParameterToList(params, "width", width); + addParameterToList(params, "height", height); + addParameterToList(params, "offset_left", offsetLeft); + addParameterToList(params, "offset_top", offsetTop); + params.add(new HttpParameter("banner", banner)); + post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() + + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, params.toArray(new HttpParameter[params.size()])); + + } + + @Override + public void updateProfileBannerImage(final InputStream banner) throws TwitterException { + ensureAuthorizationEnabled(); + post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() + + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, new HttpParameter("banner", "banner", banner)); + } + + @Override + public void updateProfileBannerImage(final InputStream banner, final int width, final int height, + final int offsetLeft, final int offsetTop) throws TwitterException { + ensureAuthorizationEnabled(); + final List params = new ArrayList(5); + addParameterToList(params, "width", width); + addParameterToList(params, "height", height); + addParameterToList(params, "offset_left", offsetLeft); + addParameterToList(params, "offset_top", offsetTop); + params.add(new HttpParameter("banner", "banner", banner)); + post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, conf.getSigningRestBaseURL() + + ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER, params.toArray(new HttpParameter[params.size()])); + } + + @Override + public User updateProfileColors(final String profileBackgroundColor, final String profileTextColor, + final String profileLinkColor, final String profileSidebarFillColor, final String profileSidebarBorderColor) + throws TwitterException { + ensureAuthorizationEnabled(); + final List params = new ArrayList(6); + addParameterToList(params, "profile_background_color", profileBackgroundColor); + addParameterToList(params, "profile_text_color", profileTextColor); + addParameterToList(params, "profile_link_color", profileLinkColor); + addParameterToList(params, "profile_sidebar_fill_color", profileSidebarFillColor); + addParameterToList(params, "profile_sidebar_border_color", profileSidebarBorderColor); + params.add(INCLUDE_ENTITIES); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_COLORS, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_COLORS, + params.toArray(new HttpParameter[params.size()]))); + } + + @Override + public User updateProfileImage(final File image) throws TwitterException { + checkFileValidity(image); + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, + new HttpParameter("image", image), INCLUDE_ENTITIES)); + } + + @Override + public User updateProfileImage(final InputStream image) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createUser(post(conf.getRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, + conf.getSigningRestBaseURL() + ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE, new HttpParameter("image", + "image", image), INCLUDE_ENTITIES)); + } + + @Override + public Status updateStatus(final StatusUpdate status) throws TwitterException { + ensureAuthorizationEnabled(); + final String url = conf.getRestBaseURL() + + (status.isWithMedia() ? ENDPOINT_STATUSES_UPDATE_WITH_MEDIA : ENDPOINT_STATUSES_UPDATE); + final String signUrl = conf.getSigningRestBaseURL() + + (status.isWithMedia() ? ENDPOINT_STATUSES_UPDATE_WITH_MEDIA : ENDPOINT_STATUSES_UPDATE); + return factory.createStatus(post(url, signUrl, status.asHttpParameterArray(INCLUDE_ENTITIES))); + } + + @Override + public Status updateStatus(final String status) throws TwitterException { + ensureAuthorizationEnabled(); + return factory.createStatus(post(conf.getRestBaseURL() + ENDPOINT_STATUSES_UPDATE, conf.getSigningRestBaseURL() + + ENDPOINT_STATUSES_UPDATE, new HttpParameter("status", status), INCLUDE_ENTITIES)); + } + + @Override + public UserList updateUserList(final long listId, final String newListName, final boolean isPublicList, + final String newDescription) throws TwitterException { + ensureAuthorizationEnabled(); + final List httpParams = new ArrayList(); + httpParams.add(new HttpParameter("list_id", listId)); + if (newListName != null) { + httpParams.add(new HttpParameter("name", newListName)); + } + httpParams.add(new HttpParameter("mode", isPublicList ? "public" : "private")); + if (newDescription != null) { + httpParams.add(new HttpParameter("description", newDescription)); + } + return factory.createAUserList(post(conf.getRestBaseURL() + ENDPOINT_LISTS_UPDATE, conf.getSigningRestBaseURL() + + ENDPOINT_LISTS_UPDATE, httpParams.toArray(new HttpParameter[httpParams.size()]))); + } + + @Override + public MediaUploadResponse uploadMedia(final File file) throws TwitterException { + final String url = conf.getUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; + final String signUrl = conf.getSigningUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; + return factory.createMediaUploadResponse(post(url, signUrl, new HttpParameter("media", file))); + } + + @Override + public MediaUploadResponse uploadMedia(final String fileName, final InputStream fileBody, final String fileType) + throws TwitterException { + final String url = conf.getUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; + final String signUrl = conf.getSigningUploadBaseURL() + ENDPOINT_MEDIA_UPLOAD; + return factory.createMediaUploadResponse(post(url, signUrl, new HttpParameter("media", fileName, fileBody, + fileType))); + } + + @Override + public User verifyCredentials() throws TwitterException { + return super.fillInIDAndScreenName(); + } } diff --git a/twidere/src/main/java/twitter4j/conf/Configuration.java b/twidere/src/main/java/twitter4j/conf/Configuration.java index bdc20206b..249e0befb 100644 --- a/twidere/src/main/java/twitter4j/conf/Configuration.java +++ b/twidere/src/main/java/twitter4j/conf/Configuration.java @@ -24,48 +24,52 @@ import twitter4j.http.HttpClientWrapperConfiguration; * @author Yusuke Yamamoto - yusuke at mac.com */ public interface Configuration extends HttpClientConfiguration, HttpClientWrapperConfiguration, - AuthorizationConfiguration { + AuthorizationConfiguration { - String getClientName(); + String getClientName(); - String getClientURL(); + String getClientURL(); - String getClientVersion(); + String getClientVersion(); - String getOAuthAccessTokenURL(); + String getOAuthAccessTokenURL(); - String getOAuthAuthenticationURL(); + String getOAuthAuthenticationURL(); - String getOAuthAuthorizationURL(); + String getOAuthAuthorizationURL(); - String getOAuthBaseURL(); + String getOAuthBaseURL(); - String getOAuthRequestTokenURL(); + String getOAuthRequestTokenURL(); - String getRestBaseURL(); + String getRestBaseURL(); - String getSigningOAuthAccessTokenURL(); + String getSigningOAuthAccessTokenURL(); - String getSigningOAuthAuthenticationURL(); + String getSigningOAuthAuthenticationURL(); - String getSigningOAuthAuthorizationURL(); + String getSigningOAuthAuthorizationURL(); - String getSigningOAuthBaseURL(); + String getSigningOAuthBaseURL(); - String getSigningOAuthRequestTokenURL(); + String getSigningOAuthRequestTokenURL(); - String getSigningRestBaseURL(); + String getSigningRestBaseURL(); - String getSigningUploadBaseURL(); + String getSigningUploadBaseURL(); - String getUploadBaseURL(); + String getUploadBaseURL(); - boolean isDebugEnabled(); + boolean isDebugEnabled(); - boolean isIncludeEntitiesEnabled(); + boolean isIncludeEntitiesEnabled(); - boolean isIncludeRTsEnabled(); + boolean isIncludeRTsEnabled(); - boolean isTwitterClientHeaderIncluded(); + boolean isIncludeReplyCountEnabled(); + + boolean isIncludeDescendentReplyCountEnabled(); + + boolean isTwitterClientHeaderIncluded(); } diff --git a/twidere/src/main/java/twitter4j/conf/ConfigurationBase.java b/twidere/src/main/java/twitter4j/conf/ConfigurationBase.java index cf9965b6f..b3076c93b 100644 --- a/twidere/src/main/java/twitter4j/conf/ConfigurationBase.java +++ b/twidere/src/main/java/twitter4j/conf/ConfigurationBase.java @@ -16,872 +16,899 @@ package twitter4j.conf; -import twitter4j.TwitterConstants; -import twitter4j.Version; -import twitter4j.http.HostAddressResolverFactory; -import twitter4j.http.HttpClientFactory; - import java.io.ObjectStreamException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import twitter4j.TwitterConstants; +import twitter4j.Version; +import twitter4j.http.HostAddressResolverFactory; +import twitter4j.http.HttpClientFactory; + /** * Configuration base class with default settings. - * + * * @author Yusuke Yamamoto - yusuke at mac.com */ class ConfigurationBase implements TwitterConstants, Configuration { - static final boolean DEFAULT_USE_SSL = true; - - private boolean debug; - private String userAgent; - private String user; - private String password; - private boolean useSSL; - private boolean ignoreSSLError; - private boolean prettyDebug; - private boolean gzipEnabled; - private String httpProxyHost; - private String httpProxyUser; - private String httpProxyPassword; - private int httpProxyPort; - private int httpConnectionTimeout; - private int httpReadTimeout; - - private int httpRetryCount; - private int httpRetryIntervalSeconds; - private int maxTotalConnections; - private int defaultMaxPerRoute; - private String oAuthConsumerKey; - private String oAuthConsumerSecret; - private String oAuthAccessToken; - private String oAuthAccessTokenSecret; - - private String oAuthRequestTokenURL; - private String oAuthAuthorizationURL; - private String oAuthAccessTokenURL; - private String oAuthAuthenticationURL; - - private String signingOAuthRequestTokenURL; - private String signingOAuthAuthorizationURL; - private String signingOAuthAccessTokenURL; - private String signingOAuthAuthenticationURL; - - private String oAuthBaseURL = DEFAULT_OAUTH_BASE_URL; - - private String signingOAuthBaseURL; - private String signingRestBaseURL; - private String signingUploadBaseURL; - - private String restBaseURL; - private String uploadBaseURL; - - private boolean includeRTsEnabled; - - private boolean includeEntitiesEnabled; - - private boolean includeTwitterClientHeader; - - // hidden portion - private String clientVersion; - private String clientURL; - private String clientName; - - private HttpClientFactory httpClientFactory; - private HostAddressResolverFactory hostAddressResolverFactory; - - // method for HttpRequestFactoryConfiguration - Map requestHeaders; - - private static final List instances = new ArrayList(); - - protected ConfigurationBase() { - setDebug(false); - setUser(null); - setPassword(null); - setUseSSL(false); - setPrettyDebugEnabled(false); - setGZIPEnabled(true); - setHttpProxyHost(null); - setHttpProxyUser(null); - setHttpProxyPassword(null); - setHttpProxyPort(-1); - setHttpConnectionTimeout(20000); - setHttpReadTimeout(120000); - setHttpRetryCount(0); - setHttpRetryIntervalSeconds(5); - setHttpMaxTotalConnections(20); - setHttpDefaultMaxPerRoute(2); - setHttpClientFactory(null); - setOAuthConsumerKey(null); - setOAuthConsumerSecret(null); - setOAuthAccessToken(null); - setOAuthAccessTokenSecret(null); - setClientName("Twitter4J"); - setClientVersion(Version.getVersion()); - setClientURL("http://twitter4j.org/en/twitter4j-" + Version.getVersion() + ".xml"); - setHttpUserAgent("twitter4j http://twitter4j.org/ /" + Version.getVersion()); - - setIncludeRTsEnbled(true); - - setIncludeEntitiesEnbled(true); - - setOAuthBaseURL(DEFAULT_OAUTH_BASE_URL); - setSigningOAuthBaseURL(DEFAULT_SIGNING_OAUTH_BASE_URL); - - setRestBaseURL(DEFAULT_REST_BASE_URL); - setSigningRestBaseURL(DEFAULT_SIGNING_REST_BASE_URL); - - setUploadBaseURL(DEFAULT_UPLOAD_BASE_URL); - setSigningUploadBaseURL(DEFAULT_SIGNING_UPLOAD_BASE_URL); - setIncludeRTsEnbled(true); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof ConfigurationBase)) return false; - final ConfigurationBase other = (ConfigurationBase) obj; - if (clientName == null) { - if (other.clientName != null) return false; - } else if (!clientName.equals(other.clientName)) return false; - if (clientURL == null) { - if (other.clientURL != null) return false; - } else if (!clientURL.equals(other.clientURL)) return false; - if (clientVersion == null) { - if (other.clientVersion != null) return false; - } else if (!clientVersion.equals(other.clientVersion)) return false; - if (debug != other.debug) return false; - if (defaultMaxPerRoute != other.defaultMaxPerRoute) return false; - if (gzipEnabled != other.gzipEnabled) return false; - if (hostAddressResolverFactory == null) { - if (other.hostAddressResolverFactory != null) return false; - } else if (!hostAddressResolverFactory.equals(other.hostAddressResolverFactory)) return false; - if (httpClientFactory == null) { - if (other.httpClientFactory != null) return false; - } else if (!httpClientFactory.equals(other.httpClientFactory)) return false; - if (httpConnectionTimeout != other.httpConnectionTimeout) return false; - if (httpProxyHost == null) { - if (other.httpProxyHost != null) return false; - } else if (!httpProxyHost.equals(other.httpProxyHost)) return false; - if (httpProxyPassword == null) { - if (other.httpProxyPassword != null) return false; - } else if (!httpProxyPassword.equals(other.httpProxyPassword)) return false; - if (httpProxyPort != other.httpProxyPort) return false; - if (httpProxyUser == null) { - if (other.httpProxyUser != null) return false; - } else if (!httpProxyUser.equals(other.httpProxyUser)) return false; - if (httpReadTimeout != other.httpReadTimeout) return false; - if (httpRetryCount != other.httpRetryCount) return false; - if (httpRetryIntervalSeconds != other.httpRetryIntervalSeconds) return false; - if (ignoreSSLError != other.ignoreSSLError) return false; - if (includeEntitiesEnabled != other.includeEntitiesEnabled) return false; - if (includeRTsEnabled != other.includeRTsEnabled) return false; - if (includeTwitterClientHeader != other.includeTwitterClientHeader) return false; - if (maxTotalConnections != other.maxTotalConnections) return false; - if (oAuthAccessToken == null) { - if (other.oAuthAccessToken != null) return false; - } else if (!oAuthAccessToken.equals(other.oAuthAccessToken)) return false; - if (oAuthAccessTokenSecret == null) { - if (other.oAuthAccessTokenSecret != null) return false; - } else if (!oAuthAccessTokenSecret.equals(other.oAuthAccessTokenSecret)) return false; - if (oAuthAccessTokenURL == null) { - if (other.oAuthAccessTokenURL != null) return false; - } else if (!oAuthAccessTokenURL.equals(other.oAuthAccessTokenURL)) return false; - if (oAuthAuthenticationURL == null) { - if (other.oAuthAuthenticationURL != null) return false; - } else if (!oAuthAuthenticationURL.equals(other.oAuthAuthenticationURL)) return false; - if (oAuthAuthorizationURL == null) { - if (other.oAuthAuthorizationURL != null) return false; - } else if (!oAuthAuthorizationURL.equals(other.oAuthAuthorizationURL)) return false; - if (oAuthBaseURL == null) { - if (other.oAuthBaseURL != null) return false; - } else if (!oAuthBaseURL.equals(other.oAuthBaseURL)) return false; - if (oAuthConsumerKey == null) { - if (other.oAuthConsumerKey != null) return false; - } else if (!oAuthConsumerKey.equals(other.oAuthConsumerKey)) return false; - if (oAuthConsumerSecret == null) { - if (other.oAuthConsumerSecret != null) return false; - } else if (!oAuthConsumerSecret.equals(other.oAuthConsumerSecret)) return false; - if (oAuthRequestTokenURL == null) { - if (other.oAuthRequestTokenURL != null) return false; - } else if (!oAuthRequestTokenURL.equals(other.oAuthRequestTokenURL)) return false; - if (password == null) { - if (other.password != null) return false; - } else if (!password.equals(other.password)) return false; - if (prettyDebug != other.prettyDebug) return false; - if (requestHeaders == null) { - if (other.requestHeaders != null) return false; - } else if (!requestHeaders.equals(other.requestHeaders)) return false; - if (restBaseURL == null) { - if (other.restBaseURL != null) return false; - } else if (!restBaseURL.equals(other.restBaseURL)) return false; - if (signingOAuthAccessTokenURL == null) { - if (other.signingOAuthAccessTokenURL != null) return false; - } else if (!signingOAuthAccessTokenURL.equals(other.signingOAuthAccessTokenURL)) return false; - if (signingOAuthAuthenticationURL == null) { - if (other.signingOAuthAuthenticationURL != null) return false; - } else if (!signingOAuthAuthenticationURL.equals(other.signingOAuthAuthenticationURL)) return false; - if (signingOAuthAuthorizationURL == null) { - if (other.signingOAuthAuthorizationURL != null) return false; - } else if (!signingOAuthAuthorizationURL.equals(other.signingOAuthAuthorizationURL)) return false; - if (signingOAuthBaseURL == null) { - if (other.signingOAuthBaseURL != null) return false; - } else if (!signingOAuthBaseURL.equals(other.signingOAuthBaseURL)) return false; - if (signingOAuthRequestTokenURL == null) { - if (other.signingOAuthRequestTokenURL != null) return false; - } else if (!signingOAuthRequestTokenURL.equals(other.signingOAuthRequestTokenURL)) return false; - if (signingRestBaseURL == null) { - if (other.signingRestBaseURL != null) return false; - } else if (!signingRestBaseURL.equals(other.signingRestBaseURL)) return false; - if (useSSL != other.useSSL) return false; - if (user == null) { - if (other.user != null) return false; - } else if (!user.equals(other.user)) return false; - if (userAgent == null) { - if (other.userAgent != null) return false; - } else if (!userAgent.equals(other.userAgent)) return false; - return true; - } - - @Override - public final String getClientName() { - return clientName; - } - - @Override - public final String getClientURL() { - return clientURL; - } - - @Override - public final String getClientVersion() { - return clientVersion; - } - - @Override - public HostAddressResolverFactory getHostAddressResolverFactory() { - return hostAddressResolverFactory; - } - - @Override - public HttpClientFactory getHttpClientFactory() { - return httpClientFactory; - } - - @Override - public final int getHttpConnectionTimeout() { - return httpConnectionTimeout; - } - - @Override - public final int getHttpDefaultMaxPerRoute() { - return defaultMaxPerRoute; - } - - @Override - public final int getHttpMaxTotalConnections() { - return maxTotalConnections; - } - - @Override - public final String getHttpProxyHost() { - return httpProxyHost; - } - - @Override - public final String getHttpProxyPassword() { - return httpProxyPassword; - } - - @Override - public final int getHttpProxyPort() { - return httpProxyPort; - } - - @Override - public final String getHttpProxyUser() { - return httpProxyUser; - } - - @Override - public final int getHttpReadTimeout() { - return httpReadTimeout; - } - - @Override - public final int getHttpRetryCount() { - return httpRetryCount; - } - - @Override - public final int getHttpRetryIntervalSeconds() { - return httpRetryIntervalSeconds; - } - - @Override - public final String getHttpUserAgent() { - return userAgent; - } - - @Override - public String getOAuthAccessToken() { - return oAuthAccessToken; - } - - @Override - public String getOAuthAccessTokenSecret() { - return oAuthAccessTokenSecret; - } - - @Override - public String getOAuthAccessTokenURL() { - return oAuthAccessTokenURL; - } - - @Override - public String getOAuthAuthenticationURL() { - return oAuthAuthenticationURL; - } - - @Override - public String getOAuthAuthorizationURL() { - return oAuthAuthorizationURL; - } - - @Override - public String getOAuthBaseURL() { - return oAuthBaseURL; - } - - @Override - public final String getOAuthConsumerKey() { - return oAuthConsumerKey; - } - - @Override - public final String getOAuthConsumerSecret() { - return oAuthConsumerSecret; - } - - @Override - public String getOAuthRequestTokenURL() { - return oAuthRequestTokenURL; - } - - @Override - public final String getPassword() { - return password; - } - - @Override - public Map getRequestHeaders() { - return requestHeaders; - } - - @Override - public String getRestBaseURL() { - return restBaseURL; - } - - @Override - public String getSigningOAuthAccessTokenURL() { - return signingOAuthAccessTokenURL != null ? signingOAuthAccessTokenURL : oAuthAccessTokenURL; - } - - @Override - public String getSigningOAuthAuthenticationURL() { - return signingOAuthAuthenticationURL != null ? signingOAuthAuthenticationURL : oAuthAuthenticationURL; - } - - @Override - public String getSigningOAuthAuthorizationURL() { - return signingOAuthAuthorizationURL != null ? signingOAuthAuthorizationURL : oAuthAuthorizationURL; - } - - @Override - public String getSigningOAuthBaseURL() { - return signingOAuthBaseURL != null ? signingOAuthBaseURL : oAuthBaseURL; - } - - @Override - public String getSigningOAuthRequestTokenURL() { - return signingOAuthRequestTokenURL != null ? signingOAuthRequestTokenURL : oAuthRequestTokenURL; - } - - @Override - public String getSigningRestBaseURL() { - return signingRestBaseURL != null ? signingRestBaseURL : restBaseURL; - } - - @Override - public String getSigningUploadBaseURL() { - return signingUploadBaseURL != null ? signingUploadBaseURL : uploadBaseURL; - } - - @Override - public String getUploadBaseURL() { - return uploadBaseURL; - } - - @Override - public final String getUser() { - return user; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (clientName == null ? 0 : clientName.hashCode()); - result = prime * result + (clientURL == null ? 0 : clientURL.hashCode()); - result = prime * result + (clientVersion == null ? 0 : clientVersion.hashCode()); - result = prime * result + (debug ? 1231 : 1237); - result = prime * result + defaultMaxPerRoute; - result = prime * result + (gzipEnabled ? 1231 : 1237); - result = prime * result + (hostAddressResolverFactory == null ? 0 : hostAddressResolverFactory.hashCode()); - result = prime * result + (httpClientFactory == null ? 0 : httpClientFactory.hashCode()); - result = prime * result + httpConnectionTimeout; - result = prime * result + (httpProxyHost == null ? 0 : httpProxyHost.hashCode()); - result = prime * result + (httpProxyPassword == null ? 0 : httpProxyPassword.hashCode()); - result = prime * result + httpProxyPort; - result = prime * result + (httpProxyUser == null ? 0 : httpProxyUser.hashCode()); - result = prime * result + httpReadTimeout; - result = prime * result + httpRetryCount; - result = prime * result + httpRetryIntervalSeconds; - result = prime * result + (ignoreSSLError ? 1231 : 1237); - result = prime * result + (includeEntitiesEnabled ? 1231 : 1237); - result = prime * result + (includeRTsEnabled ? 1231 : 1237); - result = prime * result + (includeTwitterClientHeader ? 1231 : 1237); - result = prime * result + maxTotalConnections; - result = prime * result + (oAuthAccessToken == null ? 0 : oAuthAccessToken.hashCode()); - result = prime * result + (oAuthAccessTokenSecret == null ? 0 : oAuthAccessTokenSecret.hashCode()); - result = prime * result + (oAuthAccessTokenURL == null ? 0 : oAuthAccessTokenURL.hashCode()); - result = prime * result + (oAuthAuthenticationURL == null ? 0 : oAuthAuthenticationURL.hashCode()); - result = prime * result + (oAuthAuthorizationURL == null ? 0 : oAuthAuthorizationURL.hashCode()); - result = prime * result + (oAuthBaseURL == null ? 0 : oAuthBaseURL.hashCode()); - result = prime * result + (oAuthConsumerKey == null ? 0 : oAuthConsumerKey.hashCode()); - result = prime * result + (oAuthConsumerSecret == null ? 0 : oAuthConsumerSecret.hashCode()); - result = prime * result + (oAuthRequestTokenURL == null ? 0 : oAuthRequestTokenURL.hashCode()); - result = prime * result + (password == null ? 0 : password.hashCode()); - result = prime * result + (prettyDebug ? 1231 : 1237); - result = prime * result + (requestHeaders == null ? 0 : requestHeaders.hashCode()); - result = prime * result + (restBaseURL == null ? 0 : restBaseURL.hashCode()); - result = prime * result + (signingOAuthAccessTokenURL == null ? 0 : signingOAuthAccessTokenURL.hashCode()); - result = prime * result - + (signingOAuthAuthenticationURL == null ? 0 : signingOAuthAuthenticationURL.hashCode()); - result = prime * result + (signingOAuthAuthorizationURL == null ? 0 : signingOAuthAuthorizationURL.hashCode()); - result = prime * result + (signingOAuthBaseURL == null ? 0 : signingOAuthBaseURL.hashCode()); - result = prime * result + (signingOAuthRequestTokenURL == null ? 0 : signingOAuthRequestTokenURL.hashCode()); - result = prime * result + (signingRestBaseURL == null ? 0 : signingRestBaseURL.hashCode()); - result = prime * result + (useSSL ? 1231 : 1237); - result = prime * result + (user == null ? 0 : user.hashCode()); - result = prime * result + (userAgent == null ? 0 : userAgent.hashCode()); - return result; - } - - @Override - public final boolean isDebugEnabled() { - return debug; - } - - @Override - public boolean isGZIPEnabled() { - return gzipEnabled; - } - - @Override - public boolean isIncludeEntitiesEnabled() { - return includeEntitiesEnabled; - } - - @Override - public boolean isIncludeRTsEnabled() { - return includeRTsEnabled; - } - - @Override - public boolean isPrettyDebugEnabled() { - return prettyDebug; - } - - @Override - public boolean isProxyConfigured() { - return (getHttpProxyHost() != null || "".equals(getHttpProxyHost())) && getHttpProxyPort() > 0; - } - - @Override - public boolean isSSLEnabled() { - return getRestBaseURL() != null && getRestBaseURL().startsWith("https://"); - } - - @Override - public final boolean isSSLErrorIgnored() { - return ignoreSSLError; - } - - @Override - public boolean isTwitterClientHeaderIncluded() { - return includeTwitterClientHeader; - } - - @Override - public String toString() { - return "ConfigurationBase{debug=" + debug + ", userAgent=" + userAgent + ", user=" + user + ", password=" - + password + ", useSSL=" + useSSL + ", ignoreSSLError=" + ignoreSSLError + ", prettyDebug=" - + prettyDebug + ", gzipEnabled=" + gzipEnabled + ", httpProxyHost=" + httpProxyHost - + ", httpProxyUser=" + httpProxyUser + ", httpProxyPassword=" + httpProxyPassword + ", httpProxyPort=" - + httpProxyPort + ", httpConnectionTimeout=" + httpConnectionTimeout + ", httpReadTimeout=" - + httpReadTimeout + ", httpRetryCount=" + httpRetryCount + ", httpRetryIntervalSeconds=" - + httpRetryIntervalSeconds + ", maxTotalConnections=" + maxTotalConnections + ", defaultMaxPerRoute=" - + defaultMaxPerRoute + ", oAuthConsumerKey=" + oAuthConsumerKey + ", oAuthConsumerSecret=" - + oAuthConsumerSecret + ", oAuthAccessToken=" + oAuthAccessToken + ", oAuthAccessTokenSecret=" - + oAuthAccessTokenSecret + ", oAuthRequestTokenURL=" + oAuthRequestTokenURL - + ", oAuthAuthorizationURL=" + oAuthAuthorizationURL + ", oAuthAccessTokenURL=" + oAuthAccessTokenURL - + ", oAuthAuthenticationURL=" + oAuthAuthenticationURL + ", signingOAuthRequestTokenURL=" - + signingOAuthRequestTokenURL + ", signingOAuthAuthorizationURL=" + signingOAuthAuthorizationURL - + ", signingOAuthAccessTokenURL=" + signingOAuthAccessTokenURL + ", signingOAuthAuthenticationURL=" - + signingOAuthAuthenticationURL + ", oAuthBaseURL=" + oAuthBaseURL + ", signingOAuthBaseURL=" - + signingOAuthBaseURL + ", signingRestBaseURL=" + signingRestBaseURL + ", restBaseURL=" + restBaseURL - + ", includeRTsEnabled=" + includeRTsEnabled + ", includeEntitiesEnabled=" + includeEntitiesEnabled - + ", includeTwitterClientHeader=" + includeTwitterClientHeader + ", clientVersion=" + clientVersion - + ", clientURL=" + clientURL + ", clientName=" + clientName + ", httpClientFactory=" - + httpClientFactory + ", hostAddressResolverFactory=" + hostAddressResolverFactory - + ", requestHeaders=" + requestHeaders + "}"; - } - - protected void cacheInstance() { - cacheInstance(this); - } - - // assures equality after deserializedation - protected Object readResolve() throws ObjectStreamException { - return getInstance(this); - } - - protected final void setClientName(final String clientName) { - this.clientName = clientName; - initRequestHeaders(); - } - - protected final void setClientURL(final String clientURL) { - this.clientURL = clientURL; - initRequestHeaders(); - } - - protected final void setClientVersion(final String clientVersion) { - this.clientVersion = clientVersion; - initRequestHeaders(); - } - - protected final void setDebug(final boolean debug) { - this.debug = debug; - } - - protected final void setGZIPEnabled(final boolean gzipEnabled) { - this.gzipEnabled = gzipEnabled; - initRequestHeaders(); - } - - protected void setHostAddressResolverFactory(final HostAddressResolverFactory factory) { - hostAddressResolverFactory = factory; - } - - protected void setHttpClientFactory(final HttpClientFactory factory) { - httpClientFactory = factory; - } - - protected final void setHttpConnectionTimeout(final int connectionTimeout) { - httpConnectionTimeout = connectionTimeout; - } - - protected final void setHttpDefaultMaxPerRoute(final int defaultMaxPerRoute) { - this.defaultMaxPerRoute = defaultMaxPerRoute; - } - - protected final void setHttpMaxTotalConnections(final int maxTotalConnections) { - this.maxTotalConnections = maxTotalConnections; - } - - protected final void setHttpProxyHost(final String proxyHost) { - httpProxyHost = proxyHost; - initRequestHeaders(); - } - - protected final void setHttpProxyPassword(final String proxyPassword) { - httpProxyPassword = proxyPassword; - } - - protected final void setHttpProxyPort(final int proxyPort) { - httpProxyPort = proxyPort; - initRequestHeaders(); - } - - protected final void setHttpProxyUser(final String proxyUser) { - httpProxyUser = proxyUser; - } - - protected final void setHttpReadTimeout(final int readTimeout) { - httpReadTimeout = readTimeout; - } - - protected final void setHttpRetryCount(final int retryCount) { - httpRetryCount = retryCount; - } - - protected final void setHttpRetryIntervalSeconds(final int retryIntervalSeconds) { - httpRetryIntervalSeconds = retryIntervalSeconds; - } - - protected final void setHttpUserAgent(final String userAgent) { - this.userAgent = userAgent; - initRequestHeaders(); - } - - protected final void setIgnoreSSLError(final boolean ignore) { - ignoreSSLError = ignore; - initRequestHeaders(); - } - - protected final void setIncludeEntitiesEnbled(final boolean enabled) { - includeEntitiesEnabled = enabled; - } - - protected final void setIncludeRTsEnbled(final boolean enabled) { - includeRTsEnabled = enabled; - } - - protected final void setIncludeTwitterClientHeader(final boolean includeHeader) { - includeTwitterClientHeader = includeHeader; - initRequestHeaders(); - } - - protected final void setOAuthAccessToken(final String accessToken) { - oAuthAccessToken = accessToken; - } - - protected final void setOAuthAccessTokenSecret(final String accessTokenSecret) { - oAuthAccessTokenSecret = accessTokenSecret; - } - - protected final void setOAuthBaseURL(String oAuthBaseURL) { - if (isNullOrEmpty(oAuthBaseURL)) { - oAuthBaseURL = DEFAULT_OAUTH_BASE_URL; - } - this.oAuthBaseURL = fixURLSlash(oAuthBaseURL); - - oAuthAccessTokenURL = oAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN; - oAuthAuthenticationURL = oAuthBaseURL + PATH_SEGMENT_AUTHENTICATION; - oAuthAuthorizationURL = oAuthBaseURL + PATH_SEGMENT_AUTHORIZATION; - oAuthRequestTokenURL = oAuthBaseURL + PATH_SEGMENT_REQUEST_TOKEN; - - setSigningOAuthBaseURL(oAuthBaseURL); - fixOAuthBaseURL(); - } - - protected final void setOAuthConsumerKey(final String oAuthConsumerKey) { - this.oAuthConsumerKey = oAuthConsumerKey; - fixRestBaseURL(); - } - - protected final void setOAuthConsumerSecret(final String oAuthConsumerSecret) { - this.oAuthConsumerSecret = oAuthConsumerSecret; - fixRestBaseURL(); - } - - protected final void setPassword(final String password) { - this.password = password; - } - - protected final void setPrettyDebugEnabled(final boolean prettyDebug) { - this.prettyDebug = prettyDebug; - } - - protected final void setRestBaseURL(String restBaseURL) { - if (isNullOrEmpty(restBaseURL)) { - restBaseURL = DEFAULT_REST_BASE_URL; - } - this.restBaseURL = fixURLSlash(restBaseURL); - fixRestBaseURL(); - } - - protected final void setSigningOAuthBaseURL(String signingOAuthBaseURL) { - if (isNullOrEmpty(signingOAuthBaseURL)) { - signingOAuthBaseURL = DEFAULT_SIGNING_OAUTH_BASE_URL; - } - this.signingOAuthBaseURL = fixURLSlash(signingOAuthBaseURL); - - signingOAuthAccessTokenURL = signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN; - signingOAuthAuthenticationURL = signingOAuthBaseURL + PATH_SEGMENT_AUTHENTICATION; - signingOAuthAuthorizationURL = signingOAuthBaseURL + PATH_SEGMENT_AUTHORIZATION; - signingOAuthRequestTokenURL = signingOAuthBaseURL + PATH_SEGMENT_REQUEST_TOKEN; - - fixOAuthBaseURL(); - } - - protected final void setSigningRestBaseURL(String signingRestBaseURL) { - if (isNullOrEmpty(signingRestBaseURL)) { - signingRestBaseURL = DEFAULT_SIGNING_REST_BASE_URL; - } - this.signingRestBaseURL = fixURLSlash(signingRestBaseURL); - fixRestBaseURL(); - } - - protected void setSigningUploadBaseURL(String signingUploadBaseURL) { - if (isNullOrEmpty(signingUploadBaseURL)) { - signingUploadBaseURL = DEFAULT_SIGNING_UPLOAD_BASE_URL; - } - this.signingUploadBaseURL = fixURLSlash(signingUploadBaseURL); - fixUploadBaseURL(); - } - - protected void setUploadBaseURL(String uploadBaseURL) { - if (isNullOrEmpty(uploadBaseURL)) { - uploadBaseURL = DEFAULT_UPLOAD_BASE_URL; - } - this.uploadBaseURL = fixURLSlash(uploadBaseURL); - fixUploadBaseURL(); - } - - protected final void setUser(final String user) { - this.user = user; - } - - protected final void setUseSSL(final boolean useSSL) { - this.useSSL = useSSL; - fixRestBaseURL(); - } - - private void fixOAuthBaseURL() { - if (DEFAULT_OAUTH_BASE_URL.equals(fixURL(DEFAULT_USE_SSL, oAuthBaseURL))) { - oAuthBaseURL = fixURL(useSSL, oAuthBaseURL); - } - if (oAuthBaseURL != null && oAuthBaseURL.equals(fixURL(DEFAULT_USE_SSL, signingOAuthBaseURL))) { - signingOAuthBaseURL = fixURL(useSSL, signingOAuthBaseURL); - } - if (oAuthBaseURL != null - && (oAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, oAuthAccessTokenURL))) { - oAuthAccessTokenURL = fixURL(useSSL, oAuthAccessTokenURL); - } - if (oAuthBaseURL != null - && (oAuthBaseURL + PATH_SEGMENT_AUTHENTICATION).equals(fixURL(DEFAULT_USE_SSL, oAuthAuthenticationURL))) { - oAuthAuthenticationURL = fixURL(useSSL, oAuthAuthenticationURL); - } - if (oAuthBaseURL != null - && (oAuthBaseURL + PATH_SEGMENT_AUTHORIZATION).equals(fixURL(DEFAULT_USE_SSL, oAuthAuthorizationURL))) { - oAuthAuthorizationURL = fixURL(useSSL, oAuthAuthorizationURL); - } - if (oAuthBaseURL != null - && (oAuthBaseURL + PATH_SEGMENT_REQUEST_TOKEN).equals(fixURL(DEFAULT_USE_SSL, oAuthRequestTokenURL))) { - oAuthRequestTokenURL = fixURL(useSSL, oAuthRequestTokenURL); - } - if (signingOAuthBaseURL != null - && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, - signingOAuthAccessTokenURL))) { - signingOAuthAccessTokenURL = fixURL(useSSL, signingOAuthAccessTokenURL); - } - if (signingOAuthBaseURL != null - && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, - signingOAuthAuthenticationURL))) { - signingOAuthAuthenticationURL = fixURL(useSSL, signingOAuthAuthenticationURL); - } - if (signingOAuthBaseURL != null - && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, - signingOAuthAuthorizationURL))) { - signingOAuthAuthorizationURL = fixURL(useSSL, signingOAuthAuthorizationURL); - } - if (signingOAuthBaseURL != null - && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, - signingOAuthRequestTokenURL))) { - signingOAuthRequestTokenURL = fixURL(useSSL, signingOAuthRequestTokenURL); - } - initRequestHeaders(); - } - - private void fixRestBaseURL() { - if (DEFAULT_REST_BASE_URL.equals(fixURL(DEFAULT_USE_SSL, restBaseURL))) { - restBaseURL = fixURL(useSSL, restBaseURL); - } - if (restBaseURL != null && restBaseURL.equals(fixURL(DEFAULT_USE_SSL, signingRestBaseURL))) { - signingRestBaseURL = fixURL(useSSL, signingRestBaseURL); - } - initRequestHeaders(); - } - - private void fixUploadBaseURL() { - if (DEFAULT_UPLOAD_BASE_URL.equals(fixURL(DEFAULT_USE_SSL, uploadBaseURL))) { - uploadBaseURL = fixURL(useSSL, uploadBaseURL); - } - if (uploadBaseURL != null && uploadBaseURL.equals(fixURL(DEFAULT_USE_SSL, uploadBaseURL))) { - uploadBaseURL = fixURL(useSSL, uploadBaseURL); - } - initRequestHeaders(); - } - - final void initRequestHeaders() { - requestHeaders = new HashMap(); - if (includeTwitterClientHeader) { - requestHeaders.put("X-Twitter-Client-Version", getClientVersion()); - requestHeaders.put("X-Twitter-Client-URL", getClientURL()); - requestHeaders.put("X-Twitter-Client", getClientName()); - } - - requestHeaders.put("User-Agent", getHttpUserAgent()); - if (gzipEnabled) { - requestHeaders.put("Accept-Encoding", "gzip"); - } - // I found this may cause "Socket is closed" error in Android, so I - // changed it to "keep-alive". - if (!isNullOrEmpty(httpProxyHost) && httpProxyPort > 0) { - requestHeaders.put("Connection", "keep-alive"); - } else { - requestHeaders.put("Connection", "close"); - } - } - - private static void cacheInstance(final ConfigurationBase conf) { - if (!instances.contains(conf)) { - instances.add(conf); - } - } - - private static ConfigurationBase getInstance(final ConfigurationBase configurationBase) { - int index; - if ((index = instances.indexOf(configurationBase)) == -1) { - instances.add(configurationBase); - return configurationBase; - } else - return instances.get(index); - } - - static String fixURL(final boolean useSSL, String url) { - if (null == url) return null; - if (!url.startsWith("http://") || !url.startsWith("https://")) { - url = "https://" + url; - } - final int index = url.indexOf("://"); - if (-1 == index) throw new IllegalArgumentException("url should contain '://'"); - final String hostAndLater = url.substring(index + 3); - if (useSSL) - return "https://" + hostAndLater; - else - return "http://" + hostAndLater; - } - - static String fixURLSlash(final String urlOrig) { - if (urlOrig == null) return null; - if (!urlOrig.endsWith("/")) return urlOrig + "/"; - return urlOrig; - } - - static boolean isNullOrEmpty(final String string) { - if (string == null) return true; - if (string.length() == 0) return true; - return false; - } + static final boolean DEFAULT_USE_SSL = true; + + private boolean debug; + private String userAgent; + private String user; + private String password; + private boolean useSSL; + private boolean ignoreSSLError; + private boolean prettyDebug; + private boolean gzipEnabled; + private String httpProxyHost; + private String httpProxyUser; + private String httpProxyPassword; + private int httpProxyPort; + private int httpConnectionTimeout; + private int httpReadTimeout; + + private int httpRetryCount; + private int httpRetryIntervalSeconds; + private int maxTotalConnections; + private int defaultMaxPerRoute; + private String oAuthConsumerKey; + private String oAuthConsumerSecret; + private String oAuthAccessToken; + private String oAuthAccessTokenSecret; + + private String oAuthRequestTokenURL; + private String oAuthAuthorizationURL; + private String oAuthAccessTokenURL; + private String oAuthAuthenticationURL; + + private String signingOAuthRequestTokenURL; + private String signingOAuthAuthorizationURL; + private String signingOAuthAccessTokenURL; + private String signingOAuthAuthenticationURL; + + private String oAuthBaseURL = DEFAULT_OAUTH_BASE_URL; + + private String signingOAuthBaseURL; + private String signingRestBaseURL; + private String signingUploadBaseURL; + + private String restBaseURL; + private String uploadBaseURL; + + private boolean includeRTsEnabled; + + private boolean includeReplyCountEnabled; + + private boolean includeDescendentReplyCountEnabled; + + private boolean includeEntitiesEnabled; + + private boolean includeTwitterClientHeader; + + // hidden portion + private String clientVersion; + private String clientURL; + private String clientName; + + private HttpClientFactory httpClientFactory; + private HostAddressResolverFactory hostAddressResolverFactory; + + // method for HttpRequestFactoryConfiguration + Map requestHeaders; + + private static final List instances = new ArrayList(); + + protected ConfigurationBase() { + setDebug(false); + setUser(null); + setPassword(null); + setUseSSL(false); + setPrettyDebugEnabled(false); + setGZIPEnabled(true); + setHttpProxyHost(null); + setHttpProxyUser(null); + setHttpProxyPassword(null); + setHttpProxyPort(-1); + setHttpConnectionTimeout(20000); + setHttpReadTimeout(120000); + setHttpRetryCount(0); + setHttpRetryIntervalSeconds(5); + setHttpMaxTotalConnections(20); + setHttpDefaultMaxPerRoute(2); + setHttpClientFactory(null); + setOAuthConsumerKey(null); + setOAuthConsumerSecret(null); + setOAuthAccessToken(null); + setOAuthAccessTokenSecret(null); + setClientName("Twitter4J"); + setClientVersion(Version.getVersion()); + setClientURL("http://twitter4j.org/en/twitter4j-" + Version.getVersion() + ".xml"); + setHttpUserAgent("twitter4j http://twitter4j.org/ /" + Version.getVersion()); + + setIncludeRTsEnabled(true); + + setIncludeEntitiesEnabled(true); + + setOAuthBaseURL(DEFAULT_OAUTH_BASE_URL); + setSigningOAuthBaseURL(DEFAULT_SIGNING_OAUTH_BASE_URL); + + setRestBaseURL(DEFAULT_REST_BASE_URL); + setSigningRestBaseURL(DEFAULT_SIGNING_REST_BASE_URL); + + setUploadBaseURL(DEFAULT_UPLOAD_BASE_URL); + setSigningUploadBaseURL(DEFAULT_SIGNING_UPLOAD_BASE_URL); + setIncludeRTsEnabled(true); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof ConfigurationBase)) return false; + final ConfigurationBase other = (ConfigurationBase) obj; + if (clientName == null) { + if (other.clientName != null) return false; + } else if (!clientName.equals(other.clientName)) return false; + if (clientURL == null) { + if (other.clientURL != null) return false; + } else if (!clientURL.equals(other.clientURL)) return false; + if (clientVersion == null) { + if (other.clientVersion != null) return false; + } else if (!clientVersion.equals(other.clientVersion)) return false; + if (debug != other.debug) return false; + if (defaultMaxPerRoute != other.defaultMaxPerRoute) return false; + if (gzipEnabled != other.gzipEnabled) return false; + if (hostAddressResolverFactory == null) { + if (other.hostAddressResolverFactory != null) return false; + } else if (!hostAddressResolverFactory.equals(other.hostAddressResolverFactory)) + return false; + if (httpClientFactory == null) { + if (other.httpClientFactory != null) return false; + } else if (!httpClientFactory.equals(other.httpClientFactory)) return false; + if (httpConnectionTimeout != other.httpConnectionTimeout) return false; + if (httpProxyHost == null) { + if (other.httpProxyHost != null) return false; + } else if (!httpProxyHost.equals(other.httpProxyHost)) return false; + if (httpProxyPassword == null) { + if (other.httpProxyPassword != null) return false; + } else if (!httpProxyPassword.equals(other.httpProxyPassword)) return false; + if (httpProxyPort != other.httpProxyPort) return false; + if (httpProxyUser == null) { + if (other.httpProxyUser != null) return false; + } else if (!httpProxyUser.equals(other.httpProxyUser)) return false; + if (httpReadTimeout != other.httpReadTimeout) return false; + if (httpRetryCount != other.httpRetryCount) return false; + if (httpRetryIntervalSeconds != other.httpRetryIntervalSeconds) return false; + if (ignoreSSLError != other.ignoreSSLError) return false; + if (includeEntitiesEnabled != other.includeEntitiesEnabled) return false; + if (includeRTsEnabled != other.includeRTsEnabled) return false; + if (includeTwitterClientHeader != other.includeTwitterClientHeader) return false; + if (maxTotalConnections != other.maxTotalConnections) return false; + if (oAuthAccessToken == null) { + if (other.oAuthAccessToken != null) return false; + } else if (!oAuthAccessToken.equals(other.oAuthAccessToken)) return false; + if (oAuthAccessTokenSecret == null) { + if (other.oAuthAccessTokenSecret != null) return false; + } else if (!oAuthAccessTokenSecret.equals(other.oAuthAccessTokenSecret)) return false; + if (oAuthAccessTokenURL == null) { + if (other.oAuthAccessTokenURL != null) return false; + } else if (!oAuthAccessTokenURL.equals(other.oAuthAccessTokenURL)) return false; + if (oAuthAuthenticationURL == null) { + if (other.oAuthAuthenticationURL != null) return false; + } else if (!oAuthAuthenticationURL.equals(other.oAuthAuthenticationURL)) return false; + if (oAuthAuthorizationURL == null) { + if (other.oAuthAuthorizationURL != null) return false; + } else if (!oAuthAuthorizationURL.equals(other.oAuthAuthorizationURL)) return false; + if (oAuthBaseURL == null) { + if (other.oAuthBaseURL != null) return false; + } else if (!oAuthBaseURL.equals(other.oAuthBaseURL)) return false; + if (oAuthConsumerKey == null) { + if (other.oAuthConsumerKey != null) return false; + } else if (!oAuthConsumerKey.equals(other.oAuthConsumerKey)) return false; + if (oAuthConsumerSecret == null) { + if (other.oAuthConsumerSecret != null) return false; + } else if (!oAuthConsumerSecret.equals(other.oAuthConsumerSecret)) return false; + if (oAuthRequestTokenURL == null) { + if (other.oAuthRequestTokenURL != null) return false; + } else if (!oAuthRequestTokenURL.equals(other.oAuthRequestTokenURL)) return false; + if (password == null) { + if (other.password != null) return false; + } else if (!password.equals(other.password)) return false; + if (prettyDebug != other.prettyDebug) return false; + if (requestHeaders == null) { + if (other.requestHeaders != null) return false; + } else if (!requestHeaders.equals(other.requestHeaders)) return false; + if (restBaseURL == null) { + if (other.restBaseURL != null) return false; + } else if (!restBaseURL.equals(other.restBaseURL)) return false; + if (signingOAuthAccessTokenURL == null) { + if (other.signingOAuthAccessTokenURL != null) return false; + } else if (!signingOAuthAccessTokenURL.equals(other.signingOAuthAccessTokenURL)) + return false; + if (signingOAuthAuthenticationURL == null) { + if (other.signingOAuthAuthenticationURL != null) return false; + } else if (!signingOAuthAuthenticationURL.equals(other.signingOAuthAuthenticationURL)) + return false; + if (signingOAuthAuthorizationURL == null) { + if (other.signingOAuthAuthorizationURL != null) return false; + } else if (!signingOAuthAuthorizationURL.equals(other.signingOAuthAuthorizationURL)) + return false; + if (signingOAuthBaseURL == null) { + if (other.signingOAuthBaseURL != null) return false; + } else if (!signingOAuthBaseURL.equals(other.signingOAuthBaseURL)) return false; + if (signingOAuthRequestTokenURL == null) { + if (other.signingOAuthRequestTokenURL != null) return false; + } else if (!signingOAuthRequestTokenURL.equals(other.signingOAuthRequestTokenURL)) + return false; + if (signingRestBaseURL == null) { + if (other.signingRestBaseURL != null) return false; + } else if (!signingRestBaseURL.equals(other.signingRestBaseURL)) return false; + if (useSSL != other.useSSL) return false; + if (user == null) { + if (other.user != null) return false; + } else if (!user.equals(other.user)) return false; + if (userAgent == null) { + if (other.userAgent != null) return false; + } else if (!userAgent.equals(other.userAgent)) return false; + return true; + } + + @Override + public final String getClientName() { + return clientName; + } + + @Override + public final String getClientURL() { + return clientURL; + } + + @Override + public final String getClientVersion() { + return clientVersion; + } + + @Override + public HostAddressResolverFactory getHostAddressResolverFactory() { + return hostAddressResolverFactory; + } + + @Override + public HttpClientFactory getHttpClientFactory() { + return httpClientFactory; + } + + @Override + public final int getHttpConnectionTimeout() { + return httpConnectionTimeout; + } + + @Override + public final int getHttpDefaultMaxPerRoute() { + return defaultMaxPerRoute; + } + + @Override + public final int getHttpMaxTotalConnections() { + return maxTotalConnections; + } + + @Override + public final String getHttpProxyHost() { + return httpProxyHost; + } + + @Override + public final String getHttpProxyPassword() { + return httpProxyPassword; + } + + @Override + public final int getHttpProxyPort() { + return httpProxyPort; + } + + @Override + public final String getHttpProxyUser() { + return httpProxyUser; + } + + @Override + public final int getHttpReadTimeout() { + return httpReadTimeout; + } + + @Override + public final int getHttpRetryCount() { + return httpRetryCount; + } + + @Override + public final int getHttpRetryIntervalSeconds() { + return httpRetryIntervalSeconds; + } + + @Override + public final String getHttpUserAgent() { + return userAgent; + } + + @Override + public String getOAuthAccessToken() { + return oAuthAccessToken; + } + + @Override + public String getOAuthAccessTokenSecret() { + return oAuthAccessTokenSecret; + } + + @Override + public String getOAuthAccessTokenURL() { + return oAuthAccessTokenURL; + } + + @Override + public String getOAuthAuthenticationURL() { + return oAuthAuthenticationURL; + } + + @Override + public String getOAuthAuthorizationURL() { + return oAuthAuthorizationURL; + } + + @Override + public String getOAuthBaseURL() { + return oAuthBaseURL; + } + + @Override + public final String getOAuthConsumerKey() { + return oAuthConsumerKey; + } + + @Override + public final String getOAuthConsumerSecret() { + return oAuthConsumerSecret; + } + + @Override + public String getOAuthRequestTokenURL() { + return oAuthRequestTokenURL; + } + + @Override + public final String getPassword() { + return password; + } + + @Override + public Map getRequestHeaders() { + return requestHeaders; + } + + @Override + public String getRestBaseURL() { + return restBaseURL; + } + + @Override + public String getSigningOAuthAccessTokenURL() { + return signingOAuthAccessTokenURL != null ? signingOAuthAccessTokenURL : oAuthAccessTokenURL; + } + + @Override + public String getSigningOAuthAuthenticationURL() { + return signingOAuthAuthenticationURL != null ? signingOAuthAuthenticationURL : oAuthAuthenticationURL; + } + + @Override + public String getSigningOAuthAuthorizationURL() { + return signingOAuthAuthorizationURL != null ? signingOAuthAuthorizationURL : oAuthAuthorizationURL; + } + + @Override + public String getSigningOAuthBaseURL() { + return signingOAuthBaseURL != null ? signingOAuthBaseURL : oAuthBaseURL; + } + + @Override + public String getSigningOAuthRequestTokenURL() { + return signingOAuthRequestTokenURL != null ? signingOAuthRequestTokenURL : oAuthRequestTokenURL; + } + + @Override + public String getSigningRestBaseURL() { + return signingRestBaseURL != null ? signingRestBaseURL : restBaseURL; + } + + @Override + public String getSigningUploadBaseURL() { + return signingUploadBaseURL != null ? signingUploadBaseURL : uploadBaseURL; + } + + @Override + public String getUploadBaseURL() { + return uploadBaseURL; + } + + @Override + public final String getUser() { + return user; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (clientName == null ? 0 : clientName.hashCode()); + result = prime * result + (clientURL == null ? 0 : clientURL.hashCode()); + result = prime * result + (clientVersion == null ? 0 : clientVersion.hashCode()); + result = prime * result + (debug ? 1231 : 1237); + result = prime * result + defaultMaxPerRoute; + result = prime * result + (gzipEnabled ? 1231 : 1237); + result = prime * result + (hostAddressResolverFactory == null ? 0 : hostAddressResolverFactory.hashCode()); + result = prime * result + (httpClientFactory == null ? 0 : httpClientFactory.hashCode()); + result = prime * result + httpConnectionTimeout; + result = prime * result + (httpProxyHost == null ? 0 : httpProxyHost.hashCode()); + result = prime * result + (httpProxyPassword == null ? 0 : httpProxyPassword.hashCode()); + result = prime * result + httpProxyPort; + result = prime * result + (httpProxyUser == null ? 0 : httpProxyUser.hashCode()); + result = prime * result + httpReadTimeout; + result = prime * result + httpRetryCount; + result = prime * result + httpRetryIntervalSeconds; + result = prime * result + (ignoreSSLError ? 1231 : 1237); + result = prime * result + (includeEntitiesEnabled ? 1231 : 1237); + result = prime * result + (includeRTsEnabled ? 1231 : 1237); + result = prime * result + (includeTwitterClientHeader ? 1231 : 1237); + result = prime * result + maxTotalConnections; + result = prime * result + (oAuthAccessToken == null ? 0 : oAuthAccessToken.hashCode()); + result = prime * result + (oAuthAccessTokenSecret == null ? 0 : oAuthAccessTokenSecret.hashCode()); + result = prime * result + (oAuthAccessTokenURL == null ? 0 : oAuthAccessTokenURL.hashCode()); + result = prime * result + (oAuthAuthenticationURL == null ? 0 : oAuthAuthenticationURL.hashCode()); + result = prime * result + (oAuthAuthorizationURL == null ? 0 : oAuthAuthorizationURL.hashCode()); + result = prime * result + (oAuthBaseURL == null ? 0 : oAuthBaseURL.hashCode()); + result = prime * result + (oAuthConsumerKey == null ? 0 : oAuthConsumerKey.hashCode()); + result = prime * result + (oAuthConsumerSecret == null ? 0 : oAuthConsumerSecret.hashCode()); + result = prime * result + (oAuthRequestTokenURL == null ? 0 : oAuthRequestTokenURL.hashCode()); + result = prime * result + (password == null ? 0 : password.hashCode()); + result = prime * result + (prettyDebug ? 1231 : 1237); + result = prime * result + (requestHeaders == null ? 0 : requestHeaders.hashCode()); + result = prime * result + (restBaseURL == null ? 0 : restBaseURL.hashCode()); + result = prime * result + (signingOAuthAccessTokenURL == null ? 0 : signingOAuthAccessTokenURL.hashCode()); + result = prime * result + + (signingOAuthAuthenticationURL == null ? 0 : signingOAuthAuthenticationURL.hashCode()); + result = prime * result + (signingOAuthAuthorizationURL == null ? 0 : signingOAuthAuthorizationURL.hashCode()); + result = prime * result + (signingOAuthBaseURL == null ? 0 : signingOAuthBaseURL.hashCode()); + result = prime * result + (signingOAuthRequestTokenURL == null ? 0 : signingOAuthRequestTokenURL.hashCode()); + result = prime * result + (signingRestBaseURL == null ? 0 : signingRestBaseURL.hashCode()); + result = prime * result + (useSSL ? 1231 : 1237); + result = prime * result + (user == null ? 0 : user.hashCode()); + result = prime * result + (userAgent == null ? 0 : userAgent.hashCode()); + return result; + } + + @Override + public final boolean isDebugEnabled() { + return debug; + } + + @Override + public boolean isGZIPEnabled() { + return gzipEnabled; + } + + @Override + public boolean isIncludeEntitiesEnabled() { + return includeEntitiesEnabled; + } + + @Override + public boolean isIncludeRTsEnabled() { + return includeRTsEnabled; + } + + @Override + public boolean isIncludeReplyCountEnabled() { + return includeReplyCountEnabled; + } + + @Override + public boolean isIncludeDescendentReplyCountEnabled() { + return includeDescendentReplyCountEnabled; + } + + @Override + public boolean isPrettyDebugEnabled() { + return prettyDebug; + } + + @Override + public boolean isProxyConfigured() { + return (getHttpProxyHost() != null || "".equals(getHttpProxyHost())) && getHttpProxyPort() > 0; + } + + @Override + public boolean isSSLEnabled() { + return getRestBaseURL() != null && getRestBaseURL().startsWith("https://"); + } + + @Override + public final boolean isSSLErrorIgnored() { + return ignoreSSLError; + } + + @Override + public boolean isTwitterClientHeaderIncluded() { + return includeTwitterClientHeader; + } + + @Override + public String toString() { + return "ConfigurationBase{debug=" + debug + ", userAgent=" + userAgent + ", user=" + user + ", password=" + + password + ", useSSL=" + useSSL + ", ignoreSSLError=" + ignoreSSLError + ", prettyDebug=" + + prettyDebug + ", gzipEnabled=" + gzipEnabled + ", httpProxyHost=" + httpProxyHost + + ", httpProxyUser=" + httpProxyUser + ", httpProxyPassword=" + httpProxyPassword + ", httpProxyPort=" + + httpProxyPort + ", httpConnectionTimeout=" + httpConnectionTimeout + ", httpReadTimeout=" + + httpReadTimeout + ", httpRetryCount=" + httpRetryCount + ", httpRetryIntervalSeconds=" + + httpRetryIntervalSeconds + ", maxTotalConnections=" + maxTotalConnections + ", defaultMaxPerRoute=" + + defaultMaxPerRoute + ", oAuthConsumerKey=" + oAuthConsumerKey + ", oAuthConsumerSecret=" + + oAuthConsumerSecret + ", oAuthAccessToken=" + oAuthAccessToken + ", oAuthAccessTokenSecret=" + + oAuthAccessTokenSecret + ", oAuthRequestTokenURL=" + oAuthRequestTokenURL + + ", oAuthAuthorizationURL=" + oAuthAuthorizationURL + ", oAuthAccessTokenURL=" + oAuthAccessTokenURL + + ", oAuthAuthenticationURL=" + oAuthAuthenticationURL + ", signingOAuthRequestTokenURL=" + + signingOAuthRequestTokenURL + ", signingOAuthAuthorizationURL=" + signingOAuthAuthorizationURL + + ", signingOAuthAccessTokenURL=" + signingOAuthAccessTokenURL + ", signingOAuthAuthenticationURL=" + + signingOAuthAuthenticationURL + ", oAuthBaseURL=" + oAuthBaseURL + ", signingOAuthBaseURL=" + + signingOAuthBaseURL + ", signingRestBaseURL=" + signingRestBaseURL + ", restBaseURL=" + restBaseURL + + ", includeRTsEnabled=" + includeRTsEnabled + ", includeEntitiesEnabled=" + includeEntitiesEnabled + + ", includeTwitterClientHeader=" + includeTwitterClientHeader + ", clientVersion=" + clientVersion + + ", clientURL=" + clientURL + ", clientName=" + clientName + ", httpClientFactory=" + + httpClientFactory + ", hostAddressResolverFactory=" + hostAddressResolverFactory + + ", requestHeaders=" + requestHeaders + "}"; + } + + protected void cacheInstance() { + cacheInstance(this); + } + + // assures equality after deserializedation + protected Object readResolve() throws ObjectStreamException { + return getInstance(this); + } + + protected final void setClientName(final String clientName) { + this.clientName = clientName; + initRequestHeaders(); + } + + protected final void setClientURL(final String clientURL) { + this.clientURL = clientURL; + initRequestHeaders(); + } + + protected final void setClientVersion(final String clientVersion) { + this.clientVersion = clientVersion; + initRequestHeaders(); + } + + protected final void setDebug(final boolean debug) { + this.debug = debug; + } + + protected final void setGZIPEnabled(final boolean gzipEnabled) { + this.gzipEnabled = gzipEnabled; + initRequestHeaders(); + } + + protected void setHostAddressResolverFactory(final HostAddressResolverFactory factory) { + hostAddressResolverFactory = factory; + } + + protected void setHttpClientFactory(final HttpClientFactory factory) { + httpClientFactory = factory; + } + + protected final void setHttpConnectionTimeout(final int connectionTimeout) { + httpConnectionTimeout = connectionTimeout; + } + + protected final void setHttpDefaultMaxPerRoute(final int defaultMaxPerRoute) { + this.defaultMaxPerRoute = defaultMaxPerRoute; + } + + protected final void setHttpMaxTotalConnections(final int maxTotalConnections) { + this.maxTotalConnections = maxTotalConnections; + } + + protected final void setHttpProxyHost(final String proxyHost) { + httpProxyHost = proxyHost; + initRequestHeaders(); + } + + protected final void setHttpProxyPassword(final String proxyPassword) { + httpProxyPassword = proxyPassword; + } + + protected final void setHttpProxyPort(final int proxyPort) { + httpProxyPort = proxyPort; + initRequestHeaders(); + } + + protected final void setHttpProxyUser(final String proxyUser) { + httpProxyUser = proxyUser; + } + + protected final void setHttpReadTimeout(final int readTimeout) { + httpReadTimeout = readTimeout; + } + + protected final void setHttpRetryCount(final int retryCount) { + httpRetryCount = retryCount; + } + + protected final void setHttpRetryIntervalSeconds(final int retryIntervalSeconds) { + httpRetryIntervalSeconds = retryIntervalSeconds; + } + + protected final void setHttpUserAgent(final String userAgent) { + this.userAgent = userAgent; + initRequestHeaders(); + } + + protected final void setIgnoreSSLError(final boolean ignore) { + ignoreSSLError = ignore; + initRequestHeaders(); + } + + protected final void setIncludeEntitiesEnabled(final boolean enabled) { + includeEntitiesEnabled = enabled; + } + + protected final void setIncludeRTsEnabled(final boolean enabled) { + includeRTsEnabled = enabled; + } + + protected final void setIncludeReplyCountEnabled(final boolean enabled) { + includeReplyCountEnabled = enabled; + } + + protected final void setIncludeDescendentReplyCountEnabled(final boolean enabled) { + includeDescendentReplyCountEnabled = enabled; + } + + protected final void setIncludeTwitterClientHeader(final boolean includeHeader) { + includeTwitterClientHeader = includeHeader; + initRequestHeaders(); + } + + protected final void setOAuthAccessToken(final String accessToken) { + oAuthAccessToken = accessToken; + } + + protected final void setOAuthAccessTokenSecret(final String accessTokenSecret) { + oAuthAccessTokenSecret = accessTokenSecret; + } + + protected final void setOAuthBaseURL(String oAuthBaseURL) { + if (isNullOrEmpty(oAuthBaseURL)) { + oAuthBaseURL = DEFAULT_OAUTH_BASE_URL; + } + this.oAuthBaseURL = fixURLSlash(oAuthBaseURL); + + oAuthAccessTokenURL = oAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN; + oAuthAuthenticationURL = oAuthBaseURL + PATH_SEGMENT_AUTHENTICATION; + oAuthAuthorizationURL = oAuthBaseURL + PATH_SEGMENT_AUTHORIZATION; + oAuthRequestTokenURL = oAuthBaseURL + PATH_SEGMENT_REQUEST_TOKEN; + + setSigningOAuthBaseURL(oAuthBaseURL); + fixOAuthBaseURL(); + } + + protected final void setOAuthConsumerKey(final String oAuthConsumerKey) { + this.oAuthConsumerKey = oAuthConsumerKey; + fixRestBaseURL(); + } + + protected final void setOAuthConsumerSecret(final String oAuthConsumerSecret) { + this.oAuthConsumerSecret = oAuthConsumerSecret; + fixRestBaseURL(); + } + + protected final void setPassword(final String password) { + this.password = password; + } + + protected final void setPrettyDebugEnabled(final boolean prettyDebug) { + this.prettyDebug = prettyDebug; + } + + protected final void setRestBaseURL(String restBaseURL) { + if (isNullOrEmpty(restBaseURL)) { + restBaseURL = DEFAULT_REST_BASE_URL; + } + this.restBaseURL = fixURLSlash(restBaseURL); + fixRestBaseURL(); + } + + protected final void setSigningOAuthBaseURL(String signingOAuthBaseURL) { + if (isNullOrEmpty(signingOAuthBaseURL)) { + signingOAuthBaseURL = DEFAULT_SIGNING_OAUTH_BASE_URL; + } + this.signingOAuthBaseURL = fixURLSlash(signingOAuthBaseURL); + + signingOAuthAccessTokenURL = signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN; + signingOAuthAuthenticationURL = signingOAuthBaseURL + PATH_SEGMENT_AUTHENTICATION; + signingOAuthAuthorizationURL = signingOAuthBaseURL + PATH_SEGMENT_AUTHORIZATION; + signingOAuthRequestTokenURL = signingOAuthBaseURL + PATH_SEGMENT_REQUEST_TOKEN; + + fixOAuthBaseURL(); + } + + protected final void setSigningRestBaseURL(String signingRestBaseURL) { + if (isNullOrEmpty(signingRestBaseURL)) { + signingRestBaseURL = DEFAULT_SIGNING_REST_BASE_URL; + } + this.signingRestBaseURL = fixURLSlash(signingRestBaseURL); + fixRestBaseURL(); + } + + protected void setSigningUploadBaseURL(String signingUploadBaseURL) { + if (isNullOrEmpty(signingUploadBaseURL)) { + signingUploadBaseURL = DEFAULT_SIGNING_UPLOAD_BASE_URL; + } + this.signingUploadBaseURL = fixURLSlash(signingUploadBaseURL); + fixUploadBaseURL(); + } + + protected void setUploadBaseURL(String uploadBaseURL) { + if (isNullOrEmpty(uploadBaseURL)) { + uploadBaseURL = DEFAULT_UPLOAD_BASE_URL; + } + this.uploadBaseURL = fixURLSlash(uploadBaseURL); + fixUploadBaseURL(); + } + + protected final void setUser(final String user) { + this.user = user; + } + + protected final void setUseSSL(final boolean useSSL) { + this.useSSL = useSSL; + fixRestBaseURL(); + } + + private void fixOAuthBaseURL() { + if (DEFAULT_OAUTH_BASE_URL.equals(fixURL(DEFAULT_USE_SSL, oAuthBaseURL))) { + oAuthBaseURL = fixURL(useSSL, oAuthBaseURL); + } + if (oAuthBaseURL != null && oAuthBaseURL.equals(fixURL(DEFAULT_USE_SSL, signingOAuthBaseURL))) { + signingOAuthBaseURL = fixURL(useSSL, signingOAuthBaseURL); + } + if (oAuthBaseURL != null + && (oAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, oAuthAccessTokenURL))) { + oAuthAccessTokenURL = fixURL(useSSL, oAuthAccessTokenURL); + } + if (oAuthBaseURL != null + && (oAuthBaseURL + PATH_SEGMENT_AUTHENTICATION).equals(fixURL(DEFAULT_USE_SSL, oAuthAuthenticationURL))) { + oAuthAuthenticationURL = fixURL(useSSL, oAuthAuthenticationURL); + } + if (oAuthBaseURL != null + && (oAuthBaseURL + PATH_SEGMENT_AUTHORIZATION).equals(fixURL(DEFAULT_USE_SSL, oAuthAuthorizationURL))) { + oAuthAuthorizationURL = fixURL(useSSL, oAuthAuthorizationURL); + } + if (oAuthBaseURL != null + && (oAuthBaseURL + PATH_SEGMENT_REQUEST_TOKEN).equals(fixURL(DEFAULT_USE_SSL, oAuthRequestTokenURL))) { + oAuthRequestTokenURL = fixURL(useSSL, oAuthRequestTokenURL); + } + if (signingOAuthBaseURL != null + && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, + signingOAuthAccessTokenURL))) { + signingOAuthAccessTokenURL = fixURL(useSSL, signingOAuthAccessTokenURL); + } + if (signingOAuthBaseURL != null + && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, + signingOAuthAuthenticationURL))) { + signingOAuthAuthenticationURL = fixURL(useSSL, signingOAuthAuthenticationURL); + } + if (signingOAuthBaseURL != null + && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, + signingOAuthAuthorizationURL))) { + signingOAuthAuthorizationURL = fixURL(useSSL, signingOAuthAuthorizationURL); + } + if (signingOAuthBaseURL != null + && (signingOAuthBaseURL + PATH_SEGMENT_ACCESS_TOKEN).equals(fixURL(DEFAULT_USE_SSL, + signingOAuthRequestTokenURL))) { + signingOAuthRequestTokenURL = fixURL(useSSL, signingOAuthRequestTokenURL); + } + initRequestHeaders(); + } + + private void fixRestBaseURL() { + if (DEFAULT_REST_BASE_URL.equals(fixURL(DEFAULT_USE_SSL, restBaseURL))) { + restBaseURL = fixURL(useSSL, restBaseURL); + } + if (restBaseURL != null && restBaseURL.equals(fixURL(DEFAULT_USE_SSL, signingRestBaseURL))) { + signingRestBaseURL = fixURL(useSSL, signingRestBaseURL); + } + initRequestHeaders(); + } + + private void fixUploadBaseURL() { + if (DEFAULT_UPLOAD_BASE_URL.equals(fixURL(DEFAULT_USE_SSL, uploadBaseURL))) { + uploadBaseURL = fixURL(useSSL, uploadBaseURL); + } + if (uploadBaseURL != null && uploadBaseURL.equals(fixURL(DEFAULT_USE_SSL, uploadBaseURL))) { + uploadBaseURL = fixURL(useSSL, uploadBaseURL); + } + initRequestHeaders(); + } + + final void initRequestHeaders() { + requestHeaders = new HashMap(); + if (includeTwitterClientHeader) { + requestHeaders.put("X-Twitter-Client-Version", getClientVersion()); + requestHeaders.put("X-Twitter-Client-URL", getClientURL()); + requestHeaders.put("X-Twitter-Client", getClientName()); + } + + requestHeaders.put("User-Agent", getHttpUserAgent()); + if (gzipEnabled) { + requestHeaders.put("Accept-Encoding", "gzip"); + } + // I found this may cause "Socket is closed" error in Android, so I + // changed it to "keep-alive". + if (!isNullOrEmpty(httpProxyHost) && httpProxyPort > 0) { + requestHeaders.put("Connection", "keep-alive"); + } else { + requestHeaders.put("Connection", "close"); + } + } + + private static void cacheInstance(final ConfigurationBase conf) { + if (!instances.contains(conf)) { + instances.add(conf); + } + } + + private static ConfigurationBase getInstance(final ConfigurationBase configurationBase) { + int index; + if ((index = instances.indexOf(configurationBase)) == -1) { + instances.add(configurationBase); + return configurationBase; + } else + return instances.get(index); + } + + static String fixURL(final boolean useSSL, String url) { + if (null == url) return null; + if (!url.startsWith("http://") || !url.startsWith("https://")) { + url = "https://" + url; + } + final int index = url.indexOf("://"); + if (-1 == index) throw new IllegalArgumentException("url should contain '://'"); + final String hostAndLater = url.substring(index + 3); + if (useSSL) + return "https://" + hostAndLater; + else + return "http://" + hostAndLater; + } + + static String fixURLSlash(final String urlOrig) { + if (urlOrig == null) return null; + if (!urlOrig.endsWith("/")) return urlOrig + "/"; + return urlOrig; + } + + static boolean isNullOrEmpty(final String string) { + if (string == null) return true; + if (string.length() == 0) return true; + return false; + } } diff --git a/twidere/src/main/java/twitter4j/conf/ConfigurationBuilder.java b/twidere/src/main/java/twitter4j/conf/ConfigurationBuilder.java index fe97b155b..e6ea513bb 100644 --- a/twidere/src/main/java/twitter4j/conf/ConfigurationBuilder.java +++ b/twidere/src/main/java/twitter4j/conf/ConfigurationBuilder.java @@ -25,285 +25,301 @@ import twitter4j.http.HttpClientFactory; * {@code new ConfigurationBuilder().build()} would create a usable * configuration. This configuration builder is useful for clients that wish to * configure twitter4j in unit tests or from command line flags for example. - * + * * @author John Sirois - john.sirois at gmail.com */ public final class ConfigurationBuilder { - private ConfigurationBase configuration = new ConfigurationBase(); + private ConfigurationBase configuration = new ConfigurationBase(); - public ConfigurationBuilder() { + public ConfigurationBuilder() { - } + } - public ConfigurationBuilder(final Configuration conf) { - configuration.setClientName(conf.getClientName()); - configuration.setClientURL(conf.getClientURL()); - configuration.setClientVersion(conf.getClientVersion()); - configuration.setDebug(conf.isDebugEnabled()); - configuration.setGZIPEnabled(conf.isGZIPEnabled()); - configuration.setHostAddressResolverFactory(conf.getHostAddressResolverFactory()); - configuration.setHttpClientFactory(conf.getHttpClientFactory()); - configuration.setHttpConnectionTimeout(conf.getHttpConnectionTimeout()); - configuration.setHttpDefaultMaxPerRoute(conf.getHttpDefaultMaxPerRoute()); - configuration.setHttpMaxTotalConnections(conf.getHttpMaxTotalConnections()); - configuration.setHttpProxyHost(conf.getHttpProxyHost()); - configuration.setHttpProxyPassword(conf.getHttpProxyPassword()); - configuration.setHttpProxyPort(conf.getHttpProxyPort()); - configuration.setHttpProxyUser(conf.getHttpProxyUser()); - configuration.setHttpReadTimeout(conf.getHttpReadTimeout()); - configuration.setHttpRetryCount(conf.getHttpRetryCount()); - configuration.setHttpRetryIntervalSeconds(conf.getHttpRetryIntervalSeconds()); - configuration.setHttpUserAgent(conf.getHttpUserAgent()); - configuration.setIgnoreSSLError(conf.isSSLErrorIgnored()); - configuration.setIncludeEntitiesEnbled(conf.isIncludeEntitiesEnabled()); - configuration.setIncludeRTsEnbled(conf.isIncludeRTsEnabled()); - configuration.setIncludeTwitterClientHeader(conf.isTwitterClientHeaderIncluded()); - configuration.setOAuthAccessToken(conf.getOAuthAccessToken()); - configuration.setOAuthAccessTokenSecret(conf.getOAuthAccessTokenSecret()); - configuration.setOAuthBaseURL(conf.getOAuthBaseURL()); - configuration.setOAuthConsumerKey(conf.getOAuthConsumerKey()); - configuration.setOAuthConsumerSecret(conf.getOAuthConsumerSecret()); - configuration.setPassword(conf.getPassword()); - configuration.setPrettyDebugEnabled(conf.isPrettyDebugEnabled()); - configuration.setRestBaseURL(conf.getRestBaseURL()); - configuration.setSigningOAuthBaseURL(conf.getSigningOAuthBaseURL()); - configuration.setSigningRestBaseURL(conf.getSigningRestBaseURL()); - configuration.setUploadBaseURL(conf.getUploadBaseURL()); - configuration.setSigningUploadBaseURL(conf.getSigningUploadBaseURL()); - configuration.setUser(conf.getUser()); - configuration.setUseSSL(conf.isSSLEnabled()); + public ConfigurationBuilder(final Configuration conf) { + configuration.setClientName(conf.getClientName()); + configuration.setClientURL(conf.getClientURL()); + configuration.setClientVersion(conf.getClientVersion()); + configuration.setDebug(conf.isDebugEnabled()); + configuration.setGZIPEnabled(conf.isGZIPEnabled()); + configuration.setHostAddressResolverFactory(conf.getHostAddressResolverFactory()); + configuration.setHttpClientFactory(conf.getHttpClientFactory()); + configuration.setHttpConnectionTimeout(conf.getHttpConnectionTimeout()); + configuration.setHttpDefaultMaxPerRoute(conf.getHttpDefaultMaxPerRoute()); + configuration.setHttpMaxTotalConnections(conf.getHttpMaxTotalConnections()); + configuration.setHttpProxyHost(conf.getHttpProxyHost()); + configuration.setHttpProxyPassword(conf.getHttpProxyPassword()); + configuration.setHttpProxyPort(conf.getHttpProxyPort()); + configuration.setHttpProxyUser(conf.getHttpProxyUser()); + configuration.setHttpReadTimeout(conf.getHttpReadTimeout()); + configuration.setHttpRetryCount(conf.getHttpRetryCount()); + configuration.setHttpRetryIntervalSeconds(conf.getHttpRetryIntervalSeconds()); + configuration.setHttpUserAgent(conf.getHttpUserAgent()); + configuration.setIgnoreSSLError(conf.isSSLErrorIgnored()); + configuration.setIncludeEntitiesEnabled(conf.isIncludeEntitiesEnabled()); + configuration.setIncludeRTsEnabled(conf.isIncludeRTsEnabled()); + configuration.setIncludeReplyCountEnabled(conf.isIncludeReplyCountEnabled()); + configuration.setIncludeDescendentReplyCountEnabled(conf.isIncludeDescendentReplyCountEnabled()); + configuration.setIncludeRTsEnabled(conf.isIncludeRTsEnabled()); + configuration.setIncludeTwitterClientHeader(conf.isTwitterClientHeaderIncluded()); + configuration.setOAuthAccessToken(conf.getOAuthAccessToken()); + configuration.setOAuthAccessTokenSecret(conf.getOAuthAccessTokenSecret()); + configuration.setOAuthBaseURL(conf.getOAuthBaseURL()); + configuration.setOAuthConsumerKey(conf.getOAuthConsumerKey()); + configuration.setOAuthConsumerSecret(conf.getOAuthConsumerSecret()); + configuration.setPassword(conf.getPassword()); + configuration.setPrettyDebugEnabled(conf.isPrettyDebugEnabled()); + configuration.setRestBaseURL(conf.getRestBaseURL()); + configuration.setSigningOAuthBaseURL(conf.getSigningOAuthBaseURL()); + configuration.setSigningRestBaseURL(conf.getSigningRestBaseURL()); + configuration.setUploadBaseURL(conf.getUploadBaseURL()); + configuration.setSigningUploadBaseURL(conf.getSigningUploadBaseURL()); + configuration.setUser(conf.getUser()); + configuration.setUseSSL(conf.isSSLEnabled()); - } + } - public Configuration build() { - checkNotBuilt(); - configuration.cacheInstance(); - try { - return configuration; - } finally { - configuration = null; - } - } + public Configuration build() { + checkNotBuilt(); + configuration.cacheInstance(); + try { + return configuration; + } finally { + configuration = null; + } + } - public ConfigurationBuilder setClientName(final String clientName) { - checkNotBuilt(); - configuration.setClientName(clientName); - return this; - } + public ConfigurationBuilder setClientName(final String clientName) { + checkNotBuilt(); + configuration.setClientName(clientName); + return this; + } - public ConfigurationBuilder setClientURL(final String clientURL) { - checkNotBuilt(); - configuration.setClientURL(clientURL); - return this; - } + public ConfigurationBuilder setClientURL(final String clientURL) { + checkNotBuilt(); + configuration.setClientURL(clientURL); + return this; + } - public ConfigurationBuilder setClientVersion(final String clientVersion) { - checkNotBuilt(); - configuration.setClientVersion(clientVersion); - return this; - } + public ConfigurationBuilder setClientVersion(final String clientVersion) { + checkNotBuilt(); + configuration.setClientVersion(clientVersion); + return this; + } - public ConfigurationBuilder setDebugEnabled(final boolean debugEnabled) { - checkNotBuilt(); - configuration.setDebug(debugEnabled); - return this; - } + public ConfigurationBuilder setDebugEnabled(final boolean debugEnabled) { + checkNotBuilt(); + configuration.setDebug(debugEnabled); + return this; + } - public ConfigurationBuilder setGZIPEnabled(final boolean gzipEnabled) { - checkNotBuilt(); - configuration.setGZIPEnabled(gzipEnabled); - return this; - } + public ConfigurationBuilder setGZIPEnabled(final boolean gzipEnabled) { + checkNotBuilt(); + configuration.setGZIPEnabled(gzipEnabled); + return this; + } - public ConfigurationBuilder setHostAddressResolverFactory(final HostAddressResolverFactory factory) { - checkNotBuilt(); - configuration.setHostAddressResolverFactory(factory); - return this; - } + public ConfigurationBuilder setHostAddressResolverFactory(final HostAddressResolverFactory factory) { + checkNotBuilt(); + configuration.setHostAddressResolverFactory(factory); + return this; + } - public ConfigurationBuilder setHttpClientFactory(final HttpClientFactory factory) { - checkNotBuilt(); - configuration.setHttpClientFactory(factory); - return this; - } + public ConfigurationBuilder setHttpClientFactory(final HttpClientFactory factory) { + checkNotBuilt(); + configuration.setHttpClientFactory(factory); + return this; + } - public ConfigurationBuilder setHttpConnectionTimeout(final int httpConnectionTimeout) { - checkNotBuilt(); - configuration.setHttpConnectionTimeout(httpConnectionTimeout); - return this; - } + public ConfigurationBuilder setHttpConnectionTimeout(final int httpConnectionTimeout) { + checkNotBuilt(); + configuration.setHttpConnectionTimeout(httpConnectionTimeout); + return this; + } - public ConfigurationBuilder setHttpDefaultMaxPerRoute(final int httpDefaultMaxPerRoute) { - checkNotBuilt(); - configuration.setHttpDefaultMaxPerRoute(httpDefaultMaxPerRoute); - return this; - } + public ConfigurationBuilder setHttpDefaultMaxPerRoute(final int httpDefaultMaxPerRoute) { + checkNotBuilt(); + configuration.setHttpDefaultMaxPerRoute(httpDefaultMaxPerRoute); + return this; + } - public ConfigurationBuilder setHttpMaxTotalConnections(final int httpMaxConnections) { - checkNotBuilt(); - configuration.setHttpMaxTotalConnections(httpMaxConnections); - return this; - } + public ConfigurationBuilder setHttpMaxTotalConnections(final int httpMaxConnections) { + checkNotBuilt(); + configuration.setHttpMaxTotalConnections(httpMaxConnections); + return this; + } - public ConfigurationBuilder setHttpProxyHost(final String httpProxyHost) { - checkNotBuilt(); - configuration.setHttpProxyHost(httpProxyHost); - return this; - } + public ConfigurationBuilder setHttpProxyHost(final String httpProxyHost) { + checkNotBuilt(); + configuration.setHttpProxyHost(httpProxyHost); + return this; + } - public ConfigurationBuilder setHttpProxyPassword(final String httpProxyPassword) { - checkNotBuilt(); - configuration.setHttpProxyPassword(httpProxyPassword); - return this; - } + public ConfigurationBuilder setHttpProxyPassword(final String httpProxyPassword) { + checkNotBuilt(); + configuration.setHttpProxyPassword(httpProxyPassword); + return this; + } - public ConfigurationBuilder setHttpProxyPort(final int httpProxyPort) { - checkNotBuilt(); - configuration.setHttpProxyPort(httpProxyPort); - return this; - } + public ConfigurationBuilder setHttpProxyPort(final int httpProxyPort) { + checkNotBuilt(); + configuration.setHttpProxyPort(httpProxyPort); + return this; + } - public ConfigurationBuilder setHttpProxyUser(final String httpProxyUser) { - checkNotBuilt(); - configuration.setHttpProxyUser(httpProxyUser); - return this; - } + public ConfigurationBuilder setHttpProxyUser(final String httpProxyUser) { + checkNotBuilt(); + configuration.setHttpProxyUser(httpProxyUser); + return this; + } - public ConfigurationBuilder setHttpReadTimeout(final int httpReadTimeout) { - checkNotBuilt(); - configuration.setHttpReadTimeout(httpReadTimeout); - return this; - } + public ConfigurationBuilder setHttpReadTimeout(final int httpReadTimeout) { + checkNotBuilt(); + configuration.setHttpReadTimeout(httpReadTimeout); + return this; + } - public ConfigurationBuilder setHttpRetryCount(final int httpRetryCount) { - checkNotBuilt(); - configuration.setHttpRetryCount(httpRetryCount); - return this; - } + public ConfigurationBuilder setHttpRetryCount(final int httpRetryCount) { + checkNotBuilt(); + configuration.setHttpRetryCount(httpRetryCount); + return this; + } - public ConfigurationBuilder setHttpRetryIntervalSeconds(final int httpRetryIntervalSeconds) { - checkNotBuilt(); - configuration.setHttpRetryIntervalSeconds(httpRetryIntervalSeconds); - return this; - } + public ConfigurationBuilder setHttpRetryIntervalSeconds(final int httpRetryIntervalSeconds) { + checkNotBuilt(); + configuration.setHttpRetryIntervalSeconds(httpRetryIntervalSeconds); + return this; + } - public ConfigurationBuilder setHttpUserAgent(final String userAgent) { - checkNotBuilt(); - configuration.setHttpUserAgent(userAgent); - return this; - } + public ConfigurationBuilder setHttpUserAgent(final String userAgent) { + checkNotBuilt(); + configuration.setHttpUserAgent(userAgent); + return this; + } - public ConfigurationBuilder setIgnoreSSLError(final boolean ignoreSSLError) { - checkNotBuilt(); - configuration.setIgnoreSSLError(ignoreSSLError); - return this; - } + public ConfigurationBuilder setIgnoreSSLError(final boolean ignoreSSLError) { + checkNotBuilt(); + configuration.setIgnoreSSLError(ignoreSSLError); + return this; + } - public ConfigurationBuilder setIncludeEntitiesEnabled(final boolean enabled) { - checkNotBuilt(); - configuration.setIncludeEntitiesEnbled(enabled); - return this; - } + public ConfigurationBuilder setIncludeEntitiesEnabled(final boolean enabled) { + checkNotBuilt(); + configuration.setIncludeEntitiesEnabled(enabled); + return this; + } - public ConfigurationBuilder setIncludeRTsEnabled(final boolean enabled) { - checkNotBuilt(); - configuration.setIncludeRTsEnbled(enabled); - return this; - } + public ConfigurationBuilder setIncludeRTsEnabled(final boolean enabled) { + checkNotBuilt(); + configuration.setIncludeRTsEnabled(enabled); + return this; + } - public ConfigurationBuilder setIncludeTwitterClientHeader(final boolean includeTwitterClientHeader) { - checkNotBuilt(); - configuration.setIncludeTwitterClientHeader(includeTwitterClientHeader); - return this; - } - public ConfigurationBuilder setOAuthAccessToken(final String oAuthAccessToken) { - checkNotBuilt(); - configuration.setOAuthAccessToken(oAuthAccessToken); - return this; - } + public ConfigurationBuilder setIncludeReplyCountEnabled(final boolean enabled) { + checkNotBuilt(); + configuration.setIncludeReplyCountEnabled(enabled); + return this; + } - public ConfigurationBuilder setOAuthAccessTokenSecret(final String oAuthAccessTokenSecret) { - checkNotBuilt(); - configuration.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); - return this; - } + public ConfigurationBuilder setIncludeDescendentReplyCountEnabled(final boolean enabled) { + checkNotBuilt(); + configuration.setIncludeDescendentReplyCountEnabled(enabled); + return this; + } - public ConfigurationBuilder setOAuthBaseURL(final String oAuthBaseURL) { - checkNotBuilt(); - configuration.setOAuthBaseURL(oAuthBaseURL); - return this; - } + public ConfigurationBuilder setIncludeTwitterClientHeader(final boolean includeTwitterClientHeader) { + checkNotBuilt(); + configuration.setIncludeTwitterClientHeader(includeTwitterClientHeader); + return this; + } - public ConfigurationBuilder setOAuthConsumerKey(final String oAuthConsumerKey) { - checkNotBuilt(); - configuration.setOAuthConsumerKey(oAuthConsumerKey); - return this; - } + public ConfigurationBuilder setOAuthAccessToken(final String oAuthAccessToken) { + checkNotBuilt(); + configuration.setOAuthAccessToken(oAuthAccessToken); + return this; + } - public ConfigurationBuilder setOAuthConsumerSecret(final String oAuthConsumerSecret) { - checkNotBuilt(); - configuration.setOAuthConsumerSecret(oAuthConsumerSecret); - return this; - } + public ConfigurationBuilder setOAuthAccessTokenSecret(final String oAuthAccessTokenSecret) { + checkNotBuilt(); + configuration.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); + return this; + } - public ConfigurationBuilder setPassword(final String password) { - checkNotBuilt(); - configuration.setPassword(password); - return this; - } + public ConfigurationBuilder setOAuthBaseURL(final String oAuthBaseURL) { + checkNotBuilt(); + configuration.setOAuthBaseURL(oAuthBaseURL); + return this; + } - public ConfigurationBuilder setPrettyDebugEnabled(final boolean prettyDebugEnabled) { - checkNotBuilt(); - configuration.setPrettyDebugEnabled(prettyDebugEnabled); - return this; - } + public ConfigurationBuilder setOAuthConsumerKey(final String oAuthConsumerKey) { + checkNotBuilt(); + configuration.setOAuthConsumerKey(oAuthConsumerKey); + return this; + } - public ConfigurationBuilder setRestBaseURL(final String restBaseURL) { - checkNotBuilt(); - configuration.setRestBaseURL(restBaseURL); - return this; - } + public ConfigurationBuilder setOAuthConsumerSecret(final String oAuthConsumerSecret) { + checkNotBuilt(); + configuration.setOAuthConsumerSecret(oAuthConsumerSecret); + return this; + } - public ConfigurationBuilder setSigningOAuthBaseURL(final String signingOAuthBaseURL) { - checkNotBuilt(); - configuration.setSigningOAuthBaseURL(signingOAuthBaseURL); - return this; - } + public ConfigurationBuilder setPassword(final String password) { + checkNotBuilt(); + configuration.setPassword(password); + return this; + } - public ConfigurationBuilder setSigningRestBaseURL(final String signingRestBaseURL) { - checkNotBuilt(); - configuration.setSigningRestBaseURL(signingRestBaseURL); - return this; - } + public ConfigurationBuilder setPrettyDebugEnabled(final boolean prettyDebugEnabled) { + checkNotBuilt(); + configuration.setPrettyDebugEnabled(prettyDebugEnabled); + return this; + } - public ConfigurationBuilder setSigningUploadBaseURL(final String signingUploadBaseURL) { - checkNotBuilt(); - configuration.setSigningUploadBaseURL(signingUploadBaseURL); - return this; - } + public ConfigurationBuilder setRestBaseURL(final String restBaseURL) { + checkNotBuilt(); + configuration.setRestBaseURL(restBaseURL); + return this; + } - public ConfigurationBuilder setUploadBaseURL(final String uploadBaseURL) { - checkNotBuilt(); - configuration.setUploadBaseURL(uploadBaseURL); - return this; - } + public ConfigurationBuilder setSigningOAuthBaseURL(final String signingOAuthBaseURL) { + checkNotBuilt(); + configuration.setSigningOAuthBaseURL(signingOAuthBaseURL); + return this; + } - public ConfigurationBuilder setUser(final String user) { - checkNotBuilt(); - configuration.setUser(user); - return this; - } + public ConfigurationBuilder setSigningRestBaseURL(final String signingRestBaseURL) { + checkNotBuilt(); + configuration.setSigningRestBaseURL(signingRestBaseURL); + return this; + } - public ConfigurationBuilder setUseSSL(final boolean useSSL) { - checkNotBuilt(); - configuration.setUseSSL(useSSL); - return this; - } + public ConfigurationBuilder setSigningUploadBaseURL(final String signingUploadBaseURL) { + checkNotBuilt(); + configuration.setSigningUploadBaseURL(signingUploadBaseURL); + return this; + } - private void checkNotBuilt() { - if (configuration == null) - throw new IllegalStateException("Cannot use this builder any longer, build() has already been called"); - } + public ConfigurationBuilder setUploadBaseURL(final String uploadBaseURL) { + checkNotBuilt(); + configuration.setUploadBaseURL(uploadBaseURL); + return this; + } + + public ConfigurationBuilder setUser(final String user) { + checkNotBuilt(); + configuration.setUser(user); + return this; + } + + public ConfigurationBuilder setUseSSL(final boolean useSSL) { + checkNotBuilt(); + configuration.setUseSSL(useSSL); + return this; + } + + private void checkNotBuilt() { + if (configuration == null) + throw new IllegalStateException("Cannot use this builder any longer, build() has already been called"); + } } diff --git a/twidere/src/main/java/twitter4j/internal/json/StatusJSONImpl.java b/twidere/src/main/java/twitter4j/internal/json/StatusJSONImpl.java index 589d43bff..321381437 100644 --- a/twidere/src/main/java/twitter4j/internal/json/StatusJSONImpl.java +++ b/twidere/src/main/java/twitter4j/internal/json/StatusJSONImpl.java @@ -72,6 +72,17 @@ final class StatusJSONImpl extends TwitterResponseImpl implements Status { private Place place = null; private long retweetCount; private long favoriteCount; + + public long getReplyCount() { + return replyCount; + } + + public long getDescendentReplyCount() { + return descendentReplyCount; + } + + private long replyCount; + private long descendentReplyCount; private boolean wasRetweetedByMe; private boolean isPossiblySensitive; @@ -350,6 +361,8 @@ final class StatusJSONImpl extends TwitterResponseImpl implements Status { isPossiblySensitive = getBoolean("possibly_sensitive", json); retweetCount = getLong("retweet_count", json); favoriteCount = getLong("favorite_count", json); + replyCount = getLong("reply_count", json); + descendentReplyCount = getLong("descendent_reply_count", json); try { if (!json.isNull("user")) { user = new UserJSONImpl(json.getJSONObject("user")); diff --git a/twidere/src/main/res/drawable/shadow_user_banner_image.xml b/twidere/src/main/res/drawable/shadow_user_banner_image.xml new file mode 100644 index 000000000..f2e482de7 --- /dev/null +++ b/twidere/src/main/res/drawable/shadow_user_banner_image.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/layout/header_status.xml b/twidere/src/main/res/layout/header_status.xml index eecac9519..086a0195f 100644 --- a/twidere/src/main/res/layout/header_status.xml +++ b/twidere/src/main/res/layout/header_status.xml @@ -1,245 +1,259 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content"> - + - + - + - + - + - - + + - + -