Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Using a Wrapper3:44 with Alena Holligan
The GitHub Easy Access wrapper library will handle the cURL connection to the GitHub API and provide an API object for us to work with. We'll compare the use of a wrapper library to using cURL directly when retrieving information.
Evaluating a Package
Here are some things to consider when choosing a package for your project.
- Written by a respected group such as:
- Includes a License (Learn about Open Source Licenses)
- Distributed via Composer on Packagist
- Test Coverage.
- Follows a coding standard.
- Has good documentation (both instructions for using the package and well documented code).
- Number of Contributors
- Large Install Base
- Uses Semantic Versioning
- Good Change Log
- Welcomes Contributions
Specifically for people writing packages, but has a good explanation phppackagechecklist.com
Now that you understand the basics of how APIs work,
we're ready to build a GitHub application with help from a wrapper library.
The wrapper library will handle the kernel connection to the GitHub API and
provide an API object for us to work with.
The main benefit to using a wrapper library is the ease of use when setting up
a token based authentication, which we'll be doing a little later on.
The GitHub API documentation links to many third party libraries
from many different languages.
I've chosen the GitHub API Easy Access library because of its activity and
If you would like more information on choosing a library,
make sure to check the notes associated with this video.
Let's open the workspace and try it out.
Let's start by using the wrapper to do something we're already familiar with.
We'll pull user information and display the avatar.
The first thing we need is the wrapper library.
Let's open the console.
We run composer require
Notice that it also installed the bootstrap and
twig packages because those were already included in the composer.json file.
Now we can create a new file.
So let's close the console.
We'll name this user.php.
To start off with, we would need to require the auto load file.
Then we initiate an API object.
Next let's add the URL.
Then we can get the endpoint URL and assign it to a response variable.
$api->get, and the URL.
Next we decode those results.
$user = $api->decode($response); This gives us a user object.
Finally, we can use that object to display the avatar.
Great, let's preview this in the browser.
Awesome, we see the avatar again, just like we wanted.
You need to sign up for Treehouse in order to download course files.Sign up