Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper retrofit2 async execution #6

Open
wants to merge 4 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Use proper retrofit2 async execution

  • Loading branch information
linakis committed Jan 8, 2018
commit 41f8b4964b13bb9be1aa6270ad7777fde1bc9c44
@@ -16,7 +16,6 @@
package com.github.tony19.loggly;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
@@ -40,15 +39,6 @@
@POST("inputs/{token}")
Call<LogglyResponse> log(@Path("token") String token, @Header("X-LOGGLY-TAG") String tags, @Body String message);

/**
* Posts a single log event to Loggly's REST endpoint
* @param token Loggly customer token
* @param tags CSV of tags
* @param message log event to be posted
* @param callback callback to be invoked on completion of the post
*/
@POST("inputs/{token}")
Call<Void> log(@Path("token") String token, @Header("X-LOGGLY-TAG") String tags, @Body String message, Callback<LogglyResponse> callback);

/**
* Posts several log events at once to Loggly's bulk REST endpoint
@@ -62,15 +52,4 @@
@POST("bulk/{token}")
Call<LogglyResponse> logBulk(@Path("token") String token, @Header("X-LOGGLY-TAG") String tags, @Body String messages);

/**
* Posts several log events at once to Loggly's bulk REST endpoint
* @param token Loggly customer token
* @param tags CSV of tags
* @param messages log event messages, each delimited by new-line
* The text is parsed for a log event in each line.
* e.g., "Hello\nWorld" would create two log events.
* @param callback callback to be invoked on completion of the post
*/
@POST("bulk/{token}")
Call<Void> logBulk(@Path("token") String token, @Header("X-LOGGLY-TAG") String tags, @Body String messages, Callback<LogglyResponse> callback);
}
@@ -15,14 +15,14 @@
*/
package com.github.tony19.loggly;

import java.util.Arrays;
import java.util.Collection;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.util.Arrays;
import java.util.Collection;

/**
* Loggly client
*
@@ -116,20 +116,18 @@ public boolean log(String message) {
public void log(String message, final Callback callback) {
if (message == null) return;

loggly.log(token,
tags,
message,
new retrofit2.Callback<LogglyResponse>() {
@Override
public void onResponse(Call<LogglyResponse> call, Response<LogglyResponse> response) {
callback.success();
}

@Override
public void onFailure(Call<LogglyResponse> call, Throwable throwable) {
callback.failure(throwable.getMessage());
}
});
Call call = loggly.log(token, tags, message);
call.enqueue(new retrofit2.Callback<LogglyResponse>() {
@Override
public void onResponse(Call<LogglyResponse> call, Response<LogglyResponse> response) {
callback.success();
}

@Override
public void onFailure(Call<LogglyResponse> call, Throwable throwable) {
callback.failure(throwable.getMessage());
}
});
}

/**
@@ -171,23 +169,23 @@ public boolean logBulk(Collection<String> messages) {
public void logBulk(Collection<String> messages, final Callback callback) {
if (messages == null) return;



String parcel = joinStrings(messages);
if (parcel.isEmpty()) return;

loggly.logBulk(token,
tags,
parcel,
new retrofit2.Callback<LogglyResponse>() {
@Override
public void onResponse(Call<LogglyResponse> call, Response<LogglyResponse> response) {
callback.success();
}

@Override
public void onFailure(Call<LogglyResponse> call, Throwable throwable) {
callback.failure(throwable.getMessage());
}
});
Call call = loggly.logBulk(token, tags, parcel);
call.enqueue(new retrofit2.Callback<LogglyResponse>() {
@Override
public void onResponse(Call<LogglyResponse> call, Response<LogglyResponse> response) {
callback.success();
}

@Override
public void onFailure(Call<LogglyResponse> call, Throwable throwable) {
callback.failure(throwable.getMessage());
}
});
}

/**
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.