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

Dev/inmar api #1

Merged
merged 3 commits into from
Jul 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="tme_event" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="CouponQuest" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -61,6 +61,10 @@
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="okhttp-protocols-1.3.0" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.2.2" level="project" />
<orderEntry type="library" exported="" name="gson-2.2.4" level="project" />
<orderEntry type="library" exported="" name="okhttp-1.3.0" level="project" />
</component>
</module>

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.retrofit:retrofit:1.2.2'
compile 'com.squareup.okhttp:okhttp:1.3.0'
}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name="MainApplication"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
Expand All @@ -18,4 +19,6 @@
</activity>
</application>

<uses-permission android:name="android.permission.INTERNET"/>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tme.transactthis.com.couponquest;

import android.app.Application;
import android.util.Log;

import java.util.List;

import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import tme.transactthis.com.couponquest.model.inmar.InmarApi;
import tme.transactthis.com.couponquest.model.inmar.vo.Coupon;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public class MainApplication extends Application {

@Override
public void onCreate() {
super.onCreate();

InmarApi.create(getApplicationContext(), 5*1024*1024);

// InmarApi.getInstance().getOffers( new Callback<List<Coupon>>() {
// @Override
// public void success(List<Coupon> couponResponse, Response response) {
// Log.d("SUCCESS", "SUCCESS");
// }
//
// @Override
// public void failure(RetrofitError error) {
// Log.d("FAILURE", "FAILURE");
// }
// });

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package tme.transactthis.com.couponquest.model.inmar;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;

import java.io.IOException;
import java.util.List;

import retrofit.RestAdapter;
import retrofit.client.OkClient;
import retrofit.converter.GsonConverter;
import tme.transactthis.com.couponquest.model.inmar.vo.Coupon;
import tme.transactthis.com.couponquest.model.inmar.params.OfferParams;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public class InmarApi {

public static InmarApi mInstance;

private static final String API_URL = "http://tme-ice.test.dpn.inmar.com";

private RestAdapter mRestAdapter;
private InmarServices mServices;

public static InmarApi getInstance(){
return mInstance;
}

public static void create(Context applicationContext, long cacheSize){
mInstance = new InmarApi(applicationContext, cacheSize);
}

private InmarApi(Context applicationContext, long cacheSize){
OkHttpClient okHttpClient = new OkHttpClient();
HttpResponseCache cache = null;

try {
cache = new HttpResponseCache(applicationContext.getCacheDir(), cacheSize);
} catch (IOException e) {
e.printStackTrace();
}

okHttpClient.setResponseCache(cache);

Gson gson = new GsonBuilder().create();
//.registerTypeAdapter(Date.class, new DateAdapter())
// .create();

mRestAdapter = new RestAdapter.Builder()
.setClient(new OkClient(okHttpClient))
.setConverter(new GsonConverter(gson))
.setServer(API_URL)
.build();

mServices = mRestAdapter.create(InmarServices.class);
}

public void login(String username, String password){

}

public void register(String username, String password, String email){

}

public void getOffers(OfferParams params, retrofit.Callback<List<Coupon>> callback){
mServices.getOffers(
params.skip
,params.clipped
, params.keywords
, params.limit
, params.categories
, params.sort
, params.redeemed
, params.expired
, params.includeClipped
,callback
);

}

public void getOffers(retrofit.Callback<List<Coupon>> callback){
mServices.getOffers(
callback
);

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tme.transactthis.com.couponquest.model.inmar;

import java.util.List;

import retrofit.http.GET;
import retrofit.http.Query;
import retrofit.Callback;
import tme.transactthis.com.couponquest.model.inmar.vo.Coupon;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public interface InmarServices {

@GET("/offers")
public void getOffers(@Query("skip") int skip
, @Query("clipped") boolean clipped
, @Query("keywords") String keywords
, @Query("limit") int limit
, @Query("categories") String categories
, @Query("sort") String sort
, @Query("redeemed") boolean redeemed
, @Query("expired") boolean expired
, @Query("includeClipped") boolean includeClipped
, Callback<List<Coupon>> callback);

@GET("/offers")
public void getOffers(Callback<List<Coupon>> callback);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package tme.transactthis.com.couponquest.model.inmar.params;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public class OfferParams {

public OfferParams(){

}

public OfferParams(String token
, int skip
, boolean clipped
, String keywords
, int limit
, String categories
, String sort
, boolean redeemed
, boolean expired
, boolean includeClipped) {
this.token = token;
this.skip = skip;
this.clipped = clipped;
this.keywords = keywords;
this.limit = limit;
this.categories = categories;
this.sort = sort;
this.redeemed = redeemed;
this.expired = expired;
this.includeClipped = includeClipped;
}

// Include the user token to retrieve a customized list of offers, specific to that user - by
// default unclipped (available) offers are returned first, followed by any clipped offers
// unless clipped is set to false
public String token;

//skip specified number of single offers (for paging)
public int skip;

//set to 'true' to return a user's clipped offers only (must be passed in with a token)
public boolean clipped;

//keywords a comma delimited list of keywords to search offers for (e.g. "baby,food")
public String keywords;

//limit to n number of offers (default is 12)
public int limit;

//categories comma delimited list of category ids to return (from the category API), default is offers
//from all categories
public String categories;

//sort string for sort order (asc | desc)
public String sort;

//redeemed set to 'true' to retrieve a user's redeemed offers (token must also be set), clipped/expired
//must not be set - sets redeemedDate JSON element for date redeemed (null otherwise)
public boolean redeemed;

//expired set to 'true' to retrieve a user's expired offers (token must also be set), clipped/redeemed
//must not be set
public boolean expired;

//includeClipped set to 'false' to exclude clipped offers (overrides clipped)
public boolean includeClipped;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tme.transactthis.com.couponquest.model.inmar.vo;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public class Category {

public String id;
public String name;
public int active;
public int value;
public String grocery;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tme.transactthis.com.couponquest.model.inmar.vo;

import java.util.Date;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public class Coupon {

public int mdid;
public String badge;
public boolean clipped;
public Date redeemedDate;
public Category category;
public String brand;
public String description;
public String shortDescription;
public String imageUrl;
public int value;
public String terms;
public String minPurchase;
public String offerSortValue;
public InmarDate expirationDate;
public InmarDate clipStartDate;
public InmarDate clipEndDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tme.transactthis.com.couponquest.model.inmar.vo;

/**
* Created by trey on 7/12/14.
* Copyright 2014 MindMine LLC.
*/
public class InmarDate {

// "expirationDate":{
// "__type":"Date",
// "iso":"2014-07-31T00:00:00.000Z"
// },

public String __type;
public String iso;
}