Class: NounProjectApi::IconsRetriever
- Defined in:
- lib/noun_project_api/icons_retriever.rb
Overview
Retrieve icons.
Constant Summary collapse
- API_PATH =
"/icons/"
Instance Attribute Summary
Attributes included from Connection
#access_token, #secret, #token
Instance Method Summary collapse
-
#find(term, limit = nil, offset = nil, page = nil) ⇒ Object
Finds multiple icons based on the term * term - search term * limit - limit the amount of results * offset - offset the results * page - page number.
-
#recent_uploads(limit = nil, offset = nil, page = nil) ⇒ Object
List recent uploads * limit - limit the amount of results * offset - offset the results * page - page number.
Methods included from Connection
Instance Method Details
#find(term, limit = nil, offset = nil, page = nil) ⇒ Object
Finds multiple icons based on the term
-
term - search term
-
limit - limit the amount of results
-
offset - offset the results
-
page - page number
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
List recent uploads
-
limit - limit the amount of results
-
offset - offset the results
-
page - page number
44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |