/*
*
* * Copyright 2015 Van Shu
* *
* * 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.mobimvp.cliques.service;
import com.mobimvp.cliques.AppData;
import com.mobimvp.cliques.util.PrefUtils;
import com.mobimvp.cliques.util.StringUtils;
import java.util.HashMap;
/**
* Created by Van on 2014/11/10.
*/
public class DribbbleApi {
public static final String CLIENT_ID = "875e67bf1cd7b04e1b911a78d3051711da8922a19eff4f9e11ea98ffda6a4c35";
public static final String CLIENT_SECRET = "e8a1813ab9cf3a5c12f1e010781ae369095b225241a417887bcac3cb4bf75ca7";
public static final String BASE_URL = "https://api.dribbble.com/v1";
public static final String OAUTH_AUTHORIZE = "https://dribbble.com/oauth/authorize";
public static final String OAUTH_TOKEN = "https://dribbble.com/oauth/token";
public static final String AUTHENTICATED_USER = BASE_URL + "/user";
public static final String AUTHENTICATED_USER_SHOTS = BASE_URL+"/user/shots";
public static final String AUTHENTICATED_USER_BUCKETS = BASE_URL+"/user/buckets";
public static final String AUTHENTICATED_USER_FOLLOWERS = BASE_URL+"/user/followers";
public static final String AUTHENTICATED_USER_FOLLOWLING = BASE_URL+"/user/following";
public static final String AUTHENTICATED_USER_TEAMS = BASE_URL+"/user/teams";
public static final String AUTHENTICATED_USER_PROJECTS = BASE_URL+"/user/projects";
public static final String ONE_USER=BASE_URL+"/users/%s";
public static final String ONE_USER_SHOTS=BASE_URL+"/users/%s/shots";
public static final String ONE_USER_BUCKETS=BASE_URL+"/users/%s/buckets";
public static final String ONE_USER_FOLLOWERS=BASE_URL+"/users/%s/followers";
public static final String ONE_USER_FOLLOWING=BASE_URL+"/users/%s/following";
public static final String ONE_USER_TEAMS=BASE_URL+"/users/%s/teams";
public static final String ONE_USER_PROJECTS=BASE_URL+"/users/%s/projects";
public static final String AUTHENTICATED_USER_FOLLOWLING_SHOTS = BASE_URL+"/user/following/shots";
public static final String USER_FOLLOWLING_USER = BASE_URL+"/user/following/";
public static final String SHOTS = BASE_URL + "/shots";
public static final String BUCKET_SHOTS = BASE_URL+"/buckets/%d/shots";
/**
* get Oauth code from server
* @return
*/
public static String getOauthAuthorizeUrl() {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("client_id", CLIENT_ID);
return OAUTH_AUTHORIZE + StringUtils.encodeUrl(parameters);
}
/**
* get Oauth token using authCode*
* @param authCode
* @return
*/
public static String getOauthTokenUrl(String authCode) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("client_id", CLIENT_ID);
parameters.put("client_secret", CLIENT_SECRET);
parameters.put("code", authCode);
return OAUTH_TOKEN + StringUtils.encodeUrl(parameters);
}
public static String getOneUser(String userId){
HashMap<String,String> parameters=new HashMap<>();
parameters.put("access_token",PrefUtils.getString(AppData.getContext(),PrefUtils.ACCESS_TOKEN));
return String.format(ONE_USER,userId)+StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUser() {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return AUTHENTICATED_USER + StringUtils.encodeUrl(parameters);
}
public static String getOneUserShots(String userId){
HashMap<String,String> parameters=new HashMap<>();
parameters.put("access_token",PrefUtils.getString(AppData.getContext(),PrefUtils.ACCESS_TOKEN));
return String.format(ONE_USER_SHOTS,userId)+StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUserShots(){
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return AUTHENTICATED_USER_SHOTS + StringUtils.encodeUrl(parameters);
}
public static String getoneUserBuckets(String userId) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return String.format(ONE_USER_BUCKETS,userId) + StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUserBuckets() {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return AUTHENTICATED_USER_BUCKETS + StringUtils.encodeUrl(parameters);
}
public static String getOneUserFollowing(String userId) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return String.format(ONE_USER_FOLLOWING,userId) + StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUserFollowing() {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return AUTHENTICATED_USER_FOLLOWLING + StringUtils.encodeUrl(parameters);
}
public static String getOneUserFollowers(String userId) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return String.format(ONE_USER_FOLLOWERS,userId) + StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUserFollowers() {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return AUTHENTICATED_USER_FOLLOWERS + StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUserFollowingShots() {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return AUTHENTICATED_USER_FOLLOWLING_SHOTS + StringUtils.encodeUrl(parameters);
}
public static String getAuthenticatedUserFollowingAnotherUser(String user) {
return USER_FOLLOWLING_USER + user;
}
public static String getOneUserFollowingAnotherUser(String oneUser, String anotherUser) {
return "/users/" + oneUser + "/following/" + anotherUser;
}
/**
* PUT Follow a user
*
* @param userId
* @return
*/
public static String getFollowUser(String userId) {
return "/users/" + userId + "/follow";
}
/**
* Unfollow a user
* DELETE method
*
* @param userId
* @return
*/
public static String getUnfollowUser(String userId) {
return "/users/" + userId + "/follow";
}
public static String getShots(int page,String sort) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
parameters.put("page",String.valueOf(page));
parameters.put("sort",sort);
return SHOTS + StringUtils.encodeUrl(parameters);
}
public static String getBucketShots(int bucketId){
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_token", PrefUtils.getString(AppData.getContext(), PrefUtils.ACCESS_TOKEN));
return String.format(BUCKET_SHOTS,bucketId) + StringUtils.encodeUrl(parameters);
}
}