class NounProjectApi::IconsRetriever

Retrieve icons.

Constants

API_PATH

Public Instance Methods

find(term, limit = nil, offset = nil, page = nil) click to toggle source

Finds multiple icons based on the term

  • term - search term

  • limit - limit the amount of results

  • offset - offset the results

  • page - page number

# File lib/noun_project_api/icons_retriever.rb, line 15
def find(term, limit = nil, offset = nil, page = nil)
  cache_key = Digest::MD5.hexdigest("#{term}+#{limit}+#{offset}+#{page}")
  cache_ttl = NounProjectApi.configuration.cache_ttl

  NounProjectApi.configuration.cache.fetch(cache_key, expires_in: cache_ttl) do
    raise ArgumentError, "Missing search term" unless term

    args = {
      limit_to_public_domain: NounProjectApi.configuration.public_domain ? 1 : 0,
      limit:,
      offset:,
      page:
    }.compact

    result = access_token.get("#{API_BASE}#{API_PATH}#{OAuth::Helper.escape(term)}?#{args.to_query}")
    raise ServiceError.new(result.code, result.body) unless ["200", "404"].include? result.code

    if result.code == "200"
      JSON.parse(result.body, symbolize_names: true)[:icons].map { |icon| Icon.new(icon) }
    else
      []
    end
  end
end
recent_uploads(limit = nil, offset = nil, page = nil) click to toggle source

List recent uploads

  • limit - limit the amount of results

  • offset - offset the results

  • page - page number

# File lib/noun_project_api/icons_retriever.rb, line 44
def recent_uploads(limit = nil, offset = nil, page = nil)
  args = {
    limit:,
    offset:,
    page:
  }.compact

  result = access_token.get("#{API_BASE}#{API_PATH}recent_uploads?#{args.to_query}")
  raise ServiceError.new(result.code, result.body) unless result.code == "200"

  JSON.parse(result.body, symbolize_names: true)[:recent_uploads].map { |icon| Icon.new(icon) }
end