private static Response getItem(string itemUrl)
    {
        HttpWebResponse response     = SendHttpRequestToCortex.SendGetRequest(itemUrl);
        string          responseJSON = SendHttpRequestToCortex.GetResponseBody(response);

        return((Response)RequestUtils.deserialize(responseJSON, typeof(Response)));
    }
    public static PurchaseResponse Purchase()
    {
        string orderUrl = GetOrderUrl();

        Debug.Log(orderUrl);

        //Get purchase form URL:
        HttpWebResponse orderResponse     = SendHttpRequestToCortex.SendGetRequest(orderUrl);
        string          orderResponseJSON = SendHttpRequestToCortex.GetResponseBody(orderResponse);

        Response orderResponseObject = (Response)RequestUtils.deserialize(orderResponseJSON, typeof(Response));
        string   purchaseFormUrl     = "";

        foreach (Response.Links linkObj in orderResponseObject.links)
        {
            if (linkObj.rel.Equals("purchaseform"))
            {
                purchaseFormUrl = linkObj.href;
            }
        }

        //Get submit order action URL:
        HttpWebResponse purchaseFormResponse     = SendHttpRequestToCortex.SendGetRequest(purchaseFormUrl);
        string          purchaseFormResponseJSON = SendHttpRequestToCortex.GetResponseBody(purchaseFormResponse);

        Response purchaseFormResponseObject = (Response)RequestUtils.deserialize(purchaseFormResponseJSON, typeof(Response));
        string   submitOrderActionUrl       = "";

        foreach (Response.Links linkObj in purchaseFormResponseObject.links)
        {
            if (linkObj.rel.Equals("submitorderaction"))
            {
                submitOrderActionUrl = linkObj.href;
            }
        }
        Debug.Log(purchaseFormResponseJSON);
        Debug.Log(submitOrderActionUrl);

        //Submit order to make purchase
        submitOrderActionUrl = submitOrderActionUrl + "?followLocation";
        HttpWebResponse submitOrderActionResponse = SendHttpRequestToCortex.SendPostRequest(submitOrderActionUrl, emptyJsonForm);

        Debug.Log(submitOrderActionResponse.StatusCode);

        string submitOrderActionResponseJSON = SendHttpRequestToCortex.GetResponseBody(submitOrderActionResponse);

        Debug.Log(submitOrderActionResponseJSON);

        //remove all dashes from json response since C# hates them
        submitOrderActionResponseJSON = submitOrderActionResponseJSON.Replace("-", "");
        Debug.Log(submitOrderActionResponseJSON);

        PurchaseResponse response = (PurchaseResponse)RequestUtils.deserialize(submitOrderActionResponseJSON, typeof(PurchaseResponse));

        Debug.Log(response.monetarytotal[0].amount);
        Debug.Log(response.status);

        return(response);
    }
    public static Response GetCartResponse()
    {
        string          url          = SendHttpRequestToCortex.cartsUrl;
        HttpWebResponse httpResponse = SendHttpRequestToCortex.SendGetRequest(url);

        string responseJSON = SendHttpRequestToCortex.GetResponseBody(httpResponse);

        Debug.Log(responseJSON);

        Response response = (Response)RequestUtils.deserialize(responseJSON, typeof(Response));

        return(response);
    }
    public static void AddItemToCart(string itemUri)
    {
        HttpWebResponse itemResponse     = SendHttpRequestToCortex.SendGetRequest(itemUri);
        string          itemResponseJSON = SendHttpRequestToCortex.GetResponseBody(itemResponse);

        Response itemResponseObj = (Response)RequestUtils.deserialize(itemResponseJSON, typeof(Response));

        // -- Get add to cart form uri
        string addToCartFormUrl = "";

        foreach (Response.Links linkObj in itemResponseObj.links)
        {
            if (linkObj.rel.Equals("addtocartform"))
            {
                addToCartFormUrl = linkObj.href;
            }
        }
        Debug.Log(addToCartFormUrl);

        // -- get add to cart form object to get addtodefaultcart action url
        HttpWebResponse addToCartFormResponse     = SendHttpRequestToCortex.SendGetRequest(addToCartFormUrl);
        string          addToCartFormResponseJSON = SendHttpRequestToCortex.GetResponseBody(addToCartFormResponse);

        Response addToCartFormResponseObj = (Response)RequestUtils.deserialize(addToCartFormResponseJSON, typeof(Response));

        Debug.Log(addToCartFormResponseJSON);

        // -- Get add to cart form uri
        string addToDefaultCartActionUrl = "";

        foreach (Response.Links linkObj in addToCartFormResponseObj.links)
        {
            if (linkObj.rel.Equals("addtodefaultcartaction"))
            {
                addToDefaultCartActionUrl = linkObj.href;
            }
        }

        Debug.Log(addToDefaultCartActionUrl);

        // add item to cart
        HttpWebResponse httpResponse = SendHttpRequestToCortex.SendPostRequest(addToDefaultCartActionUrl, quantityJsonForm);

        Debug.Log(httpResponse.StatusCode);
    }
    /*
     * returns item url
     */
    static string SearchForItem(string itemName)
    {
        //Create search request json object
        RequestItemSearch searchRequestObj = new RequestItemSearch();

        searchRequestObj.keywords = itemName;

        string          requestJSON  = RequestUtils.serialize(searchRequestObj, typeof(RequestItemSearch));
        HttpWebResponse httpResponse = SendHttpRequestToCortex.SendPostRequest(searchURL, requestJSON);

        string         responseJSON      = SendHttpRequestToCortex.GetResponseBody(httpResponse);
        ResponseSearch responseSearchObj = (ResponseSearch)RequestUtils.deserialize(responseJSON, typeof(ResponseSearch));

        string itemUrl = responseSearchObj.links[0].href;         //We know there is only one link in the search results

        Debug.Log("Item URL: " + itemUrl);

        return(itemUrl);
    }
    void LoginScreen()
    {
        // Make a background box
        GUI.backgroundColor = Color.black;
        GUI.Box(new Rect(Screen.width / 2 - 110, Screen.height / 2 - 100, 300, 140), "Welcome, Please Log In");

        // Make login text fields
        GUI.backgroundColor = Color.gray;
        UserName            = GUI.TextField(new Rect(Screen.width / 2 - 60, Screen.height / 2 - 60, 200, 20), UserName, 50);
        //Password = GUI.TextField(new Rect(Screen.width/2-60, Screen.height/2-30, 200, 20),Password, 50);
        Password = GUI.PasswordField(new Rect(Screen.width / 2 - 60, Screen.height / 2 - 30, 200, 20), Password, "*"[0], 50);

        // Make the first button.
        if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2, 80, 20), "Login"))
        {
            // Create a request object
            RequestUser user = new RequestUser();
            user.username = UserName;
            user.password = Password;

            // Serialize to a string
            string jsonText = RequestUtils.serialize(user, typeof(RequestUser));

            HttpWebResponse httpResponse = SendHttpRequestToCortex.SendPostRequest(authUrl, jsonText);
            Debug.Log(httpResponse.StatusCode);

            if (httpResponse.StatusCode == HttpStatusCode.OK)
            {
                // Change application behavior once authenticated
                stage = 1;

                // Get JSON string from response
                string responseJSON = SendHttpRequestToCortex.GetResponseBody(httpResponse);

                auth = (ResponseAuthentication)RequestUtils.deserialize(responseJSON, typeof(ResponseAuthentication));
            }
            else
            {
                GUI.Box(new Rect(Screen.width / 2 + 30, Screen.height / 2 + 30, 80, 20), "Invalid Password, Please try Again");
            }
        }
    }
    /*
     * returns price
     */
    public static string FindItemPrice(string itemUrl)
    {
        Response itemResponse = getItem(itemUrl);

        //get link to prices from item
        string priceHref = "";

        foreach (Response.Links linkObj in itemResponse.links)
        {
            if (linkObj.rel.Equals("price"))
            {
                priceHref = linkObj.href;
            }
        }

        HttpWebResponse priceResponse     = SendHttpRequestToCortex.SendGetRequest(priceHref);
        string          priceJSONResponse = SendHttpRequestToCortex.GetResponseBody(priceResponse);

        ResponsePrice priceObject = (ResponsePrice)RequestUtils.deserialize(priceJSONResponse, typeof(ResponsePrice));

        return(priceObject.purchaseprice[0].display);
    }
    public static void setShippingOptionInfoIfNeeded()
    {
        //Get OrderUri
        string orderUrl = GetOrderUrl();

        //Get Order
        Response orderResponse = GetOrderResponse(orderUrl);

        //check if order has needInfoLink
        string needInfoUrl = GetRelUri("needinfo", orderResponse);

        //if needInfo is blank, no needInfo found
        if (needInfoUrl.Equals(""))
        {
            Debug.Log("No NeedInfo Found");
            return;
        }
        else
        {
            //get shipment details id
            string[] needInfoUrlTokens = needInfoUrl.Split(seperators);
            string   shipmentDetailsId = needInfoUrlTokens[3];

            //create shippingOptionUrl
            string shippingOptionUrl = cortexServerUrl + "/shipmentdetails" + storeScope + "/" +
                                       shipmentDetailsId + "/shippingoptioninfo/selector/shipmentdetails" + storeScope + "/" +
                                       shipmentDetailsId + "/shippingoptions/" + shippingOptionId;

            Debug.Log("ShippingOptionUrl: " + shippingOptionUrl);

            HttpWebResponse getHttpResponse = SendHttpRequestToCortex.SendGetRequest(shippingOptionUrl);
            Debug.Log("GetResponse: " + SendHttpRequestToCortex.GetResponseBody(getHttpResponse));

            //send POST request to select shipping option
            HttpWebResponse httpResponse = SendHttpRequestToCortex.SendPostRequest(shippingOptionUrl, emptyJsonForm);

            Debug.Log(httpResponse.StatusCode);
        }
    }