Android Open Source - inbox-android Test Api






From Project

Back to project page inbox-android.

License

The source code is released under:

MIT License

If you think the Android project inbox-android 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 com.inboxapp.androidsdk.scratchpad.scratchpad_apis;
//  w w w .j  a v a 2s.c  o  m
import android.util.Log;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Path;


/**
 * Created by sylvianguessan on 8/5/14.
 */
public class TestApi {



    public  TestApi()
    {
    }
    static class Contributor {
        String login;
        int contributions;
    }

    public String GET_with_OKHTPP() throws Exception
    {
        String ENDPOINT = "https://raw.github.com/square/okhttp/master/README.md";
        OkHttpClient okHttpClient = new OkHttpClient();
        // Create request for remote resource.
        Request request = new Request.Builder()
                                   .url(ENDPOINT)
                                   .build();
        // Execute the request and retrieve the response.
        Response response = okHttpClient.newCall(request).execute();
        Log.w("Test Api GET_with_OKHTPP()", response.body().string());
        return "GET_with_OKHTPP()";
    }
    public String GET_with_OKHTPP_with_GSON() throws Exception
    {
        String ENDPOINT = "https://api.github.com/repos/square/okhttp/contributors";
        Gson GSON = new Gson();
        TypeToken<List<Contributor>> CONTRIBUTORS_TYPETOKEN = new TypeToken<List<Contributor>>() {};
        long start = System.currentTimeMillis();
        OkHttpClient client = new OkHttpClient();
        Request.Builder requestBuilder = new Request.Builder();
        requestBuilder.url(ENDPOINT);
        requestBuilder.header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36");
        Request request = requestBuilder.build();

       // Deserialize HTTP response to concrete type
        Response response = client.newCall(request).execute();
        //Reader reader = response.body().charStream();   // for some reason was failing

        List<Contributor> contributors = GSON.fromJson(response.body().string(), CONTRIBUTORS_TYPETOKEN.getType());
        long end = System.currentTimeMillis();
        Log.w("Okhttpwithgson Timing", "Time (ms): " + ((end - start)));

        Collections.sort(contributors, new Comparator<Contributor>() {
            @Override
            public int compare(Contributor contributor1, Contributor contributor2) {
                return contributor1.contributions - contributor2.contributions;  //from smallest contribution to greatest
            }
        });
        Log.w("body: ","contributor count"+  contributors.size() + " "+response.body().string());
        for (Contributor contributor : contributors) {
            Log.w("Test GET_with_OKHTPP_with_GSON()", "contributor.login + "+": " + contributor.contributions);
        }
        return "GET_with_OKHTPP_with_GSON()";
    }
    public String GET_with_OKHTPP_with_JackSON() throws Exception
    {
        String ENDPOINT = "https://api.github.com/repos/square/okhttp/contributors";
        Gson GSON = new Gson();
        long start = System.currentTimeMillis();
        OkHttpClient client = new OkHttpClient();

        Request.Builder requestBuilder = new Request.Builder();
        requestBuilder.url(ENDPOINT);
        requestBuilder.header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36");
        Request request = requestBuilder.build();

        // Deserialize HTTP response to concrete type
        Response response = client.newCall(request).execute();
        ObjectMapper mapper = new ObjectMapper();

        List<JacksonContributor> jacksonContributors =
                mapper.readValue(response.body().string(), new TypeReference<List<JacksonContributor>>(){});
        long end = System.currentTimeMillis();
        Log.w("Okhttpwithjackson Timing", "Time (ms): " + ((end - start)));

        // Log.w("body: "," jackson contributor count"+  jacksonContributors.size() + " "+response.body().string());
        Collections.sort(jacksonContributors, new Comparator<JacksonContributor>() {
            @Override
            public int compare(JacksonContributor contributor1, JacksonContributor contributor2) {
                return contributor1.contributions - contributor2.contributions;  //from smallest contribution to greatest
            }
        });

        for (JacksonContributor contributor : jacksonContributors) {
            Log.w("Test GET_with_OKHTPP_with_JackSON()", "contributor.login + "+": " + contributor.contributions);
        }
        return "GET_with_OKHTPP_with_JackSON()";
    }

