I wanted to automatically retrieve an xml file (phpunit junit log) from a travis server.
I don't know why but rsync and scp failed so I assumed I could post it to pastebin but the pulbic api shut down years ago.
So I tried with github and gist...
I have 2 factor authentication... and I wanted an easy easy way to do things so I finally found the option to create a token password with limited scope. And that's awesome and easy.
- Go to your account and create a secret token with limited scope (check only gist)
- Copy and store the token value (you will not be able to see it after a while)
- Now you can try in command line the token
curl -u username:token https://api.github.com/user
- The limit is the JSON, so you will have to put your file in json. I used the following php script with php -a
$content=file_get_contents("log/test.xml");
$topost = ["description"=>"test xml","public"=>false,"files"=>["test.xml"=>["content"=>""]]];
$topost["files"]["test.xml"]["content"]=$content;
file_put_contents("log/test.xml.gist.json",json_encode($topost));
It will create the log/test.xml.gist.json file that contains the payload that will create a gists:
- private
- with the description: text xml
- with a file: text.xml
- that contains: the xml generated by phpunit
Now it's time to push it to gists.
Just follow the gist api
curl -u username:**token** -d @log/test.xml.gist.json https://api.github.com/gists
That's all Folk!