Measurement of the differential cross-sections of prompt and non-prompt production of J/\psi and \psi (2\mathrm {S}) in pp collisions at \sqrt{s} = 7 and 8 TeV with the ATLAS detector