1 |
/* Copyright (c) 2012 Google Inc. |
2 |
* |
3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
* you may not use this file except in compliance with the License. |
5 |
* You may obtain a copy of the License at |
6 |
* |
7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8 |
* |
9 |
* Unless required by applicable law or agreed to in writing, software |
10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
* See the License for the specific language governing permissions and |
13 |
* limitations under the License. |
14 |
*/ |
15 |
|
16 |
package com.example.android.trivialdrivesample.util; |
17 |
|
18 |
import org.json.JSONException; |
19 |
import org.json.JSONObject; |
20 |
|
21 |
/** |
22 |
* Represents an in-app product's listing details. |
23 |
*/ |
24 |
public class SkuDetails { |
25 |
String mItemType; |
26 |
String mSku; |
27 |
String mType; |
28 |
String mPrice; |
29 |
String mTitle; |
30 |
String mDescription; |
31 |
String mJson; |
32 |
|
33 |
public SkuDetails(String jsonSkuDetails) throws JSONException { |
34 |
this(IabHelper.ITEM_TYPE_INAPP, jsonSkuDetails); |
35 |
} |
36 |
|
37 |
public SkuDetails(String itemType, String jsonSkuDetails) throws JSONException { |
38 |
mItemType = itemType; |
39 |
mJson = jsonSkuDetails; |
40 |
JSONObject o = new JSONObject(mJson); |
41 |
mSku = o.optString("productId"); |
42 |
mType = o.optString("type"); |
43 |
mPrice = o.optString("price"); |
44 |
mTitle = o.optString("title"); |
45 |
mDescription = o.optString("description"); |
46 |
} |
47 |
|
48 |
public String getSku() { return mSku; } |
49 |
public String getType() { return mType; } |
50 |
public String getPrice() { return mPrice; } |
51 |
public String getTitle() { return mTitle; } |
52 |
public String getDescription() { return mDescription; } |
53 |
|
54 |
@Override |
55 |
public String toString() { |
56 |
return "SkuDetails:" + mJson; |
57 |
} |
58 |
} |