github_search_for_jni: Migrate to new Github API
[nit.git] / lib / github / github_curl.nit
index 05761b1..6f28546 100644 (file)
@@ -18,6 +18,7 @@ module github_curl
 
 import curl
 import json::static
+import json
 
 # Specific Curl that know hot to talk to the github API
 class GithubCurl
@@ -42,7 +43,7 @@ class GithubCurl
 
        # Get the requested URI, and check the HTTP response. Then convert to JSON
        # and check for Github errors.
-       fun get_and_check(uri: String): nullable Jsonable
+       fun get_and_check(uri: String): nullable Serializable
        do
                var request = new CurlHTTPRequest(uri)
                request.user_agent = user_agent
@@ -52,7 +53,7 @@ class GithubCurl
                if response isa CurlResponseSuccess then
                        var obj = response.body_str.parse_json
                        if obj isa JsonObject then
-                               if obj.keys.has("message") then
+                               if obj.keys.has("message") and obj.keys.has("documentation_url") then
                                        print "Message from Github API: {obj["message"] or else ""}"
                                        print "Requested URI: {uri}"
                                        abort
@@ -73,7 +74,7 @@ class GithubCurl
        # Then convert to JSON and check for Github errors.
        # Unlike `get_and_check`, error do not trigger an abort but
        # are reported as `GithubError`.
-       fun get_and_parse(uri: String): nullable Jsonable
+       fun get_and_parse(uri: String): nullable Serializable
        do
                var request = new CurlHTTPRequest(uri)
                request.user_agent = user_agent
@@ -82,7 +83,7 @@ class GithubCurl
                if response isa CurlResponseSuccess then
                        var obj = response.body_str.parse_json
                        if obj isa JsonObject then
-                               if obj.keys.has("message") then
+                               if obj.keys.has("message") and obj.keys.has("documentation_url") then
                                        var title = "GithubAPIError"
                                        var msg = obj["message"].as(not null).to_s
                                        var err = new GithubError(msg, title)
@@ -113,7 +114,7 @@ end
 # Check the `json` value to find them.
 class GithubError
        super Error
-       super Jsonable
+       super Serializable
 
        # The name of the error.
        var name: String