Created
September 19, 2014 05:35
-
-
Save moltak/d413bab3022440361ecb to your computer and use it in GitHub Desktop.
retrofit builder and request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrofit adapter builder | |
* Created by moltak on 2014. 7. 9.. | |
*/ | |
public class LMNetworkBuilder { | |
public static RestAdapter getAdapter() { | |
return getBuilder().build(); | |
} | |
public static RestAdapter.Builder getBuilder() { | |
RestAdapter.Builder builder = new RestAdapter.Builder() | |
.setEndpoint("http://api.limostaging.net/v1/"); | |
if(BuildConfig.DEBUG) { | |
builder.setLogLevel(RestAdapter.LogLevel.FULL); | |
} | |
return builder; | |
} | |
} | |
/** | |
* request object | |
* Created by moltak on 2014. 9. 19.. | |
* url: http://api.limostaging.net/v1/driver_notices/1 | |
* | |
* result: | |
* { | |
"id": 1, | |
"country_id": 1, | |
"title": "User notice title", | |
"body": "This is user notice test's body", | |
"created_at": "2014-09-19T02:53:03.000Z", | |
"updated_at": "2014-09-19T02:53:03.000Z", | |
"notice_type": "1" | |
} | |
*/ | |
public class LMQueryGetDriverNotices { | |
public static void get(String id) { | |
LMNetworkBuilder.getAdapter().create(GetDriverNoticeService.class) | |
.get(id, new Callback<n_PacketDriverNotice>() { | |
@Override | |
public void success(n_PacketDriverNotice result, Response response) { | |
LMNetworkBus.getInstance().post(result); | |
} | |
@Override | |
public void failure(RetrofitError error) { | |
error.printStackTrace(); | |
} | |
}); | |
} | |
private interface GetDriverNoticeService { | |
@GET("/driver_notices/{id}") | |
void get(@Path("id") String id, Callback<n_PacketDriverNotice> resultCallback); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment