diff --git a/app.js b/app.js index 24f80a1..facbe01 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,8 @@ -var apiKey = 'insert you key here' -var baseUrl = 'https://api.pearson.com/longman/dictionary/0.1'; -var dataFmt = '.json'; -var searchUrl = baseUrl + '/entry' + dataFmt; +var apiKey = 'insert you key here'; +var keyData = '';// 'apiKey=' + apiKey; +var baseUrl = 'https://api.pearson.com/v2/dictionaries/ldoce5'; +var dataFmt = ''; +var searchUrl = baseUrl + '/entries' + dataFmt; var debugLog; function init(){ @@ -15,7 +16,8 @@ function init(){ function doSearch(searchFor){ debugLog.append('Looking up ' + searchFor + ' using ' + searchUrl + '
'); - var data = 'apikey=' + apiKey + '&q=' + searchFor + // Use double quotation marks to handle words e.g. yes-man + var data = keyData + '&headword=' + '"' + searchFor + '"'; $.ajax({ type: 'GET', url: searchUrl, @@ -34,7 +36,7 @@ function doSearch(searchFor){ function handleResponse(data){ debugLog.append('Response received
'); - var results = data.Entries.Entry; + var results = data.results; var html = entry(results); $('#resultList').html(html); $('li>a').click(function(){ @@ -53,18 +55,18 @@ function entry(from){ html += entry(from[idx]); } } else { - debugLog.append("Processing Entry: " + from.Head.HWD['#text'] + '
'); + debugLog.append("Processing Entry: " + from.headword + '
'); html += '
  • '; - html += from.Head.HWD['#text']; + html += from.headword; html += '
    '; if ($(from).hasAttr('multimedia')) { html += multimedia(from.multimedia); } html += '
      '; - html += sense(from.Sense); + html += sense(from.senses); html += '
    '; html += '
  • \n'; - debugLog.append("
    Processed Entry: " + from.Head.HWD['#text'] + '
    '); + debugLog.append("
    Processed Entry: " + from.headword + '
    '); } return html; } @@ -98,9 +100,9 @@ function multimedia(from){ break; } if (mm_href.match(/\.mp3$/)) { - html = mm_type + ' '; + html = mm_type + ' '; } else if (mm_type == 'DVD_PICTURES') { - html = ' '; + html = ' '; } html += '
    '; } @@ -118,9 +120,9 @@ function sense(from){ } else if ($(from).hasAttr('Subsense')) { html += sense(from.Subsense); } else { - html += '
  • ' + text(from.DEF) + '
    '; - if ($(from).hasAttr('EXAMPLE')){ - html += example(from.EXAMPLE); + html += '
  • ' + from.definition + '
    '; + if ($(from).hasAttr('examples')){ + html += example(from.examples); } else if ($(from).hasAttr('LEXUNIT')){ html += example(from.LEXUNIT); } @@ -150,7 +152,7 @@ function example(from){ function text(from){ debugLog.append('text '); var result = ''; - var text = from['#text']; + var text = from.text; var nonDv; var hasNonDv = $(from).hasAttr('NonDV'); if ($.isArray(text)){