Created
November 18, 2013 22:02
-
-
Save NuclearMonster/7536202 to your computer and use it in GitHub Desktop.
Unity Free-to-Paid Cross Promotion Gist for Leap Motion Airspace App Store created by Pohung Chen
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
using UnityEngine; | |
using System.Collections; | |
using System; | |
using System.Net; | |
using System.IO; | |
using SimpleJSON; | |
public class AirspaceCrossPromotion : MonoBehaviour { | |
string endpointURL = "https://warehouse.leapmotion.com/api/v1/cross_promotions/[your_cross_promotion_id]"; | |
void GetCTA() { | |
try { | |
WebRequest getURL = WebRequest.Create (endpointURL); | |
Stream objStream = getURL.GetResponse().GetResponseStream(); | |
StreamReader objReader = new StreamReader(objStream); | |
var parsedObj = JSON.Parse(objReader.ReadToEnd()); | |
Debug.Log(parsedObj["cross_promotion"]["uuid"]); | |
if (parsedObj["cross_promotion"]["active"].AsBool) { | |
CTAActive(parsedObj["cross_promotion"]["cta_url"]); | |
} else { | |
CTAInActive(); | |
} | |
} catch (WebException e) { | |
CTAError(e.Message); | |
} | |
} | |
void CTAActive(string url) { | |
Debug.Log(url); | |
} | |
void CTAInActive() { | |
Debug.Log("Cross Promotion Found but not yet active"); | |
} | |
void CTAError(string error) { | |
Debug.LogError(error); | |
} | |
void Start () { | |
GetCTA(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment