Skip to content
Snippets Groups Projects
Commit 8d4acba0 authored by Shreya Sharma's avatar Shreya Sharma
Browse files

Merge branch 'master' into 'assignment-3.2'

# Conflicts:
#   App.js
parents 8263ccac b7df067b
No related branches found
No related tags found
3 merge requests!6Updated Assignment 3.2,!5Partially Completed Assignment 3.2,!4Partially Completed Assignment 3.2
Showing
with 97 additions and 231 deletions
import React from 'react'
import { createStackNavigator } from 'react-navigation';
import { AuthSession } from 'expo'
import Profile from './react_components/page_components/Profile';
import Notifications from './react_components/page_components/Notifications';
import Repositories from './react_components/page_components/Repositories';
......@@ -8,39 +9,34 @@ import Following from './react_components/page_components/Following';
console.disableYellowBox = true;
const base_auth_url = "https://github.com/login/oauth/authorize";
const HomePage = createStackNavigator(
{
Profile: {
screen: Profile,
navigationOptions: ({ navigation }) => ({
headerMode: 'none',
headerTransparent: true
}),
},
Repositories: {
screen: Repositories,
navigationOptions: ({ navigation }) => ({
title: 'Repositories',
}),
},
Notifications: {
screen: Notifications,
navigationOptions: ({ navigation }) => ({
title: 'Notifications',
}),
},
Followers: {
screen: Followers,
navigationOptions: ({ navigation }) => ({
title: 'Followers',
}),
},
Following: {
screen: Following,
navigationOptions: ({ navigation }) => ({
title: 'Following',
}),
}
Profile: {
screen: Profile,
navigationOptions: ({ navigation }) => ({
headerMode: 'none',
headerTransparent: true
}),
},
Repositories: {
screen: Repositories,
navigationOptions: ({ navigation }) => ({
title: 'Repositories',
}),
},
Followers: {
screen: Followers,
navigationOptions: ({ navigation }) => ({
title: 'Followers',
}),
},
Following: {
screen: Following,
navigationOptions: ({ navigation }) => ({
title: 'Following',
}),
}
},
{
initialRouteName: 'Profile',
......@@ -54,6 +50,17 @@ export default class App extends React.Component
this.state = {};
}
authorizeOAuth = async () => {
let redirectUrl = AuthSession.getRedirectUrl()
let result = await AuthSession.startAsync({
authUrl:
base_auth_url +
`&client_id=1f161604092bb84609dd` +
`&redirect_uri=${encodeURIComponent(redirectUrl)}`,
}).then(res => console.log(res));
this.setState({ result })
};
render() {
return (
<HomePage/>
......
const axios = require('axios');
const base_api_url = 'https://api.github.com';
const accessToken = 'access_token=71f1e4e711a6a25922369ff3f847485c8866fd24&scope=notifications%2Cpublic_repo%2Cuser&token_type=bearer';
const username = 'shreyasharmaxo'
// Collect and parse user's profile information
exports.getProfileInfo =
function() {
function(username) {
return axios.get(base_api_url + '/users/' + username)
.then(function(res) {
return parseProfileInfo(res.data);
......@@ -24,8 +22,7 @@ function parseProfileInfo(info) {
'email': 'shreya.sharma4697@gmail.com',
'repositories': info.public_repos,
'followers': info.followers,
'following': info.following,
'avatar': info.avatar_url
'following': info.following
}
return parsedProfile;
......@@ -33,7 +30,7 @@ function parseProfileInfo(info) {
// Collect and parse user's repository information
exports.getRepoInfo =
function() {
function(username) {
return axios.get(base_api_url + '/users/' + username + '/repos')
.then(function(res) {
return parseRepoInfo(res.data);
......@@ -48,28 +45,19 @@ function parseRepoInfo(info) {
for (r of info) {
parsedRepositories.push({
'name': r.name,
'owner': r.owner.login,
'description': r.description,
'url': r.html_url
'name': r.name,
'owner': r.owner.login,
'description': r.description,
'url': r.html_url
});
}
return parsedRepositories;
}
// Collect and parse user's notification information
exports.getNotificationInfo =
function () {
return axios.get(base_api_url + '/notifications?' + accessToken)
.then(function(res) {
return res.data;
})
}
// Collect and parse user's follower/following information
exports.getFollowersInfo =
function() {
function(username) {
return axios.get(base_api_url + '/users/' + username + '/followers')
.then(function(res) {
return parseFollowInfo(res.data);
......@@ -80,7 +68,7 @@ function() {
}
exports.getFollowingInfo =
function() {
function(username) {
return axios.get(base_api_url + '/users/' + username + '/following')
.then(function(res) {
return parseFollowInfo(res.data);
......@@ -96,45 +84,11 @@ function parseFollowInfo(info) {
for (f of info) {
parsedFollows.push(
{
'username': f.login,
'avatar': f.avatar_url,
'url': f.html_url
'username': f.login,
'avatar': f.avatar_url,
'url': f.html_url
});
}
return parsedFollows;
}
// Follow/Unfollow a user
exports.followUser =
function (userToFollow) {
return axios.put(base_api_url + '/user/following/' + userToFollow + accessToken)
.catch(function(err) {
console.log(err);
});
}
exports.unfollowUser =
function (userToUnfollow) {
return axios.delete(base_api_url + '/user/following/' + userToUnfollow + accessToken)
.catch(function(err) {
console.log(err);
});
}
// Follow/Unfollow a user
exports.starRepo =
function (owner, repoToStar) {
return axios.put(base_api_url + '/user/starred/' + owner + '/' + repoToStar + accessToken)
.catch(function(err) {
console.log(err);
});
}
exports.unStarRepo =
function (owner, repoToUnstar) {
return axios.delete(base_api_url + '/user/starred/' + owner + '/' + repoToUnstar + accessToken)
.catch(function(err) {
console.log(err);
});
}
assets/blank_profile.png

21.6 KiB

<svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M13.99 11.991v1H0v-1l.73-.58c.769-.769.809-2.547 1.189-4.416.77-3.767 4.077-4.996 4.077-4.996 0-.55.45-1 .999-1 .55 0 1 .45 1 1 0 0 3.387 1.229 4.156 4.996.38 1.879.42 3.657 1.19 4.417l.659.58h-.01zM6.995 15.99c1.11 0 1.999-.89 1.999-1.999H4.996c0 1.11.89 1.999 1.999 1.999z"/></svg>
\ No newline at end of file
assets/profile_picture.jpg

37.4 KiB

......@@ -26,9 +26,6 @@ export default class ContentBlock extends React.Component
case 'email':
source = require('../../assets/icons/mail.svg');
break;
case 'bell':
source = require('../../assets/icons/bell.svg');
break;
case 'repo':
source = require('../../assets/icons/git-branch.svg');
break;
......
import React from 'react';
import { View, Image, Dimensions } from 'react-native';
//Helper component to display Profile Picture information
export default class Picture extends React.Component
{
constructor(properties) {
super(properties);
this.state = {};
}
render() {
return (
<View>
<Image
style={{width: Dimensions.get('window').width, height: Dimensions.get('window').width}}
source={require('../../assets/profile_picture.jpg')}
/>
</View>
);
}
}
const axios = require('axios')
const base_api_url = 'https://api.github.com';
const accessToken = 'access_token=71f1e4e711a6a25922369ff3f847485c8866fd24&scope=notifications%2Cpublic_repo%2Cuser&token_type=bearer';
// Define Variables //
// Username
const userToFollow = 'ananyacleetus'
axios.put(base_api_url + '/user/following/' + userToFollow + accessToken)
.catch(function(err) {
console.log(err);
});
......@@ -3,6 +3,7 @@ import { ScrollView, TouchableHighlight, Linking } from 'react-native';
import UserBlock from '../helper_components/UserBlock';
const githubapi = require('../../api/github_api')
const user = 'shreyasharmaxo';
//Component to display Followers information
......@@ -14,11 +15,11 @@ export default class Followers extends React.Component
'followers': []
};
this.loadUserProfile();
this.loadUserProfile(user);
}
loadUserProfile() {
return githubapi.getFollowersInfo()
loadUserProfile(github_username) {
return githubapi.getFollowersInfo(github_username)
.then(followersData => {
this.setState({'followers': followersData});
});
......
import React from 'react';
import { Linking, ScrollView, TouchableHighlight } from 'react-native';
import { Linking, View, ScrollView, TouchableHighlight } from 'react-native';
import UserBlock from '../helper_components/UserBlock';
const githubapi = require('../../api/github_api')
const user = 'shreyasharmaxo';
//Component to display Following information
......@@ -11,14 +12,15 @@ export default class Following extends React.Component
constructor(props) {
super(props);
this.state = {
'following': []
'following': [],
'tok': '***'
};
this.loadUserProfile();
this.loadUserProfile(user);
}
loadUserProfile() {
return githubapi.getFollowingInfo()
loadUserProfile(github_username) {
return githubapi.getFollowingInfo(github_username)
.then(followingInfo => {
this.setState({'following': followingInfo});
});
......
import React from 'react';
import { ScrollView, TouchableHighlight } from 'react-native';
import ContentBlock from '../helper_components/ContentBlock';
const githubapi = require('../../api/github_api')
//Component to display Notification information
export default class Notifications extends React.Component
{
constructor(props) {
super(props);
this.state = {
'notifications': []
};
this.loadUserProfile();
}
loadUserProfile() {
return githubapi.getNotificationInfo()
.then(notificationInfo => {
this.setState({'notifications': notificationInfo});
});
}
render() {
return (
<ScrollView>
{this.state.notifications.map((notification, index) => (
<TouchableHighlight key={index} underlayColor='#FFAAEE'>
<ContentBlock iconType='bell' title={notification.repository.name} content={notification.subject.title}/>
</TouchableHighlight>
))}
</ScrollView>
);
}
}
import React from 'react'
import { View, Image, ScrollView, TouchableHighlight, Dimensions } from 'react-native'
import { ScrollView, TouchableHighlight, Dimensions } from 'react-native'
import ProfilePicture from '../helper_components/ProfilePicture'
import ContentBlock from '../helper_components/ContentBlock'
const githubapi = require('../../api/github_api')
const user = 'shreyasharmaxo';
//Component to display Profile information
......@@ -18,20 +20,19 @@ export default class Profile extends React.Component
'email': '',
'repositories': '',
'followers': '',
'following': '',
'avatar': ''
},
'following': ''
},
'screen': {
'height': 10,
'width': 0
}
};
this.loadUserProfile();
this.loadUserProfile(user);
}
loadUserProfile () {
return githubapi.getProfileInfo()
loadUserProfile (github_username) {
return githubapi.getProfileInfo(github_username)
.then(profileInfo => {
this.setState({'profileInfo': profileInfo});
});
......@@ -41,10 +42,6 @@ export default class Profile extends React.Component
this.props.navigation.navigate('Repositories');
}
onPressNotifications() {
this.props.navigation.navigate('Notifications');
}
onPressFollowers() {
this.props.navigation.navigate('Followers');
}
......@@ -58,28 +55,10 @@ export default class Profile extends React.Component
}
render() {
let displayAvatar = {}
if (this.state.profileInfo.avatar === "")
{
displayAvatar = require('../../assets/blank_profile.png')
}
else {
displayAvatar = {
uri: this.state.profileInfo.avatar
}
}
return (
<ScrollView onLayout={ this.orientation }>
<View>
<Image
style={{width: Dimensions.get('window').width, height: Dimensions.get('window').width}}
source={ displayAvatar }
/>
</View>
<ProfilePicture/>
<ContentBlock iconType='person' title='Name' content={this.state.profileInfo.name}/>
<ContentBlock iconType='github' title='Username' content={this.state.profileInfo.username}/>
......@@ -89,9 +68,6 @@ export default class Profile extends React.Component
<TouchableHighlight onPress={() => this.onPressRepositories()} underlayColor='#FFAAEE'>
<ContentBlock iconType='repo' title='Repositories' content={this.state.profileInfo.repositories}/>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.onPressNotifications()} underlayColor='#FFAAEE'>
<ContentBlock iconType='bell' title='Notifications'/>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.onPressFollowers()} underlayColor='#FFAAEE'>
<ContentBlock iconType='group' title='Followers' content={this.state.profileInfo.followers}/>
</TouchableHighlight>
......
......@@ -3,6 +3,7 @@ import { Linking, ScrollView, TouchableHighlight } from 'react-native';
import ContentBlock from '../helper_components/ContentBlock';
const githubapi = require('../../api/github_api')
const user = 'shreyasharmaxo';
//Component to display Repository information
......@@ -14,11 +15,11 @@ export default class Profile extends React.Component
'repositories': []
};
this.loadUserProfile();
this.loadUserProfile(user);
}
loadUserProfile() {
return githubapi.getRepoInfo()
loadUserProfile(github_username) {
return githubapi.getRepoInfo(github_username)
.then(repoInfo => {
this.setState({'repositories': repoInfo});
});
......
const axios = require('axios')
const base_api_url = 'https://api.github.com';
const accessToken = 'access_token=71f1e4e711a6a25922369ff3f847485c8866fd24&scope=notifications%2Cpublic_repo%2Cuser&token_type=bearer';
// Define Variables //
// Username
const owner = 'shreyasharmaxo'
// Repository
const repoToStar = 'TwitterBots'
axios.put(base_api_url + '/user/starred/' + owner + '/' + repoToStar + accessToken)
.catch(function(err) {
console.log(err);
});
\ No newline at end of file
const axios = require('axios')
const base_api_url = 'https://api.github.com';
const accessToken = 'access_token=71f1e4e711a6a25922369ff3f847485c8866fd24&scope=notifications%2Cpublic_repo%2Cuser&token_type=bearer';
// Define Variables //
// Username
const userToUnfollow = 'ananyacleetus'
axios.delete(base_api_url + '/user/following/' + userToUnfollow + accessToken)
.catch(function(err) {
console.log(err);
});
const axios = require('axios')
const base_api_url = 'https://api.github.com';
const accessToken = 'access_token=71f1e4e711a6a25922369ff3f847485c8866fd24&scope=notifications%2Cpublic_repo%2Cuser&token_type=bearer';
// Define Variables //
// Username
const owner = 'shreyasharmaxo'
// Repository
const repoToUnstar = 'TwitterBots'
axios.delete(base_api_url + '/user/starred/' + owner + '/' + repoToUnstar + accessToken)
.catch(function(err) {
console.log(err);
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment