Skip to content

Commit

Permalink
Login functionality consuming REST API services. This commit closes #10
Browse files Browse the repository at this point in the history
…, closes #20 and closes #29
  • Loading branch information
e-liva committed Sep 27, 2015
1 parent d8a9178 commit 046f0f3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class UserAccount extends UserData implements Serializable {
private String token = null;
private int id;

public UserAccount(final String email, final String password, final String token, int id){
super(email, password);
public UserAccount(final String email, final String token, int id){
super(email, null);
this.token = token;
this.id = id; // User ID
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class UserProfile extends UserData {
private String lastLocation = null;
private int id;

public UserProfile(String email, String password, String firstname, String lastname, String photo, String lastLocation, int id){
super(email, password);
public UserProfile(String email, String firstname, String lastname, String photo, String lastLocation, int id){
super(email, null);
this.firstname = firstname;
this.lastname = lastname;
this.photo = photo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@

import com.squareup.okhttp.OkHttpClient;

import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.client.OkClient;

public abstract class AbstractService {
private static final String BASE_URL = "http://quick-entities.herokuapp.com";
private static RestAdapter restAdapter = new RestAdapter.Builder()
private static RestAdapter.Builder builder = new RestAdapter.Builder()
.setEndpoint(BASE_URL)
.setClient(new OkClient(new OkHttpClient()))
.setLogLevel(RestAdapter.LogLevel.FULL).build();
.setLogLevel(RestAdapter.LogLevel.FULL);

protected <T> T createService(Class<T> service) {
return restAdapter.create(service);

protected <T> T createService(Class<T> service, final String token) {
if (token != null){
builder.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Accept", "application/json");
request.addHeader("Authorization", token);
}
});
}
return builder.build().create(service);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ private interface FilesServiceApi {

private FilesServiceApi mFilesServiceApi;

public FilesService() {
this.mFilesServiceApi = createService(FilesServiceApi.class);
public FilesService(final String token) {
this.mFilesServiceApi = createService(FilesServiceApi.class, token);
}

public void getFiles(final ServiceCallback<List<File>> serviceCallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private interface LoginServiceApi {
private LoginServiceApi mLoginServiceApi;

public LoginService() {
this.mLoginServiceApi = createService(LoginServiceApi.class);
this.mLoginServiceApi = createService(LoginServiceApi.class, null);
}

public void getToken(/*UserData uData, */final ServiceCallback<UserAccount> uAccountCb){
Expand Down

0 comments on commit 046f0f3

Please sign in to comment.