forked from jonan/ForkHub
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from AndreySBer/feature_milestones_api_interface
CRUD milestones
- Loading branch information
Showing
6 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/github/mobile/api/service/MilestoneService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/github/mobile/core/milestone/CreateMilestoneTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
app/src/main/java/com/github/mobile/core/milestone/DeleteMilestoneTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/github/mobile/core/milestone/EditMilestoneTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters