views:

662

answers:

2

I'm making a small app in Adobe Air which I need to interact with the Github Gist API. However I'm kind of stuck.

If you're not familiar with Adobe Air you can still help, the XMLHttpRequest javascript object can do cross domain requests, as there is no domain as such. So theres nothing Adobe Air specific here.

Where I'm stuck is I think I need to authenticate myself then make the POST. I just don't understand it

+1  A: 

You shouldn't have to authenticate the user.

The XMLHttpRequest will just have to have the user name and the users API token included in the request.

Looking at the example ruby script provided by github here, you just have to provide the following attributes:

  • File Extenstion
  • file name
  • content
  • If the gist is private or not
  • User login
  • User API Token

python and perl versions of the script

Brian Gianforcaro
I can't get anything to work. This is what I tried http://pastebin.com/fa70880b
Ben Shelock
I think your file type/name and content have to be prefixed like the example. 'file_ext[gistfile1]' 'file_name[gistfile1]' 'file_contents[gistfile1]'
Brian Gianforcaro
I changed it but it still didn't work http://pastebin.com/f977d433
Ben Shelock
+3  A: 

The problem with your script is that though you're sending a POST method, you're adding the data in the URL as though it were a GET. I don't use Air so I can't test it, but here the script you linked modified so that I think it should work. You just needed to change xmlhttp.send(NULL) to xmlhttp.send(data), where data is the query data you were appending to the gists URL before (including the file and authentication information).

As a simple example, here's an excerpt from a bash script creating a new gist:

#!/usr/bin/env bash
if [ -z "$(git config github.token)" ]
then echo "warning: no api key found, to add follow instructions on github account page."
else echo "attempting to create a new gist using your github authentication..."; fi

SHA=$((curl http://gist.github.com/gists --include \
       --data login=$(git config github.user) \
       --data token=$(git config github.token) \
       --data action_button=private \
       --data 'file_ext[gistfile1]=txt' \
       --data 'file_contents[gistfile1]=Hello World, this is an example gist!' \
| perl -e 'for(<>){if(/^Location: https?:\/\/gist.github.com\/([0-9a-f]+)/){print $1}}')2>/dev/null)

echo "New example gist created at https://gist.github.com/$SHA"
Jeremy Banks
I don't understand what format the POST data has to be in. Could you explain a little further please.
Ben Shelock
In your original script you had the line: "var url = gists+'?...'". Your post data would be everything I replaced with "...".
Jeremy Banks

related questions