Skip to content

Instantly share code, notes, and snippets.

@Adam-Fresko
Created January 8, 2016 13:37
Show Gist options
  • Save Adam-Fresko/67f2f60fdfd4d5479733 to your computer and use it in GitHub Desktop.
Save Adam-Fresko/67f2f60fdfd4d5479733 to your computer and use it in GitHub Desktop.
public class Retro {
private static OkHttpClient httpClient;
private static Retrofit retrofit;
private static RetrofitServiceProfile mServiceProfile;
static {
httpClient = new OkHttpClient();
httpClient.interceptors().add(new OkHttpInterceptor());
// Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(new ItemTypeAdapterFactory()) // This is the important line ;)
// .setDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'")
// .create();
retrofit = new Retrofit.Builder()
// .baseUrl("http://dev.vmrhost.net/tests/webike/frontend/api/v4_inpulse/")
// .baseUrl("https://api.moveapponline.com/v4/")
.baseUrl("http://api.online.kreckm.pl/v4/")
.client(httpClient)
// .addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create())
.build();
mServiceProfile = retrofit.create(RetrofitServiceProfile.class);
}
public Retrofit getInstance() {
return retrofit;
}
public static RetrofitServiceProfile getServiceProfile() {
return mServiceProfile;
}
}
public interface RetrofitServiceProfile {
@GET("users/{id}/thumb:300x300")
Call<ResponseProfile> getProfile(@Path("id") int id);
}
package com.main.model.profile;
import com.google.gson.annotations.SerializedName;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.io.Serializable;
/**
* Created by Adam Fręśko - Deadswine Studio on 2016-01-08.
*/
public class Profile implements Serializable {
public static final String PRIVACY_FULL = "FULL";
public static final String PRIVACY_BASIC = "BASIC";
public static final String PRIVACY_BASIC_STATS = "BASIC_STATS";
public static final String TYPE_EMPTY = "TYPE_EMPTY";
private String type;
boolean isSelf = true;
private long id;
private String token;
@SerializedName("new")
private boolean new_account;
private String first_name;
private String last_name;
@Deprecated
private int city;
@Deprecated
private int state;
private String gender;
private String birthdate;
@DatabaseField
private float weight;
private String photo_url;
private String location;
private String manual_location;
private String rules_acceptation;
private String[] favourite_sports;
private int friends_count;
private int achievements_count;
private boolean is_friend;
private boolean invited;
@SerializedName("friends_privacy_policy")
private String privacyFriends;
@SerializedName("others_privacy_policy")
private String privacyOthers;
private Integer[] distance_weekly;
private Integer[] activities_weekly;
public boolean is_facebook;
public String email;
public Profile() {
}
public Profile(long id, String name, String url) {
this.id = id;
this.first_name = name;
this.photo_url = url;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Profile{");
sb.append("id=").append(id);
sb.append(", first_name='").append(first_name).append('\'');
sb.append(", last_name='").append(last_name).append('\'');
sb.append(", photo_url='").append(photo_url).append('\'');
sb.append(", location='").append(location).append('\'');
sb.append(", manual_location='").append(manual_location).append('\'');
sb.append('}');
return sb.toString();
}
}
RetrofitServiceProfile client = Retro.getServiceProfile();
Call<ResponseProfile> call = client.getProfile(93632);
log(" call.execute(): " + call.execute().raw());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment