use of org.eclipse.egit.github.core.User in project camel by apache.
the class MockPullRequestService method addPullRequest.
public PullRequest addPullRequest(String title) {
User author = createAuthor();
PullRequest pullRequest = new PullRequest();
pullRequest.setUser(author);
pullRequest.setHtmlUrl("https://github.com/someguy/somerepo/pull" + pullRequestNumber);
pullRequest.setTitle(title);
pullRequest.setNumber(pullRequestNumber.get());
pullRequest.setId(pullRequestNumber.get());
pullRequest.setState("open");
pullRequests.put(pullRequest.getId(), pullRequest);
pullRequestNumber.incrementAndGet();
return pullRequest;
}
use of org.eclipse.egit.github.core.User in project camel by apache.
the class MockPullRequestService method createAuthor.
private User createAuthor() {
User author = new User();
author.setEmail("someguy@gmail.com");
author.setHtmlUrl("http://github/someguy");
author.setLogin("someguy");
return author;
}
use of org.eclipse.egit.github.core.User in project hubroid by EddieRingle.
the class GitHubApiService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) {
return;
}
mGitHubClient = new GitHubClient(sApiHostname, sApiPort, sApiScheme);
mGitHubClient.setUserAgent(USER_AGENT);
if (!intent.getBooleanExtra(ARG_ANONYMOUS, false)) {
if (intent.hasExtra(ARG_OAUTH_TOKEN)) {
mGitHubClient.setOAuth2Token(intent.getStringExtra(ARG_OAUTH_TOKEN));
} else if (intent.hasExtra(ARG_BASIC_USERNAME) && intent.hasExtra(ARG_BASIC_PASSWORD)) {
mGitHubClient.setCredentials(intent.getStringExtra(ARG_BASIC_USERNAME), intent.getStringExtra(ARG_BASIC_PASSWORD));
} else if (intent.hasExtra(ARG_ACCOUNT) && intent.getParcelableExtra(ARG_ACCOUNT) != null) {
final Account account = intent.getParcelableExtra(ARG_ACCOUNT);
try {
final String oauthToken = new OAuthUserProvider().getOAuthResponse(this, account).access_token;
if (oauthToken != null) {
mGitHubClient.setOAuth2Token(oauthToken);
}
} catch (IOException e) {
e.printStackTrace();
} catch (AccountsException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
if (intent.getAction().equals(ACTION_GET_URI)) {
final GitHubRequest request = new GitHubRequest();
request.setUri(intent.getData().toString());
GitHubResponse response;
try {
response = mGitHubClient.get(request);
} catch (IOException e) {
response = null;
e.printStackTrace();
}
final Intent resultIntent = new Intent(ACTION_GET_URI, intent.getData());
if (response != null) {
resultIntent.putExtra(EXTRA_HAS_NEXT, response.getNext() != null);
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(response.getBody()));
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_EVENTS_LIST_USER_PUBLIC)) {
final EventService es = new EventService(mGitHubClient);
ArrayList<Event> result = null;
PageIterator<Event> iterator = null;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
if (intent.hasExtra(PARAM_LOGIN)) {
iterator = es.pageUserEvents(intent.getStringExtra(PARAM_LOGIN), true, startPage, REQUEST_PAGE_SIZE);
}
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Event>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_USER_PUBLIC);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_EVENTS_LIST_USER_RECEIVED)) {
final EventService es = new EventService(mGitHubClient);
ArrayList<Event> result = null;
PageIterator<Event> iterator = null;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
if (intent.hasExtra(PARAM_LOGIN)) {
iterator = es.pageUserReceivedEvents(intent.getStringExtra(PARAM_LOGIN), false, startPage, REQUEST_PAGE_SIZE);
}
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Event>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_USER_RECEIVED);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_EVENTS_LIST_TIMELINE)) {
final EventService es = new EventService(mGitHubClient);
ArrayList<Event> result = null;
PageIterator<Event> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
iterator = es.pagePublicEvents(startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Event>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_TIMELINE);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_ISSUES_LIST_SELF)) {
final IssueService is = new IssueService(mGitHubClient);
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
ArrayList<RepositoryIssue> result = null;
PageIterator<RepositoryIssue> iterator;
HashMap<String, String> params = new HashMap<String, String>();
if (intent.hasExtra(PARAM_FILTER)) {
params.put("filter", intent.getStringExtra(PARAM_FILTER));
}
if (intent.hasExtra(PARAM_STATE)) {
params.put("state", intent.getStringExtra(PARAM_STATE));
}
if (intent.hasExtra(PARAM_LABELS)) {
params.put("labels", intent.getStringExtra(PARAM_LABELS));
}
if (intent.hasExtra(PARAM_SORT)) {
params.put("sort", intent.getStringExtra(PARAM_SORT));
}
if (intent.hasExtra(PARAM_DIRECTION)) {
params.put("direction", intent.getStringExtra(PARAM_DIRECTION));
}
if (intent.hasExtra(PARAM_SINCE)) {
params.put("since", intent.getStringExtra(PARAM_SINCE));
}
iterator = is.pageIssues(params, startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<RepositoryIssue>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_ISSUES_LIST_SELF);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_ORGS_SELF_MEMBERSHIPS)) {
final OrganizationService os = new OrganizationService(mGitHubClient);
List<User> result;
try {
result = os.getOrganizations();
} catch (IOException e) {
result = null;
e.printStackTrace();
}
final Intent resultIntent = new Intent(ACTION_ORGS_SELF_MEMBERSHIPS);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_REPOS_GET_REPO)) {
final RepositoryService rs = new RepositoryService(mGitHubClient);
Repository result;
try {
result = rs.getRepository(intent.getStringExtra(PARAM_REPO_OWNER), intent.getStringExtra(PARAM_REPO_NAME));
} catch (IOException e) {
result = null;
e.printStackTrace();
}
final Intent resultIntent = new Intent(ACTION_REPOS_GET_REPO);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_REPOS_LIST_ORG_OWNED)) {
final RepositoryService rs = new RepositoryService(mGitHubClient);
ArrayList<Repository> result = null;
PageIterator<Repository> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
iterator = rs.pageOrgRepositories(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Repository>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_REPOS_LIST_ORG_OWNED);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_REPOS_LIST_SELF_OWNED)) {
final RepositoryService rs = new RepositoryService(mGitHubClient);
ArrayList<Repository> result = null;
PageIterator<Repository> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
Map<String, String> filter = new HashMap<String, String>();
filter.put("type", "owner");
filter.put("sort", "pushed");
iterator = rs.pageRepositories(filter, startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Repository>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_REPOS_LIST_SELF_OWNED);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_REPOS_LIST_USER_OWNED)) {
final RepositoryService rs = new RepositoryService(mGitHubClient);
ArrayList<Repository> result = null;
PageIterator<Repository> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
iterator = rs.pageRepositories(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Repository>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_REPOS_LIST_USER_OWNED);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_REPOS_LIST_USER_WATCHED)) {
final WatcherService ws = new WatcherService(mGitHubClient);
ArrayList<Repository> result = null;
PageIterator<Repository> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
try {
iterator = ws.pageWatched(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
} catch (IOException e) {
iterator = null;
}
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<Repository>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_REPOS_LIST_USER_WATCHED);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_USERS_GET_USER)) {
final UserService us = new UserService(mGitHubClient);
User result;
try {
result = us.getUser(intent.getStringExtra(PARAM_LOGIN));
} catch (IOException e) {
result = null;
e.printStackTrace();
}
final Intent resultIntent = new Intent(ACTION_USERS_GET_USER);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_USERS_LIST_FOLLOWERS)) {
final UserService us = new UserService(mGitHubClient);
ArrayList<User> result = null;
PageIterator<User> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
iterator = us.pageFollowers(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<User>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_USERS_LIST_FOLLOWERS);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
} else if (intent.getAction().equals(ACTION_USERS_LIST_FOLLOWING)) {
final UserService us = new UserService(mGitHubClient);
ArrayList<User> result = null;
PageIterator<User> iterator;
final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
iterator = us.pageFollowing(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
if (iterator != null && iterator.hasNext()) {
result = new ArrayList<User>();
result.addAll(iterator.next());
}
final Intent resultIntent = new Intent(ACTION_USERS_LIST_FOLLOWING);
if (result != null) {
resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
} else {
resultIntent.putExtra(EXTRA_ERROR, true);
}
sendBroadcast(resultIntent);
}
}
use of org.eclipse.egit.github.core.User in project hubroid by EddieRingle.
the class AccountSelectActivity method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle, R.layout.account_select_activity);
mProgress = (ProgressBar) findViewById(R.id.progress);
mContent = (RelativeLayout) findViewById(R.id.content);
ListView listView = (ListView) findViewById(R.id.lv_userselect_users);
TextView msgView = (TextView) findViewById(R.id.tv_userselect_msg);
Button noChoiceBtn = (Button) findViewById(R.id.btn_userselect_nochoice);
mAccountManager = AccountManager.get(getContext());
if (mCurrentAccount == null) {
noChoiceBtn.setText(R.string.userselect_justbrowsing);
}
final Account[] accounts = mAccountManager.getAccountsByType(AuthConstants.GITHUB_ACCOUNT_TYPE);
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(getContext(), R.layout.account_select_listitem);
for (Account a : accounts) {
listAdapter.add(a.name);
}
noChoiceBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPrefsEditor.remove(HubroidConstants.PREF_CURRENT_USER_LOGIN);
mPrefsEditor.remove(HubroidConstants.PREF_CURRENT_USER);
mPrefsEditor.remove(HubroidConstants.PREF_CURRENT_CONTEXT_LOGIN);
mPrefsEditor.commit();
final Intent intent = new Intent(AccountSelectActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
});
if (!listAdapter.isEmpty()) {
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
mContent.setVisibility(GONE);
mProgress.setVisibility(VISIBLE);
new RoboAsyncTask<Boolean>(AccountSelectActivity.this) {
public Boolean call() throws Exception {
mCurrentAccount = accounts[position];
mGitHubClient = null;
UserService service = new UserService(getGHClient());
User user = service.getUser();
if (user != null) {
mPrefsEditor.putString(HubroidConstants.PREF_CURRENT_USER_LOGIN, user.getLogin());
mPrefsEditor.putString(HubroidConstants.PREF_CURRENT_USER, GsonUtils.toJson(user));
mPrefsEditor.commit();
return true;
}
return false;
}
@Override
public void onSuccess(Boolean authSuccess) {
final Intent intent = new Intent(AccountSelectActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
@Override
protected void onFinally() throws RuntimeException {
mProgress.setVisibility(GONE);
mContent.setVisibility(VISIBLE);
super.onFinally();
}
}.execute();
}
});
listView.setAdapter(listAdapter);
}
}
use of org.eclipse.egit.github.core.User in project hubroid by EddieRingle.
the class GitHubAuthenticatorActivity method handleLogin.
/**
* Handles onClick event on the Submit button. Sends username/mPassword to the server for
* authentication. <p/> Specified by android:onClick="handleLogin" in the layout xml
*/
public void handleLogin(View view) {
if (mAuthenticationTask != null) {
return;
}
if (mRequestNewAccount) {
mLogin = mLoginText.getText().toString();
}
mPassword = mPasswordText.getText().toString();
showProgress();
mAuthenticationTask = new RoboAsyncTask<Boolean>(this) {
public Boolean call() throws Exception {
GitHubClient client = new GitHubClient();
client.setCredentials(mLogin, mPassword);
client.setUserAgent(USER_AGENT_STRING);
UserService service = new UserService(client);
User user = service.getUser();
if (user != null) {
/* Make sure we're using the user's username, rather than email */
mLogin = user.getLogin();
return true;
}
return false;
}
@Override
protected void onException(Exception e) throws RuntimeException {
Throwable cause = e.getCause() != null ? e.getCause() : e;
String message;
/* A 401 is returned as an IOException with this message */
if ("Received authentication challenge is null".equals(cause.getMessage())) {
message = getResources().getString(R.string.auth_message_bad_credentials);
} else {
message = cause.getMessage();
}
ToastUtil.toastOnUiThread(GitHubAuthenticatorActivity.this, message);
}
@Override
public void onSuccess(Boolean authSuccess) {
onAuthenticationResult(authSuccess);
}
@Override
protected void onFinally() throws RuntimeException {
hideProgress();
mAuthenticationTask = null;
}
};
mAuthenticationTask.execute();
}
Aggregations