Skip to content
Permalink
Browse files

Update content and tutorial

  • Loading branch information...
nlaz committed Feb 22, 2019
1 parent 0186a21 commit 7b036d06b64be286358979fedcf9015ace1e1932
@@ -15,8 +15,6 @@ <h2 class="h4 font-weight-light text-gray-light">{% block subtitle %}{% endblock

{% block content %}
<div class="container py-5 my-5" style="max-width: 980px;">
<div class="border rounded p-5">
{% block container %}{% endblock %}
</div>
{% block container %}{% endblock %}
</div>
{% endblock %}

This file was deleted.

@@ -0,0 +1,70 @@
{% extends "guides/base.html" %}
{% from "guides/repo.html" import render_repo with context %}

{% block title %}Requesting Data{% endblock %}
{% block subtitle %}Learn how to retrieve data from GitHub.{% endblock %}

{% block container %}
<h4 class="py-1 m-0">GitHub API</h4>
<p class="mb-5">GitHub provides a way to request and interact with data on its platform. This makes it possible to use GitHub data in your application. For example, you can see all your favorite GitHub projects or show what code you are working. This interaction is done through a interface called an API. We provided examples of using GitHub's API to help you get started.</a>

<div class="border rounded p-5 mb-5">
<h5 class="py-1 m-0">Retrieving your starred projects</h5>
<p>You can retrieve your starred projects on GitHub using the <code>/user/starred</code> endpoint. Within this starter project, you can also use the <code>services/github.py</code> module, which makes it easier to make an authenticated request.<p>
<p>A GET request to the <code>/user/starred</code> endpoint using the <code>github.py</code> module would follow this format:</p>
<pre class="bg-light rounded"><code>
github = GitHub(access_token=session['access_token'])
results = github.get('/user/starred')
</code></pre>
<p class="mt-4">As a result, you will see your starred repositories below:</p>
{% if tutorial1|length == 0 %}
<div class="bg-light rounded p-5 text-center text-muted">
{% if g.user %}
<p class="m-4">You haven't starred any repositories on GitHub yet. You can star <a href="https://github.com/MLH/mlh-hackathon-flask-starter">this project here</a>.</p>
{% else %}
<p class="m-4">This example requires an authenticated user. Please log in to see your starred repositories.</p>
{% endif %}
</div>
{% endif %}

{% for item in tutorial1 %}
{{ render_repo(item, loop) }}
{% endfor %}
</div>

<div class="border rounded p-5">
<h5 class="py-1 m-0">Searching GitHub</h5>
<p>The endpoint for searching GitHub projects is located at <code>/search/repositories</code>. You can use this endpoint to find projects on GitHub. Within this starter project, you also can use the <code>services/github.py</code> module, which makes it easier to make an authenticated request.
<p>A GET request to the <code>/search/repositories</code> endpoint using the <code>github.py</code> module would follow this format:</p>
<pre class="bg-light rounded"><code>
github = GitHub(access_token=session['access_token'])
results = github.get('/search/repositories')
</code></pre>
<p class="mt-4">As a result, you should be able to search for GitHub projects below:</p>
<div class="text-center mx-auto mb-3">
<form action="{{ url_for('guides.requesting') }}" method="get" class="d-flex">
<input name="query" class="form-control form-control-sm" value="{{ query }}" placeholder="Search for repos" />
<button type="submit" class="btn btn-primary btn-sm ml-1">Search</button>
</form>
</div>

{% if tutorial2|length == 0 %}
<div class="rounded bg-light p-5 text-center text-muted">
{% if g.user %}
{% if query or query|length == 0 %}
<p class="m-4">You can use the search bar above to find new projects.</p>
{% else %}
<p class="m-4">Cannot find a repository that matches that input. Please try again.</p>
{% endif %}
{% else %}
<p class="m-4">Please sign in to use the search functionality.</p>
{% endif %}
</div>
{% endif %}

{% for item in tutorial2 %}
{{ render_repo(item, loop) }}
{% endfor %}
</div>

{% endblock %}

This file was deleted.

@@ -17,8 +17,8 @@ <h2 class="h4 text-gray font-weight-light">Build your hackathon project faster.<

{% block content %}
<div class="text-gray-light text-center py-5 my-5">
<p class="lead">Edit <code>views/</code> to update how to receive and reply to requests.</p>
<p class="lead">Edit <code>templates/</code> to update the layout and styling.</p>
<p class="lead">Edit <code>models/</code> to update how the data is stored.</p>
<p class="lead">Edit <code>views/</code> to update the controller layer.</p>
</div>
{% endblock %}
@@ -14,8 +14,7 @@
Tutorials
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ url_for('guides.fetching' )}}">Fetching Data</a>
<a class="dropdown-item" href="{{ url_for('guides.searching' )}}">Searching Data</a>
<a class="dropdown-item" href="{{ url_for('guides.requesting' )}}">Requesting Data</a>
</div>
</li>
{% if g.user %}
@@ -7,15 +7,23 @@

blueprint = Blueprint('guides', __name__, url_prefix='/guides')

@blueprint.route('/fetching')
def fetching():
@blueprint.route('/requesting')
def requesting():
search = request.args.get('query', '')
if not 'access_token' in session:
return render_template('guides/fetching.html')
flash('This tutorial needs an authenticated user to make the request. Please sign in with your GitHub account.', 'danger')
return render_template('guides/requesting.html')

github = GitHub(access_token=session['access_token'])
results = github.get('/user/starred')
results1 = github.get('/user/starred')
results2 = github.get('/search/repositories', { 'q': search } )
results2 = results2.get('items', [])

return render_template('guides/fetching.html', repos=results[:5])
return render_template('guides/requesting.html',
tutorial1 = results1[:5],
tutorial2 = results2[:5],
query = search
)

@blueprint.route('/searching')
def searching():
@@ -27,15 +35,15 @@ def search():

if search is None or search == '':
flash('Please include a valid search query.', 'danger')
return redirect(url_for('guides.searching'))
return redirect(url_for('guides.requesting'))
if not 'access_token' in session:
flash('This example needs an authenticated user to make the request. Please sign in with your GitHub account.', 'danger')
return redirect(url_for('guides.searching'))
return redirect(url_for('guides.requesting'))

github = GitHub(access_token=session['access_token'])
repos = github.get('/search/repositories', { 'q': search } )
starred = github.get('/user/starred')

return render_template('guides/searching.html', repos=repos['items'][:5])
return render_template('guides/requesting.html', starred=repos['items'][:5], query=search)

@blueprint.route('/star', methods=['POST'])
def star():

0 comments on commit 7b036d0

Please sign in to comment.
You can’t perform that action at this time.