Using the Haskell Github Gist API

First of all, I have never used an API before, and I have never used an HTTP library in Haskell. I'm not sure what I'm doing wrong here, so maybe someone who knows can help.

I am using what I can read: http://github.com/defunkt/gist/blob/master/gist.rb , namely the write method, to write this:

req = postRequest "http://gist.github.com/gists/new" testPost = simpleHTTP $ req {rqBody = urlEncodeVars [("login", "Raynes"), ("token","<removed>"), ("file_ext[gistfile1]",".hs"), ("file_name[gistfile1]","testfile"), ("file_contents[gistfile1]","main = putStrLn \"Hello, world!\"")]} 

When run, testPost gives this result:

 Right HTTP/1.1 302 Found Server: nginx/0.7.61 Date: Sun, 29 Nov 2009 17:13:51 GMT Content-Type: text/html; charset=utf-8 Connection: close Status: 302 Found Location: http://gist.github.com/gists/new X-Runtime: 1ms Content-Length: 98 Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly Cache-Control: no-cache 

As far as I know, the location should be a link to the new Gist. However, a new Gist is not created. I'm not sure what I'm doing wrong. There is basically no documentation for the Gist API, and I can only assume that I'm not translating Ruby correctly. As I said, I have never used the HTTP library before.

Any help is appreciated.

+4
source share
2 answers

I realized this after reading the Network.Browser.browse usage example.

 req = "http://gist.github.com/gists" testPost = do (uri, rsp) <- Network.Browser.browse $ do setAllowRedirects True request $ formToRequest $ Form POST (fromJust $ parseURI req) [("file_ext[gistfile1]",".hs"), ("file_contents[gistfile1]","main = putStrLn \"Hello, world!\""), ("login","Raynes"), ("token","removed")] return uri 
+1
source

Your POST URL is incorrect, according to the source it should be http://gist.github.com/gists

0
source

All Articles