SHOW:
|
|
- or go back to the newest paste.
| 1 | get '/anagrams/:word' do | |
| 2 | content_type :json | |
| 3 | errors = [] | |
| 4 | if settings.lexicon.is_word?(params[:word]) | |
| 5 | anagram_list = settings.lexicon.get_anagrams(params[:word]) | |
| 6 | return [200, {'data': anagram_list, 'error': []}].to_json unless anagram_list.empty?
| |
| 7 | errors.push('That word has no anagrams. Try another word?')
| |
| 8 | return [200, {'data': [], 'error': errors}].to_json
| |
| 9 | else | |
| 10 | errors.push('There is no such word in our lexicon. Try another word?')
| |
| 11 | return [404, {'data': [], 'error': errors}].to_json
| |
| 12 | end | |
| 13 | end |