WeatherTrigger API

Code Samples

Javascript/Jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>

        $.ajax({
            url: base_url + query,
            type: 'GET',
            success: function (parsedResponse, statusText, jqXhr) {

                var responseText = jqXhr.responseText;
                var ConditionMatched = parsedResponse.ConditionMatched;
                var ConditionMatchedNum = parsedResponse.ConditionMatchedNum;
                
            },
            error: function (error) {
                
                var status_code = error.status;
                var status_text = error.statusText;
                var data = jQuery.parseJSON(error.responseText);
                var error_message = data.Message;
                var error_description = data.Description;
                var error_internal_code = data.InternalCode;
                var error_url = data.HelpUrl;
            }
        });

    </script>

Using YQL and JSONP

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script>

        $.ajax({
            url: "http://api.weatherunlocked.com/api/trigger/51.50,-0.12/current%20temperature%20gt%202?app_id={APP_ID}&app_key={APP_KEY}",
         
            // the name of the callback parameter, as specified by the YQL service
            jsonp: "callback",
         
            // tell jQuery we're expecting JSONP
            dataType: "jsonp",
         
            // tell YQL what we want and that we want JSON
            data: {
                format: "json"
            },
         
            // work with the response
            success: function( response ) {
                // server response
                console.log( response );
            }
        });

    </script>

C#

using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;

        try
        {
            WebClient ClientGet = new WebClient();
            ClientGet.Headers["Content-type"] = "application/json";
            byte[] data = ClientGet.DownloadData(base_url + user_query);
            MemoryStream stream = new MemoryStream(data);

            using (stream)
            {
                stream.Position = 0;
                var sr = new StreamReader(stream);
                string json = sr.ReadToEnd();
                var result = JObject.Parse(json);

                string responseText = json;
                string ConditionMatched = result["ConditionMatched"].ToString();
                string ConditionMatchedNum = result["ConditionMatchedNum"].ToString();
            }

        }
        catch (WebException ex)
        {
            var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
            var result = JObject.Parse(resp);

            var response = ex.Response as HttpWebResponse;
            string status_code = ((int)response.StatusCode).ToString();
            string status_text = response.StatusCode.ToString();

            string error_message = result["Message"].ToString();
            string error_description = result["Description"].ToString();
            string error_internal_code = result["InternalCode"].ToString();
            string error_url = result["HelpUrl"].ToString();
        }