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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/noun-project-api/icons_retriever.rb', line 13 def find(term, limit = nil, offset = nil, page = nil) fail(ArgumentError, 'Missing search term') unless term search = OAuth::Helper.escape(term) search += "?limit_to_public_domain=#{NounProjectApi.configuration.public_domain ? 1 : 0}" args = { 'limit' => limit, 'offset' => offset, 'page' => page }.reject { |_, v| v.nil? } args.each { |k, v| search += "&#{k}=#{v}" } if args.size > 0 result = access_token.get("#{API_BASE}#{API_PATH}#{search}") fail(ArgumentError, 'Bad request') unless %w(200 404).include? result.code if result.code == '200' JSON.parse(result.body)['icons'].map { |icon| Icon.new(icon) } else [] 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/noun-project-api/icons_retriever.rb', line 36 def recent_uploads(limit = nil, offset = nil, page = nil) args = { 'limit' => limit, 'offset' => offset, 'page' => page }.reject { |k, v| v.nil? } if args.size > 0 search = '?' args.each { |k, v| search += "#{k}=#{v}&" } else search = '' end result = access_token.get("#{API_BASE}#{API_PATH}recent_uploads#{search}") fail(ArgumentError, 'Bad request') unless result.code == '200' JSON.parse(result.body)['recent_uploads'].map { |icon| Icon.new(icon) } end |