Quick Start (Standard SDK Use)

Once you have configured your application for the Koupon Media SDK, the typical flow of calling SDK functions follows the pattern below.

  1. Obtain the consumer’s identity.
  2. Retrieve the consumer’s offer list.
  3. Mark offer in “Access” state
  4. Mark offers as “Viewed”
  5. Mark offers as “Presented”
  6. Add Offer to a Consumer.
  7. Add Multiple Offers to a Consumer.
The quick start steps below refer to code that has been pulled directly from the Koupon Media SDK Sample App. We recommend downloading the sample app and reviewing the files for context (e.g. our sample code utilizes button on click listeners) before proceeding.

Obtain the Consumer’s Identity

The code for registering a consumer was introduced in the section “Obtaining a Consumer Identity” above. To reiterate, there are two options for obtaining a consumer’s identity: (1) implement AsyncTaskListener in the current class and (2) inline.

 
//Inside your onCreate method.
	Koupon koupon = new Koupon(this);
	JSONObject consumerData = new JSONObject();
	try {
	//Optional, add any PII info for the consumer.
	//By default, Koupon will add the UDID of the device to ensure that consumer
		identities are unique.
		consumerData.put("cid", "some identifier");
	} catch (Exception ex) {
		Log.e(ex.printStackTrace());
	}
	KMRequest km = koupon.createConsumerIdentity(consumerData, null);
//Pass in an AsyncTaskListener. You could do this in two different ways.

 

Retrieve the Consumer’s Offer List

To retrieve a list of offers for the consumer, call the Koupon Media SDK as follows:

 
button2.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {
		KMRequest km = koupon.getConsumerOfferList(null, null);
		// km.print();
		if (km != null)
			km.sendRequestAsync(listener);
	}
});

button3.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {

		String offer = "0";
		if (offer != null && offers.length() > 0) {
			try {
				offer = String.valueOf(offers.getJSONObject(0).getInt("offerId"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		KMRequest km = koupon.getConsumerOffer(offer, null);
		// km.print();
		if (km != null)
			km.sendRequestAsync(listener);
	}
});

 

Mark an Offer in “Access” state

To mark a consumer’s offers as in an “access” state, this helps the Koupon Media system learn about consumer preferences based on what the consumer has or has not accessed, call the Koupon Media SDK as follows:

 
 button4.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
 
                 String offer = "0";
                  if (offers.length() > 0) {
                          try {
                                   offer = String.valueOf(offers.getJSONObject(0).getInt("offerId"));
                          } catch (JSONException e) {
                                   e.printStackTrace();
                          }
                  }
                 KMRequest km = koupon.updateConsumerState(“ACCESS", offer, null);
                  // km.print();
                  if (km != null)
                          km.sendRequestAsync(listener);
         }});

 

Mark an Offer as Viewed

To mark a consumer’s offers as “viewed,” which helps the Koupon Media system learn about consumer preferences based on what the consumer has or has not viewed, call the Koupon Media SDK as follows:

 
button4.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {

		String offer = "0";
		if (offers.length() > 0) {
			try {
				offer = String.valueOf(offers.getJSONObject(0).getInt("offerId"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		KMRequest km = koupon.updateConsumerState("Viewed", offer, null);
		// km.print();
		if (km != null)
			km.sendRequestAsync(listener);
	}
});

 

Mark an Offer as Presented (Single Use and Multi-Use)

Another common task for the Koupon Media SDK is to mark offers as used or “presented.” Note that offers can be configured as single-use or multi-use. When a consumer’s application marks a single-use offer as “presented” (i.e. the barcode has been presented to the screen for scanning), the offer will be removed from his or her offer list. Conversely, multi-use offers will be counted as used, but continue to appear in the offer list until the offer expires.

 
btnPresented.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {

		String offer = "0";
		if (offers != null && offers.length() > 0) {
			try {
				offer = String.valueOf(offers.getJSONObject(0).getInt("offerId"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		KMRequest km = koupon.updateConsumerState("PRESENTED", offer,
				null);                
		// km.print();
		if (km != null)
			km.sendRequestAsync(listener);
	}
});

 

Add Offer to a Consumer

The sample code below adds a single-use offer to a consumer.

 
button5.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {

		// TODO: Add an actual Offer here.
		KMRequest km = koupon.addOfferToConsumer("0", null);
		// km.print();
		if (km != null)
			km.sendRequestAsync(listener);
	}
});

 

Add Multiple Offers to a Consumer

The sample code below adds a multi-use offer to a consumer.

 
button9.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {

		JSONArray offerList = new JSONArray();
		// TODO: Add actual Triggered Offers
		offerList.put("0");
		offerList.put("1");

		KMRequest km = koupon.addMultipleOffersToConsumer(offerList,
				null);
		// km.print();
		if (km != null)
			km.sendRequestAsync(listener);
	}
});