Skip to content

Commit

Permalink
Merge pull request #46 from AndreySBer/feature_milestones_api_interface
Browse files Browse the repository at this point in the history
CRUD milestones
  • Loading branch information
phansier authored Dec 17, 2017
2 parents 970e2d0 + 095bbf9 commit 25634e3
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/github/mobile/ServicesModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ MilestoneService milestoneService(GitHubClient client) {
return new MilestoneService(client);
}

@Provides
com.github.mobile.api.service.MilestoneService milestoneService(Retrofit retrofit) {
return retrofit.create(com.github.mobile.api.service.MilestoneService.class);
}

@Provides
LabelService labelService(GitHubClient client) {
return new LabelService(client);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2016 Jon Ander Peñalba
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.api.service;

import com.github.mobile.api.model.Issue;
import com.github.mobile.api.model.Milestone;
import java.util.List;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.PATCH;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface MilestoneService {
@Headers("Accept: application/vnd.github.v3+json")
@GET("repos/{owner}/{repo}/milestones/{number}")
Call<Milestone> getMilestone(
@Path("owner") String owner,
@Path("repo") String repo,
@Path("number") long number);

@Headers("Accept: application/vnd.github.v3+json")
@GET("repos/{owner}/{repo}/milestones")
Call<List<Milestone>> getMilestones(
@Path("owner") String owner,
@Path("repo") String repo);

@Headers("Accept: application/vnd.github.squirrel-girl-preview")
@GET("repos/{owner}/{repo}/issues")
Call<List<Issue>> getIssues(
@Path("owner") String owner,
@Path("repo") String repo,
@Query("milestone") long milestone);

@Headers("Accept: application/vnd.github.v3+json")
@POST("repos/{owner}/{repo}/milestones")
Call<Milestone> createMilestone (
@Path("owner") String owner,
@Path("repo") String repo,
@Body Milestone milestone);

@Headers("Accept: application/vnd.github.v3+json")
@PATCH("repos/{owner}/{repo}/milestones/{number}")
Call<Milestone> editMilestone (
@Path("owner") String owner,
@Path("repo") String repo,
@Path("number") long number,
@Body Milestone milestone);

@Headers("Accept: application/vnd.github.v3+json")
@DELETE("repos/{owner}/{repo}/milestones/{number}")
Call<Milestone> deleteMilestone(
@Path("owner") String owner,
@Path("repo") String repo,
@Path("number") long number);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.core.milestone;

import android.accounts.Account;
import android.app.Activity;
import android.util.Log;

import com.github.mobile.R;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.api.service.MilestoneService;
import com.github.mobile.ui.ProgressDialogTask;
import com.github.mobile.util.ToastUtils;
import com.google.inject.Inject;

public class CreateMilestoneTask extends ProgressDialogTask<Milestone> {
private static final String TAG = "CreateMilestoneTask";

@Inject
private MilestoneService service;

private final String owner;
private final String repo;
private final Milestone milestone;

/**
* Create task to create an {@link Milestone}
*
* @param activity
* @param owner
* @param repo
* @param milestone
*/
public CreateMilestoneTask(final Activity activity,
final String owner,
final String repo,
final Milestone milestone) {
super(activity);
this.owner = owner;
this.repo = repo;
this.milestone = milestone;
}

/**
* Create milestone
*
* @return this task
*/
public CreateMilestoneTask create() {
showIndeterminate(R.string.creating_milestone);

execute();
return this;
}

@Override
public Milestone run(Account account) throws Exception {
return service.createMilestone(owner, repo, milestone).execute().body();
}

@Override
protected void onException(Exception e) throws RuntimeException {
super.onException(e);

Log.e(TAG, "Exception creating milestone", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.core.milestone;

import android.accounts.Account;
import android.app.Activity;
import android.util.Log;

import com.github.mobile.R;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.api.service.MilestoneService;
import com.github.mobile.ui.ProgressDialogTask;
import com.github.mobile.util.ToastUtils;
import com.google.inject.Inject;

public class DeleteMilestoneTask extends ProgressDialogTask<Milestone> {
private static final String TAG = "DeleteMilestoneTask";

@Inject
private MilestoneService service;

private final String owner;
private final String repo;
private final Milestone milestone;

/**
* Create task to delete an {@link Milestone}
*
* @param activity
* @param owner
* @param repo
* @param milestone
*/
public DeleteMilestoneTask(final Activity activity,
final String owner,
final String repo,
final Milestone milestone) {
super(activity);
this.owner = owner;
this.repo = repo;
this.milestone = milestone;
}

/**
* Delete milestone
*
* @return this task
*/
public DeleteMilestoneTask create() {
showIndeterminate(R.string.deleting_milestone);

execute();
return this;
}

@Override
public Milestone run(Account account) throws Exception {
service.deleteMilestone(owner, repo, milestone.number).execute();
return milestone;
}

@Override
protected void onException(Exception e) throws RuntimeException {
super.onException(e);

Log.e(TAG, "Exception deleting milestone", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.core.milestone;

import android.accounts.Account;
import android.app.Activity;
import android.util.Log;

import com.github.mobile.R;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.api.service.MilestoneService;
import com.github.mobile.ui.ProgressDialogTask;
import com.github.mobile.util.ToastUtils;
import com.google.inject.Inject;

public class EditMilestoneTask extends ProgressDialogTask<Milestone> {
private static final String TAG = "EditMilestoneTask";

@Inject
private MilestoneService service;

private final String owner;
private final String repo;
private final Milestone milestone;

/**
* Create task to edit an {@link Milestone}
*
* @param activity
* @param owner
* @param repo
* @param milestone
*/
public EditMilestoneTask(final Activity activity,
final String owner,
final String repo,
final Milestone milestone) {
super(activity);
this.owner = owner;
this.repo = repo;
this.milestone = milestone;
}

/**
* Edit milestone
*
* @return this task
*/
public EditMilestoneTask create() {
showIndeterminate(R.string.updating_milestone);

execute();
return this;
}

@Override
public Milestone run(Account account) throws Exception {
return service.editMilestone(owner, repo, milestone.number, milestone).execute().body();
}

@Override
protected void onException(Exception e) throws RuntimeException {
super.onException(e);

Log.e(TAG, "Exception editing milestone", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
<string name="reopening_issue">Reopening Issue…</string>
<string name="avatar">Avatar</string>
<string name="creating_issue">Creating Issue…</string>
<string name="creating_milestone">Creating Milestone…</string>
<string name="prefix_created">created\u0020</string>
<string name="prefix_updated">updated\u0020</string>
<string name="prefix_opened">opened\u0020</string>
Expand Down Expand Up @@ -311,6 +312,7 @@
<string name="navigate_to">Navigate to…</string>
<string name="navigate_to_user">Navigate to %s</string>
<string name="contributions">%d commits</string>
<string name="deleting_milestone">Deleting milestone…</string>

<!-- Tab titles, should be as short as possible -->
<string name="tab_repositories">repositories</string>
Expand Down

0 comments on commit 25634e3

Please sign in to comment.