Skip to content

Commit

Permalink
feat: Update server url and allow customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Hu Chen committed Apr 20, 2020
1 parent 5619cc0 commit 9013030
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Receive an array of trending repositories.

**URL Endpoint:**

https://github-trending-api.now.sh/repositories?language=javascript&since=weekly
https://ghapi.huchen.dev/repositories?language=javascript&since=weekly

**Parameters:**

Expand Down Expand Up @@ -151,7 +151,7 @@ Receive an array of trending developers.

**URL Endpoint:**

https://github-trending-api.now.sh/developers?language=javascript&since=weekly
https://ghapi.huchen.dev/developers?language=javascript&since=weekly

**Parameters:**

Expand Down Expand Up @@ -183,7 +183,7 @@ https://github-trending-api.now.sh/developers?language=javascript&since=weekly

**URL Endpoint:**

https://github-trending-api.now.sh/languages
https://ghapi.huchen.dev/languages

**Response:**

Expand Down Expand Up @@ -212,7 +212,7 @@ https://github-trending-api.now.sh/languages

**URL Endpoint:**

https://github-trending-api.now.sh/spoken_languages
https://ghapi.huchen.dev/spoken_languages

**Response:**

Expand Down
2 changes: 1 addition & 1 deletion apiary.apib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FORMAT: 1A
HOST: https://github-trending-api.now.sh/
HOST: https://ghapi.huchen.dev/

# GitHub Trending API

Expand Down
22 changes: 13 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sample, sampleSize, snakeCase } from 'lodash';
import languages from './languages.json';
import spokenLanguages from './spoken-languages.json';

const SERVER_URL = 'https://github-trending-api.now.sh';
const SERVER_URL = 'https://ghapi.huchen.dev';

function buildUrl(baseUrl, params = {}) {
const queryString = Object.keys(params)
Expand All @@ -20,30 +20,34 @@ function checkResponse(res) {
}
}

export async function fetchRepositories(params) {
const res = await axios(buildUrl(`${SERVER_URL}/repositories`, params));
export async function fetchRepositories(params, serverUrl = SERVER_URL) {
const res = await axios(buildUrl(`${serverUrl}/repositories`, params));
checkResponse(res);

return res.data;
}

export async function fetchDevelopers(params) {
const res = await axios(buildUrl(`${SERVER_URL}/developers`, params));
export async function fetchDevelopers(params, serverUrl = SERVER_URL) {
const res = await axios(buildUrl(`${serverUrl}/developers`, params));
checkResponse(res);

return res.data;
}

export async function fetchRandomRepository(params) {
const res = await axios(buildUrl(`${SERVER_URL}/repositories`, params));
export async function fetchRandomRepository(params, serverUrl = SERVER_URL) {
const res = await axios(buildUrl(`${serverUrl}/repositories`, params));
checkResponse(res);

const json = res.data;
return sample(json);
}

export async function fetchRandomRepositories(size = 1, params) {
const res = await axios(buildUrl(`${SERVER_URL}/repositories`, params));
export async function fetchRandomRepositories(
size = 1,
params,
serverUrl = SERVER_URL
) {
const res = await axios(buildUrl(`${serverUrl}/repositories`, params));
checkResponse(res);

const json = res.data;
Expand Down

0 comments on commit 9013030

Please sign in to comment.