Wrapper networking library that can be used with Retrofit or Volley
Retrofit : link
Volley : link
-
Build the jar ( Use gradle task "makeJar" to build ) . Latest version is available here
-
Or By using gradle
dependencies { compile 'com.talentica:tsnetworking:0.1.1b' }
-
Import it on your project and include either Retrofit or Volley as second dependency.
-
Implement
TSCallback
in your main activity and initialize the library by using ,TSNetworking networking = new TSNetworking.Builder().setUrl(URL).withCallback(this).build();
-
Responses can be handled inside override method
onResponse
andonFailure
-
That's it. You can switch between volley and retrofit only by changing dependency.
-
Final Activity will look like as below :
public class MainActivity extends AppCompatActivity implements TSCallback {
private TSNetworking networking;
private final String URL = "https://api.stackexchange.com/2.2/"; //primary url
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
networking = new TSNetworking.Builder().setUrl(URL).withCallback(this).build();
networking.getTSGetResponse("search?order=desc&sort=activity&tagged=android&site=stackoverflow");//get response
}
@Override
public void onResponse(TSCall call, TSResponse response) {
Log.d("tsnetworking", "response code " + response.code());
Log.d("tsnetworking", "response body " + response.getBody());
}
@Override
public void onFailure(TSError error) {
Log.d("tsnetworking", "response error message " + error.getErrorMsg());
Log.d("tsnetworking", "response error code " + error.getErrorCode());
}
}
Copyright 2016 Talentica Software
Copyright 2013 Square, Inc.
Copyright (C) 2011 The Android Open Source Project
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.