    interface GitHub {
        @GET("/repos/{owner}/{repo}/contributors")
        List<Contributor> contributors(
                @Path("owner") String owner,
                @Path("repo") String repo
        );
    }
    public String GET_with_RETROFIT()
    {
        String API_URL = "https://api.github.com";
        long start = System.currentTimeMillis();
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(API_URL)
                .build();
        // Create an instance of our GitHub API interface.
        GitHub github = restAdapter.create(GitHub.class);
        // Fetch and print a list of the contributors to this library.
        List<Contributor> contributors = github.contributors("square", "retrofit");
        long end = System.currentTimeMillis();
        Log.w("Retrofit Timing", "Time  (ms): " + ((end - start)));

        for (Contributor contributor : contributors) {
            Log.w("GET_with_RETROFIT()", contributor.login + " (" + contributor.contributions + ")");
        }

        return "GET_with_RETROFIT()";



    }
    public void GET_with_AndroidNative()
    {

    }

    public void GET_with_AsyncHTTP()
    {

    }

    public void POST_with_RETROFIT()
    {

    }
    public void POST_with_OKHTPP()
    {

    }
    public void POST_with_AndroidNative()
    {

    }

    public void POST_with_AsyncHTTP()
    {

    }




}




Java Source Code List

com.inboxapp.androidapplication.MainActivity.java
com.inboxapp.androidsdk.apis.InboxAppClient.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTaskCallback.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTaskQueue.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxTaskID.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.CreateCustomTagTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.CreateDraftWithBodyTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.SendDraftWithBodyTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.SendDraftWithIDTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.UpdateThreadTagsTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.base.InboxAppTask.java
com.inboxapp.androidsdk.json_objects.collection_objects.ContactList.java
com.inboxapp.androidsdk.json_objects.collection_objects.DraftList.java
com.inboxapp.androidsdk.json_objects.collection_objects.FileList.java
com.inboxapp.androidsdk.json_objects.collection_objects.MessageList.java
com.inboxapp.androidsdk.json_objects.collection_objects.NameSpaceList.java
com.inboxapp.androidsdk.json_objects.collection_objects.ParticipantList.java
com.inboxapp.androidsdk.json_objects.collection_objects.TagList.java
com.inboxapp.androidsdk.json_objects.collection_objects.ThreadList.java
com.inboxapp.androidsdk.json_objects.single_objects.Contact.java
com.inboxapp.androidsdk.json_objects.single_objects.Draft.java
com.inboxapp.androidsdk.json_objects.single_objects.File.java
com.inboxapp.androidsdk.json_objects.single_objects.Message.java
com.inboxapp.androidsdk.json_objects.single_objects.Namespace.java
com.inboxapp.androidsdk.json_objects.single_objects.Participant.java
com.inboxapp.androidsdk.json_objects.single_objects.Tag.java
com.inboxapp.androidsdk.json_objects.single_objects.Thread.java
com.inboxapp.androidsdk.json_objects.single_objects.base.InboxAppSingleObject.java
com.inboxapp.androidsdk.json_objects.single_objects.body_objects.DraftID.java
com.inboxapp.androidsdk.json_objects.single_objects.body_objects.TagEdit.java
com.inboxapp.androidsdk.json_objects.single_objects.body_objects.TagName.java
com.inboxapp.androidsdk.sample_application.SampleArrayAdapter.java
com.inboxapp.androidsdk.sample_application.SampleDetailsActivity.java
com.inboxapp.androidsdk.sample_application.SampleMenuActivity.java
com.inboxapp.androidsdk.scratchpad.Scratchpad_MainActivity.java
com.inboxapp.androidsdk.scratchpad.scratchpad_apis.JacksonContributor.java
com.inboxapp.androidsdk.scratchpad.scratchpad_apis.TestApi.java
com.inboxapp.androidsdk.utils.InboxAppStringUtils.java