GithubHelp home page GithubHelp logo

github-repo-starring's Introduction

Star Github Repo

Personal Access Tokens

Most of the API interaction we've been doing so far has been authorized using client IDs and secrets, which lets API calls act on behalf of an application. For this lab, though, we're going to be starring and unstarring Github repositories, which only makes sense if done on behalf of a user. In a few days, we'll see how to do this with OAuth. But for now, we're going to use a personal access token from Github's website.

In the settings section of Github's website, go to "Personal access tokens" and then "Generate new token". Give the token some name (say, "FIS Labs" or something). You then need to specify the permissions you grant someone with this token. For this lab, granting just public_repo should be sufficient.

Once you click "Generate token", you'll see your personal access token one time and one time only. Be sure to copy it before leaving the page. We're going to store it in a file in our project.

The Constants File

We've gone ahead and brought in code that fetches the list of public repositories from Github and displays it in a table view. To get that code working, you'll need to create the FISConstants.m file add your client ID, secret, and personal access token to it, in a format like this:

NSString *const GITHUB_CLIENT_ID = @"your app ID";
NSString *const GITHUB_CLIENT_SECRET = @"your app secret";

NSString *const GITHUB_AUTH_TOKEN = @"your personal access token";

This is how the exising API client builds URLs for talking to the API; check out the API client to see the details. It's good practice to put your constants into one file like this so they can be changed easily and not committed to Git.

Once you've set up your constants .m file, run the app to make sure the table view is being populated correctly.

Goal

We want to be able to tap on repos in the table view and have it star or unstar the repository appropriately, using Github's API. You can see the overview of the relevant API calls here.

Instructions

  1. Create the method in FISGithubAPIClient called isRepositoryStarred:completion: that accepts a repo full name (e.g. githubUser/repoName) and checks to see if it is currently starred. The completion block should take a boolean (true for starred, false otherwise). Checkout the Github Documentation on how this works on the API side. - Keep in mind that since this action needs to know which user is doing the starring, it will have to be passed the access token. You can do that by adding an access_token parameter in the query string of the URL. The same is true for all the remaining API calls in this lab.
  2. Make a method in FISGithubAPIClient that stars a repo given its full name. Checkout the Github Documentation.
  3. Make a method in FISGithubAPIClient that unstars a repo given its full name. Checkout the Github Documentation.
  4. Create a method in FISReposDataStore that, given a FISGithubRepository object, checks to see if it's starred or not and then either stars or unstars the repo. That is, it should toggle the star on a given repository. In the completion block, there should be a BOOL parameter called starred that is YES if the repo was just starred, and NO if it was just unstarred.
  5. Finally, when a cell in the table view is selected, it should call your FISReposDataStore method to toggle the starred status and display a UIAlertController saying either "You just starred " or "You just unstarred ".

View Star Github Repo on Learn.co and start learning to code for free.

github-repo-starring's People

Contributors

fislabstest avatar ipc103 avatar jimcampagno avatar misterfifths avatar sarogers avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

github-repo-starring's Issues

verify Github Auth

Github has changed its permission to require verified email addresses. Verify that the auth token still works. Ideally students should use their own OAuth tokens.

tests need to be updated

API methods have their completion blocks be void void when we're teaching them to write them void bool. Fortunately most students end up commenting out the tests instead of writing the methods incorrectly, but we should update them

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.