Android Open Source - xing-android-sdk Xing Api Client






From Project

Back to project page xing-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project xing-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.hdodenhof.xingapi;
//w  ww .j a va  2  s  .c  o  m
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import com.squareup.okhttp.OkHttpClient;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.XingApi;
import org.scribe.model.Token;
import org.scribe.oauth.OAuthService;

import android.content.Context;

import java.util.concurrent.TimeUnit;

import de.hdodenhof.xingapi.internal.AuthHandler;
import de.hdodenhof.xingapi.internal.OAuthConstants;
import de.hdodenhof.xingapi.internal.communication.SigningOkClient;
import de.hdodenhof.xingapi.models.ActivityObject;
import de.hdodenhof.xingapi.typeadapter.ActivityObjectTypeAdapter;
import retrofit.RestAdapter;
import retrofit.converter.GsonConverter;

public class XingApiClient {

    public interface AuthenticationCallback extends AuthHandler.Callback {
    }

    public interface Logger {
        public void log(String message);
    }

    private static final String API_ENDPOINT = "https://api.xing.com";
    private static final String API_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
    private static final int HTTP_CONNECT_TIMEOUT_SECONDS = 5;
    private static final int HTTP_READ_TIMEOUT_SECONDS = 10;

    private final OAuthService mOAuthService;
    private final SigningOkClient mClient;
    private final RestAdapter mRestAdapter;
    private final Logger mLogger;

    private ContactsAPI mContactsAPI;
    private MessagesAPI mMessagesAPI;
    private NetworkFeedAPI mNetworkFeedAPI;
    private ProfileVisitsAPI mProfileVisitsAPI;
    private UserProfilesAPI mUserProfilesAPI;

    public XingApiClient(String consumerKey, String consumerSecret, Logger logger) {
        mOAuthService = new ServiceBuilder()
                .provider(XingApi.class)
                .apiKey(consumerKey)
                .apiSecret(consumerSecret)
                .callback(OAuthConstants.CALLBACK_URL)
                .build();

        mClient = buildClient(mOAuthService);

        mRestAdapter = new RestAdapter.Builder()
                .setEndpoint(API_ENDPOINT)
                .setClient(mClient)
                .setConverter(buildGsonConverter())
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .build();

        mLogger = logger;
    }

