'use strict'

import api from '../services/api'

import {
  RANKINGS_REQUEST,
  RANKINGS_SUCCESS,
  RANKINGS_ERROR
} from './../constants'

function rankingsRequest() {
  return {
    type: RANKINGS_REQUEST
  }
}

function rankingsSuccess(data) {
  return {
    type: RANKINGS_SUCCESS,
    data
  }
}

function rankingsError(err) {
  return {
    type: RANKINGS_ERROR,
    err
  }
}

function fetchRankings(params = { country: 'BR', state: undefined, city: undefined }) {
  return dispatch => {
    dispatch(rankingsRequest())

    return api({
      url: '/rankings',
      params: {
        country: params.country,
        state: params.state,
        city: params.city
      }
    })
    .then(res => dispatch(rankingsSuccess(res)))
    .catch(err => dispatch(rankingsError(err)))
  }
}

export default fetchRankings

@@ -459,16 +459,29 @@
 ndefined
+, limit = 300
  %7D) %7B%0A  
@@ -678,16 +678,45 @@
 ams.city
+,%0A        limit: params.limit
 %0A      %7D

Fix Limit