Skip to content

Commit

Permalink
Added Dribbble team API methods & data manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed May 14, 2016
1 parent 84b256a commit 1e8142f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ Call<List<Shot>> getTeamShots(@Path("team") long teamId,
@Query("page") Integer page,
@Query("per_page") Integer pageSize);

@GET("v1/teams/{team}/shots")
Call<List<Shot>> getTeamShots(@Path("team") String teamName,
@Query("page") Integer page,
@Query("per_page") Integer pageSize);

@GET("v1/teams/{team}/members")
Call<List<User>> getTeamMembers(@Path("team") long teamId,
@Query("page") Integer page,
@Query("per_page") Integer pageSize);

@GET("v1/teams/{team}/members")
Call<List<User>> getTeamMembers(@Path("team") String teamName,
@Query("page") Integer page,
@Query("per_page") Integer pageSize);


/* Magic Constants */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2016 Google 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 io.plaidapp.data.api.dribbble;

import android.content.Context;

import java.util.List;

import io.plaidapp.data.PaginatedDataManager;
import io.plaidapp.data.api.dribbble.model.User;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
* Loads the members of a given dribbble team.
*/
public abstract class TeamMembersDataManager extends PaginatedDataManager<List<User>> {

private final String teamName;
private Call teamMembersCall;

public TeamMembersDataManager(Context context, String teamName) {
super(context);
this.teamName = teamName;
}

@Override
public void cancelLoading() {
if (teamMembersCall != null) teamMembersCall.cancel();
}

@Override
protected void loadData(int page) {
teamMembersCall = getDribbbleApi()
.getTeamMembers(teamName, page, DribbbleService.PER_PAGE_DEFAULT);
teamMembersCall.enqueue(new Callback<List<User>>() {

@Override
public void onResponse(Call<List<User>> call, Response<List<User>> response) {
if (response.isSuccessful()) {
loadFinished();
final List<User> teamMembers = response.body();
moreDataAvailable = teamMembers.size() == DribbbleService.PER_PAGE_DEFAULT;
onDataLoaded(teamMembers);
teamMembersCall = null;
} else {
failure();
}
}

@Override
public void onFailure(Call<List<User>> call, Throwable t) {
failure();
}

private void failure() {
loadFinished();
moreDataAvailable = false;
teamMembersCall = null;
}
});
}
}

0 comments on commit 1e8142f

Please sign in to comment.