    private SigningOkClient buildClient(OAuthService oAuthService) {
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setConnectTimeout(HTTP_CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
        okHttpClient.setReadTimeout(HTTP_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS);
        return new SigningOkClient(okHttpClient, oAuthService);
    }

    private GsonConverter buildGsonConverter() {
        Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .setDateFormat(API_DATE_FORMAT)
                .registerTypeAdapter(ActivityObject.class, new ActivityObjectTypeAdapter())
                .create();
        return new GsonConverter(gson);
    }

    public void setCredentials(String accessToken, String secret) {
        mClient.setAccessToken(new Token(accessToken, secret));
    }

    public void requestAuthentication(Context context, AuthenticationCallback callback) {
        AuthHandler authHandler = new AuthHandler(mOAuthService);
        authHandler.authenticate(context, callback);
    }

    public ContactsAPI getContactsAPI() {
        if (mContactsAPI == null) {
            mContactsAPI = new ContactsAPI(mRestAdapter);
        }
        return mContactsAPI;
    }

    public MessagesAPI getMessagesAPI() {
        if (mMessagesAPI == null) {
            mMessagesAPI = new MessagesAPI(mRestAdapter);
        }
        return mMessagesAPI;
    }

    public NetworkFeedAPI getNetworkFeedAPI() {
        if (mNetworkFeedAPI == null) {
            mNetworkFeedAPI = new NetworkFeedAPI(mRestAdapter);
        }
        return mNetworkFeedAPI;
    }

    public ProfileVisitsAPI getProfileVisitsAPI() {
        if (mProfileVisitsAPI == null) {
            mProfileVisitsAPI = new ProfileVisitsAPI(mRestAdapter);
        }
        return mProfileVisitsAPI;
    }

    public UserProfilesAPI getUserProfilesAPI() {
        if (mUserProfilesAPI == null) {
            mUserProfilesAPI = new UserProfilesAPI(mRestAdapter);
        }
        return mUserProfilesAPI;
    }
}




Java Source Code List

de.hdodenhof.xingapi.BaseAPI.java
de.hdodenhof.xingapi.ContactsAPI.java
de.hdodenhof.xingapi.MessagesAPI.java
de.hdodenhof.xingapi.NetworkFeedAPI.java
de.hdodenhof.xingapi.ProfileVisitsAPI.java
de.hdodenhof.xingapi.UserProfilesAPI.java
de.hdodenhof.xingapi.XingApiClient.java
de.hdodenhof.xingapi.enums.ActivityAction.java
de.hdodenhof.xingapi.enums.ActivityAggregator.java
de.hdodenhof.xingapi.enums.ActivityObjectType.java
de.hdodenhof.xingapi.enums.ActivityVerb.java
de.hdodenhof.xingapi.enums.Badge.java
de.hdodenhof.xingapi.enums.CarrerLevel.java
de.hdodenhof.xingapi.enums.CompanyIndustry.java
de.hdodenhof.xingapi.enums.CompanySize.java
de.hdodenhof.xingapi.enums.EmploymentStatus.java
de.hdodenhof.xingapi.enums.ErrorName.java
de.hdodenhof.xingapi.enums.FormOfEmployment.java
de.hdodenhof.xingapi.enums.IMAccount.java
de.hdodenhof.xingapi.enums.LanguageSkill.java
de.hdodenhof.xingapi.enums.Language.java
de.hdodenhof.xingapi.enums.PremiumService.java
de.hdodenhof.xingapi.enums.Reason.java
de.hdodenhof.xingapi.enums.UserField.java
de.hdodenhof.xingapi.enums.WebProfile.java
de.hdodenhof.xingapi.exceptions.ApiException.java
de.hdodenhof.xingapi.exceptions.BaseException.java
de.hdodenhof.xingapi.exceptions.ConversionException.java
de.hdodenhof.xingapi.exceptions.NetworkException.java
de.hdodenhof.xingapi.internal.AuthHandler.java
de.hdodenhof.xingapi.internal.OAuthConstants.java
de.hdodenhof.xingapi.internal.communication.ErrorHandler.java
de.hdodenhof.xingapi.internal.communication.SigningOkClient.java
de.hdodenhof.xingapi.internal.communication.XingApiInterface.java
de.hdodenhof.xingapi.internal.response.ActivityWrapper.java
de.hdodenhof.xingapi.internal.response.CommentsWrapper.java
de.hdodenhof.xingapi.internal.response.ContactsWrapper.java
de.hdodenhof.xingapi.internal.response.ConversationWrapper.java
de.hdodenhof.xingapi.internal.response.ConversationsWrapper.java
de.hdodenhof.xingapi.internal.response.IdCardWrapper.java
de.hdodenhof.xingapi.internal.response.LikesWrapper.java
de.hdodenhof.xingapi.internal.response.MessageWrapper.java
de.hdodenhof.xingapi.internal.response.MessagesWrapper.java
de.hdodenhof.xingapi.internal.response.NetworkActivityWrapper.java
de.hdodenhof.xingapi.internal.response.ProfileMessageWrapper.java
de.hdodenhof.xingapi.internal.response.ResponseWrapper.java
de.hdodenhof.xingapi.internal.response.ResultWrapper.java
de.hdodenhof.xingapi.internal.response.SharedContactsWrapper.java
de.hdodenhof.xingapi.internal.response.TagsWrapper.java
de.hdodenhof.xingapi.internal.response.UserWrapper.java
de.hdodenhof.xingapi.internal.response.VisitsWrapper.java
de.hdodenhof.xingapi.internal.util.HTTPUtils.java
de.hdodenhof.xingapi.internal.util.URLUtils.java
de.hdodenhof.xingapi.internal.widget.AuthWebDialog.java
de.hdodenhof.xingapi.models.ActivityObject.java
de.hdodenhof.xingapi.models.Address.java
de.hdodenhof.xingapi.models.ApiError.java
de.hdodenhof.xingapi.models.Award.java
de.hdodenhof.xingapi.models.BirthDate.java
de.hdodenhof.xingapi.models.Bookmark.java
de.hdodenhof.xingapi.models.Comment.java
de.hdodenhof.xingapi.models.CompanyProfileUpdate.java
de.hdodenhof.xingapi.models.CompanyProfile.java
de.hdodenhof.xingapi.models.Company.java
de.hdodenhof.xingapi.models.Contacts.java
de.hdodenhof.xingapi.models.Conversation.java
de.hdodenhof.xingapi.models.Conversations.java
de.hdodenhof.xingapi.models.EducationalBackground.java
de.hdodenhof.xingapi.models.ErrorResponse.java
de.hdodenhof.xingapi.models.Event.java
de.hdodenhof.xingapi.models.FindByEmailsResult.java
de.hdodenhof.xingapi.models.Group.java
de.hdodenhof.xingapi.models.IdCard.java
de.hdodenhof.xingapi.models.JobPosting.java
de.hdodenhof.xingapi.models.Message.java
de.hdodenhof.xingapi.models.Messages.java
de.hdodenhof.xingapi.models.MetaComment.java
de.hdodenhof.xingapi.models.MetaLike.java
de.hdodenhof.xingapi.models.NetworkActivity.java
de.hdodenhof.xingapi.models.PhotoUrls.java
de.hdodenhof.xingapi.models.ProfessionalExperience.java
de.hdodenhof.xingapi.models.ProfileMessage.java
de.hdodenhof.xingapi.models.Results.java
de.hdodenhof.xingapi.models.School.java
de.hdodenhof.xingapi.models.Status.java
de.hdodenhof.xingapi.models.Tag.java
de.hdodenhof.xingapi.models.Tags.java
de.hdodenhof.xingapi.models.Thread.java
de.hdodenhof.xingapi.models.TimeZone.java
de.hdodenhof.xingapi.models.User.java
de.hdodenhof.xingapi.models.Visit.java
de.hdodenhof.xingapi.sample.MainActivity.java
de.hdodenhof.xingapi.sample.OAuthFragment.java
de.hdodenhof.xingapi.sample.ProfileFragment.java
de.hdodenhof.xingapi.typeadapter.ActivityObjectTypeAdapter.java