Manipulating Files with the GitHub API Gem
Oct 6th, 2013
I’ve been building an application, that is for creating, managing and organizing all those little bits of code you have floating around in your brain. Every piece of knowledge you save within the application gets saved to GitHub in your own personal repository.
I’m using two different Gems to interact with the GitHub API. I’m using the GitHub API Gem by Piotr Murach, as well as the Octokit gem which is maintained by GitHub. Most of the interaction I’m doing with the GitHub API is with Piotr’s gem, however the Octokit gem has new features implemented faster.
A pivotal piece of this application, is the ability to create, remove, and update files. So being more comfortable with Pitor’s gem, I decided to use it for the file manipulation.
I was able to find some documentation in the Github repo outlining how to create a file. However, as it turns out, the documentation is very dated.
So I took matters into my own hands and looked at the source code to figure out what’s going on. Finally after hours of banging my head against the wall, I found the solution I was looking for.
My gift to you, is what you need to create/update/remove a file using Pitor Murach’s Github_API Gem.
All Methods use the Github Repo Contents method to interact with the Repo Contents API
1 2 3
Creating a File
1 2 3 4 5
Update a File
1 2 3 4 5 6 7 8
Removing a File
1 2 3 4 5 6 7
There you have it. I plan to send in a pull-request to update the documentation. Hope this saves someone some time.