summaryrefslogtreecommitdiff
path: root/src/redux/github/actions.js
diff options
context:
space:
mode:
authorKamran Ahmed <kamranahmed.se@gmail.com>2018-08-19 21:58:30 +0400
committerKamran Ahmed <kamranahmed.se@gmail.com>2018-08-19 21:58:30 +0400
commit02614f5ee9c6ad3389a7d43bdbeba6ec6e88659b (patch)
treee9df96aa2e47f070b2f5c13143adcc9da14bdf6a /src/redux/github/actions.js
parentSeparate loading component (diff)
downloadgithunt-02614f5ee9c6ad3389a7d43bdbeba6ec6e88659b.tar.gz
Add axios and reducer for github
Diffstat (limited to 'src/redux/github/actions.js')
-rw-r--r--src/redux/github/actions.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js
new file mode 100644
index 0000000..2db93ce
--- /dev/null
+++ b/src/redux/github/actions.js
@@ -0,0 +1,33 @@
+import axios from 'axios';
+
+import {
+ FETCH_TRENDING_FAILED,
+ FETCH_TRENDING_SUCCESS,
+ PROCESS_FETCH_TRENDING
+} from './types';
+
+const API_URL = 'https://api.github.com/search/repositories';
+
+/**
+ * @param {object} filters
+ * @returns {Function}
+ */
+export const fetchTrending = function (filters) {
+ return dispatch => {
+ dispatch({ type: PROCESS_FETCH_TRENDING });
+
+ axios.get(API_URL, {
+ params: filters
+ }).then(response => {
+ dispatch({
+ type: FETCH_TRENDING_SUCCESS,
+ payload: response.data
+ });
+ }).catch(error => {
+ dispatch({
+ type: FETCH_TRENDING_FAILED,
+ payload: error
+ });
+ });
+ };
+};