This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
697 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...le-urbanairship/src/main/java/org/springframework/mobile/urbanairship/ContentReceipt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
public class ContentReceipt { | ||
|
||
private final String transactionReceipt; | ||
|
||
private final String udid; | ||
|
||
private final String version; | ||
|
||
public String getTransactionReceipt() { | ||
return transactionReceipt; | ||
} | ||
|
||
public String getUdid() { | ||
return udid; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public ContentReceipt(String transactionReceipt, String udid, String version) { | ||
this.transactionReceipt = transactionReceipt; | ||
this.udid = udid; | ||
this.version = version; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...irship/src/main/java/org/springframework/mobile/urbanairship/InAppPurchaseOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
import java.util.List; | ||
|
||
public interface InAppPurchaseOperations { | ||
|
||
List<InventoryItem> getInventory(); | ||
|
||
String getDownloadUrl(String productId); | ||
|
||
String getDownloadUrl(String productId, ContentReceipt receipt); | ||
|
||
List<Product> checkForUpdates(List<Product> products); | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...src/main/java/org/springframework/mobile/urbanairship/InvalidContentReceiptException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
@SuppressWarnings("serial") | ||
public class InvalidContentReceiptException extends RuntimeException { | ||
|
||
private final Integer receiptStatus; | ||
|
||
private final String serverResponse; | ||
|
||
public InvalidContentReceiptException(Integer receiptStatus, String serverResponse) { | ||
this.receiptStatus = receiptStatus; | ||
this.serverResponse = serverResponse; | ||
} | ||
|
||
public Integer getReceiptStatus() { | ||
return receiptStatus; | ||
} | ||
|
||
public String getServerResponse() { | ||
return serverResponse; | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...ile-urbanairship/src/main/java/org/springframework/mobile/urbanairship/InventoryItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
public class InventoryItem { | ||
|
||
private final String name; | ||
|
||
private final String url; | ||
|
||
private final String iconUrl; | ||
|
||
private final String previewUrl; | ||
|
||
private final String downloadUrl; | ||
|
||
private final String currentRevision; | ||
|
||
private final String productId; | ||
|
||
private final boolean free; | ||
|
||
private final int fileSize; | ||
|
||
private final String description; | ||
|
||
private InventoryItem(String name, String url, String iconUrl, String previewUrl, String downloadUrl, String currentRevision, String productId, boolean free, int fileSize, String description) { | ||
this.name = name; | ||
this.url = url; | ||
this.iconUrl = iconUrl; | ||
this.previewUrl = previewUrl; | ||
this.downloadUrl = downloadUrl; | ||
this.currentRevision = currentRevision; | ||
this.productId = productId; | ||
this.free = free; | ||
this.fileSize = fileSize; | ||
this.description = description; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getIconUrl() { | ||
return iconUrl; | ||
} | ||
|
||
public String getPreviewUrl() { | ||
return previewUrl; | ||
} | ||
|
||
public String getDownloadUrl() { | ||
return downloadUrl; | ||
} | ||
|
||
public String getCurrentRevision() { | ||
return currentRevision; | ||
} | ||
|
||
public String getProductId() { | ||
return productId; | ||
} | ||
|
||
public boolean isFree() { | ||
return free; | ||
} | ||
|
||
public int getFileSize() { | ||
return fileSize; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...ng-mobile-urbanairship/src/main/java/org/springframework/mobile/urbanairship/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
public class Product { | ||
|
||
private final String productId; | ||
|
||
private final int currentRevision; | ||
|
||
private String downloadUrl; | ||
|
||
public Product(String productId, int currentRevision) { | ||
this.productId = productId; | ||
this.currentRevision = currentRevision; | ||
} | ||
|
||
public String getProductId() { | ||
return productId; | ||
} | ||
|
||
public int getCurrentRevision() { | ||
return currentRevision; | ||
} | ||
|
||
public String getDownloadUrl() { | ||
return downloadUrl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...-urbanairship/src/main/java/org/springframework/mobile/urbanairship/impl/DownloadUrl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship.impl; | ||
|
||
public class DownloadUrl { | ||
|
||
private String contentUrl; | ||
|
||
private Integer receiptStatus; | ||
|
||
private String serverResponse; | ||
|
||
public DownloadUrl(String contentUrl, Integer receiptStatus, String serverResponse) { | ||
this.contentUrl = contentUrl; | ||
this.receiptStatus = receiptStatus; | ||
this.serverResponse = serverResponse; | ||
} | ||
|
||
public String getContentUrl() { | ||
return contentUrl; | ||
} | ||
|
||
public Integer getReceiptStatus() { | ||
return receiptStatus; | ||
} | ||
|
||
public String getServerResponse() { | ||
return serverResponse; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...hip/src/main/java/org/springframework/mobile/urbanairship/impl/InAppPurchaseTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship.impl; | ||
|
||
import static org.springframework.http.HttpMethod.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mobile.urbanairship.ContentReceipt; | ||
import org.springframework.mobile.urbanairship.InAppPurchaseOperations; | ||
import org.springframework.mobile.urbanairship.InvalidContentReceiptException; | ||
import org.springframework.mobile.urbanairship.InventoryItem; | ||
import org.springframework.mobile.urbanairship.Product; | ||
import org.springframework.web.client.RestOperations; | ||
|
||
public class InAppPurchaseTemplate implements InAppPurchaseOperations { | ||
|
||
private final RestOperations restOperations; | ||
|
||
public InAppPurchaseTemplate(RestOperations restOperations) { | ||
this.restOperations = restOperations; | ||
} | ||
|
||
public List<InventoryItem> getInventory() { | ||
return restOperations.getForObject(IAP_URL + "content", Inventory.class); | ||
} | ||
|
||
public String getDownloadUrl(String productId) { | ||
DownloadUrl downloadUrl = restOperations.postForObject(IAP_URL + "content/" + productId + "/download", "", DownloadUrl.class); | ||
return downloadUrl.getContentUrl(); | ||
} | ||
|
||
public String getDownloadUrl(String productId, ContentReceipt receipt) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<ContentReceipt> requestEntity = new HttpEntity<ContentReceipt>(receipt, headers); | ||
DownloadUrl response = restOperations.exchange(IAP_URL + "content/" + productId + "/download", POST, requestEntity, DownloadUrl.class).getBody(); | ||
if (response.getContentUrl() == null || response.getReceiptStatus() != null) { | ||
throw new InvalidContentReceiptException(response.getReceiptStatus(), response.getServerResponse()); | ||
} | ||
return response.getContentUrl(); | ||
} | ||
|
||
public List<Product> checkForUpdates(List<Product> products) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<List<Product>> requestEntity = new HttpEntity<List<Product>>(products, headers); | ||
return restOperations.exchange(IAP_URL + "updates", POST, requestEntity, ProductList.class).getBody(); | ||
} | ||
|
||
private static final String IAP_URL = "https://go.urbanairship.com/api/app/"; | ||
|
||
@SuppressWarnings("serial") | ||
private static class Inventory extends ArrayList<InventoryItem> {} | ||
|
||
@SuppressWarnings("serial") | ||
private static class ProductList extends ArrayList<Product> {} | ||
} |
Oops, something went wrong.