Contents API
As opposed to the 2 Git Data API, this part of the binding provides a high-level way of reading, creating, updating and deleting files. The classes that are involved are GHRepository
and GHContent
. The four different use-cases are explained in the sections below.
3.1. Get file contents
To get the contents of a file, one can send the following messages to an instance of GHRepository
:
getContentAtPath:
- Returns an instance of
GHContent
which contains the file contents of the file at the given path. getContentAtPath:atRef:
- Same as above, but returns the file at the given version (can be a commit name, branch name or tag name).
3.2. Create a file
Use GHRepository
>>
createContent:onPath:withMessage:
, with the parameters being the content of the file, the path of the file, and the commit message (all being instances of String
).
3.3. Update a file
Use GHContent
>>
updateContent:withMessage:
, with similar parameters as with the method to create files. This method updates the same instance with the new content information, thus it is possible to send updateContent:withMessage:
multiple times.
Moreover, it returns the GHGitCommit
object representing the commit of the change. Thus from here it is possible to switch to using the 2 Git Data API and create commits with the returned GHGitCommit
object as parent.
3.4. Delete a file
Use GHContent
>>
deleteContentWithMessage:
. Like updateContent:withMessage:
, this method returns a GHGitCommit
instance.