@@ -0,0 +1,2152 @@
+from hammock import Hammock as Github%0Aimport json%0Aimport base64%0Afrom pprint import pprint%0A%0A# Let's create the first chain of hammock using base api url%0Agithub = Github('https://api.github.com')%0A%0Auser = 'holtzermann17'%0A# In the future this will be running on a server%0A# somewhere, so password can just be hard coded%0Apassword = raw_input(%22Enter your github password: %22)%0Arepo = 'py-blot'%0A%0A# The most interesting things for us are in this part of the API%0A# https://developer.github.com/v3/repos/contents/%0A%0A# get the contents of a given file, the README in this case%0Aresp = github.repos(user, repo).contents.GET('README.md')%0A%0A# examine the file we retrieved,%0A# here's how to have a look at everything:%0A#pprint(vars(resp))%0A# And from that, the most interesting part(s) can be extracted:%0Atext = base64.b64decode(json.loads(resp._content)%5B'content'%5D)%0A# (we will need the sha later)%0Asha = json.loads(resp._content)%5B'sha'%5D%0A%0Aprint text%0A%0A# Now to further explore the API, let's loop back and%0A# update the file.  Let's prompt the user to add%0A# some text to the file.%0A%0Adelta = raw_input(%22Add text: %22)%0A%0Anewtext = ''.join(%5Btext, '%5Cn', delta%5D) %0A%0Anewcontent = base64.b64encode(newtext)%0A#message = base64.b64encode()%0A%0Adata=%7B'message':'Adding %22'+text+'%22.',%0A      'committer':%7B'name':'Joe Corneli',%0A                   'email':'holtzermann17@gmail.com'%7D,%0A      'content':newcontent,%0A      'sha':sha,%0A      'branch':'master'%7D%0A%0A# Forming the correct URL (by following the instructions from Hammock docs!)%0A# In particular, we need to specify the :path as part of the url, whereas%0A# other arguments are passed along as a JSON body%0Aresptwo = github.repos(user, repo).contents('README.md').PUT(%0A    auth=(user, password),%0A    headers = %7B'Content-type': 'application/json'%7D,%0A    data=json.dumps(data))%0A%0Apprint(vars(resptwo))%0A%0A# Here's how to do something similar with curl:%0A%0A# curl -i -X PUT -H 'Authorization: %3Ctoken%3E' -d '%7B%22path%22: %22test4.txt%22, %22message%22: %22Initial Test%22, %22committer%22: %7B%22name%22: %22Joe Corneli%22, %22email%22: %22holtzermann17@gmail.com%22%7D, %22content%22: %22bXkgbmV3IGZpbGUgY29udGVudHM=%22, %22branch%22: %22master%22%7D' https://api.github.com/repos/holtzermann17/py-blot/contents/test4.txt%0A

Add a proof of concept for reading and writing from github api