lib & contrib: update imports
[nit.git] / lib / github / github_curl.nit
index dea87e4..f2d5737 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
@@ -26,6 +27,9 @@ class GithubCurl
        var header: HeaderMap is noinit
 
        # OAuth token
+       #
+       # Use an empty string to disable authentication and connect
+       # anonymously (thus less capabilities and more rate limits)
        var auth: String
 
        # User agent (is used by github to contact devs in case of problems)
@@ -34,7 +38,7 @@ class GithubCurl
 
        init do
                header = new HeaderMap
-               header["Authorization"] = "token {auth}"
+               if auth != "" then header["Authorization"] = "token {auth}"
        end
 
        # Get the requested URI, and check the HTTP response. Then convert to JSON
@@ -81,7 +85,7 @@ class GithubCurl
                        if obj isa JsonObject then
                                if obj.keys.has("message") then
                                        var title = "GithubAPIError"
-                                       var msg = obj["message"].to_s
+                                       var msg = obj["message"].as(not null).to_s
                                        var err = new GithubError(msg, title)
                                        err.json["requested_uri"] = uri
                                        err.json["status_code"] = response.status_code
@@ -124,9 +128,7 @@ class GithubError
                json["message"] = message.to_json
        end
 
-       redef fun to_json do
-               return json.to_json
-       end
+       redef fun serialize_to(v) do json.serialize_to v
 
        redef fun to_s do return "[{name}] {super}"
 end