Code coverage report for code/utils/open-clipart.coffee

Statements: 0% (0 / 15)      Branches: 0% (0 / 2)      Functions: 0% (0 / 2)      Lines: 0% (0 / 10)      Ignored: none     

All files » code/utils/ » open-clipart.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                                                 
initialResultSize = 12
 
module.exports = OpenClipArt =
 
  jqXHR: null
 
  search: (query, options, callback) ->
    # abort the last request
    OpenClipArt.jqXHR?.abort()
 
    url = "https://openclipart.org/search/json/?query=#{encodeURIComponent query}&sort=downloads&amount=#{if options.limitResults then initialResultSize else 200}" # 200 is max amount for api
    OpenClipArt.jqXHR = $.getJSON url, (data) ->
      results = []
      numMatches = Math.min(parseInt(data?.info?.results or '0', 10), 200)
      for item in data?.payload
        results.push
          image: item.svg.png_thumb
          metadata:
            source: 'search'
            title: item.title
            description: item.description
            link: item.detail_link
      callback results, numMatches