示例#1
0
        public void ObtainFromRemote(string url, string apiKey)
        {
            list.Clear();
            if (String.IsNullOrEmpty(apiKey))
            {
                throw new Exception("The api key is not installed.");
            }
            IDictionary <string, string> headers = new Dictionary <string, string>();

            headers["Authorization"] = apiKey;

            SimpleWebQuery  myRequest = new SimpleWebQuery(url);
            HttpWebResponse response  = myRequest.DoAction(@"/api/3/action/package_list", "GET", headers, null);
            Stream          stream    = response.GetResponseStream();
            StreamReader    reader    = new StreamReader(stream);

            string result = reader.ReadToEnd();

            JavaScriptSerializer         serializer         = new JavaScriptSerializer();
            IDictionary <string, object> deserializedResult = serializer.Deserialize <IDictionary <string, object> >(result);

            if (deserializedResult["success"].ToString().Equals("true"))
            {
                if (deserializedResult["result"] is IDictionary <string, object> )
                {
                    IDictionary <string, string> results = (deserializedResult["result"] as IDictionary <string, string>);
                    foreach (string item in results.Values)
                    {
                        list.Add(item);
                    }
                }
            }
            stream.Dispose();
            reader.Dispose();
        }
示例#2
0
        public DatasetModel GetDataModelByPackageName(string url, string apiKey, string name)
        {
            if (String.IsNullOrEmpty(apiKey))
            {
                throw new Exception("The api key is not installed.");
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception("The input package name is empty.");
            }

            IDictionary <string, string> headers = new Dictionary <string, string>();

            headers["Authorization"] = apiKey;

            SimpleWebQuery  myRequest = new SimpleWebQuery(url);
            HttpWebResponse response  = myRequest.DoAction(String.Format(@"/api/3/action/package_show?id={0}", name), "GET", headers, null);
            Stream          stream    = response.GetResponseStream();
            StreamReader    reader    = new StreamReader(stream);

            string result = reader.ReadToEnd();

            JavaScriptSerializer         serializer         = new JavaScriptSerializer();
            IDictionary <string, object> deserializedResult = serializer.Deserialize <IDictionary <string, object> >(result);

            if (deserializedResult["success"].ToString().Equals("true"))
            {
                if (deserializedResult["result"] is IDictionary <string, object> )
                {
                    IDictionary <string, string> results = (deserializedResult["result"] as IDictionary <string, string>);
                    DatasetModel model = new DatasetModel();

                    foreach (KeyValuePair <string, string> item in results)
                    {
                        switch (item.Key)
                        {
                        case "maintainer":
                            model.maintainer = item.Value;
                            break;

                        case "author_email":
                            model.authorEmail = item.Value;
                            break;

                        case "license_id":
                            model.licenseResourceId = item.Value;
                            break;

                        case "name":
                            model.name = item.Value;
                            break;

                        case "num_resources":
                            model.numberOfResources = Convert.ToInt32(item.Value);
                            break;

                        case "title":
                            model.title = item.Value;
                            break;

                        case "notes":
                            model.note = item.Value;
                        }
                        list.Add(item);
                    }
                }
            }
            stream.Dispose();
            reader.Dispose();
        }
 /// <summary>
 /// Do login action.
 /// </summary>
 /// <param name="requests">Dictionary object of keys and values.</param>
 /// <returns>HttpWebResponse</returns>
 public HttpWebResponse Login(IDictionary <string, string> headers, IDictionary <string, object> postParameters)
 {
     return(query.DoAction("/login_generic?came_from=/user/logged_in", "POST", headers, postParameters));
 }