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
[MUSIC] 0:00 Now that you understand the basics of how APIs work, 0:04 we're ready to build a GitHub application with help from a wrapper library. 0:07 The wrapper library will handle the kernel connection to the GitHub API and 0:12 provide an API object for us to work with. 0:17 The main benefit to using a wrapper library is the ease of use when setting up 0:20 a token based authentication, which we'll be doing a little later on. 0:25 The GitHub API documentation links to many third party libraries 0:30 from many different languages. 0:34 I've chosen the GitHub API Easy Access library because of its activity and 0:36 test coverage. 0:40 If you would like more information on choosing a library, 0:41 make sure to check the notes associated with this video. 0:44 Let's open the workspace and try it out. 0:47 Let's start by using the wrapper to do something we're already familiar with. 0:51 We'll pull user information and display the avatar. 0:55 The first thing we need is the wrapper library. 0:59 Let's open the console. 1:02 We run composer require 1:07 milo/github-api. 1:11 Notice that it also installed the bootstrap and 1:26 twig packages because those were already included in the composer.json file. 1:29 Now we can create a new file. 1:35 So let's close the console. 1:37 We'll name this user.php. 1:43 To start off with, we would need to require the auto load file. 1:52 Vendor autoload. 2:02 Then we initiate an API object. 2:06 Next let's add the URL. 2:21 Then we can get the endpoint URL and assign it to a response variable. 2:36 $api->get, and the URL. 2:47 Next we decode those results. 2:53 $user = $api->decode($response); This gives us a user object. 2:59 Finally, we can use that object to display the avatar. 3:09 $user->avatar_url. 3:20 Great, let's preview this in the browser. 3:29 User.php. 3:36 Awesome, we see the avatar again, just like we wanted. 3:41
You need to sign up for Treehouse in order to download course files.Sign up