{"size": 1637, "ext": "js", "max_stars_repo_path": "src/actions/index.js", "max_stars_repo_name": "blmalone/coinmarketcap", "max_stars_repo_stars_event_min_datetime": "2018-02-27T11:03:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-03T11:47:19.000Z", "max_issues_repo_path": "src/actions/index.js", "max_issues_repo_name": "blmalone/coinmarketcap", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/actions/index.js", "max_forks_repo_name": "blmalone/coinmarketcap", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 45.4722222222, "max_line_length": 114, "alphanum_fraction": 0.7593158216}
import axios from 'axios';

//Create an action creator that will be responsible for manking an api request.
const API_ENDPOINT_TOP10 = "https://api.coinmarketcap.com/v1/ticker/?limit=10";
const API_ENDPOINT_COIN = "https://api.coinmarketcap.com/v1/ticker/";

export const FETCH_COIN = 'FETCH_COIN';
export const FETCH_TOP_TEN_COINS = 'FETCH_TOP_TEN_COINS';

//Action creators always have to return an action which must always include a propery called 'type'. 
export function fetchCoin(coinName) {
	const url = `${API_ENDPOINT_COIN}${coinName}/`;
	const request = axios.get(url); // this returns a promise - stored in 'request'

	//payoad is an optional property that can go along with actions to contain additional info 
	//by passing a promise in the payload, ReduxPromise middleware will be able to detect that it's a promise
	//and handle the call then return the response to the reducer... allows us to have nice looking code in reducers.
	return {
		type: FETCH_COIN,
		payload: request
	};
}

//Action creators always have to return an action which must always include a propery called 'type'. 
export function fetchTopTenCoins() {
	const url = `${API_ENDPOINT_TOP10}`;
	const request = axios.get(url); // this returns a promise - stored in 'request'

	//payoad is an optional property that can go along with actions to contain additional info 
	//by passing a promise in the payload, ReduxPromise middleware will be able to detect that it's a promise
	//and handle the call then return the response to the reducer... allows us to have nice looking code in reducers.
	return {
		type: FETCH_TOP_TEN_COINS,
		payload: request
	};
}