A Ruby API wrapper for The Noun Project API's
gem "noun-project-api", "~> 3.1.0", require: "noun_project_api"
Current version only wraps the Icon/Icons API's. Feel free to send a pull request with more API's wrapped!
You need a valid pair of token and secret to use the Gem, you can get these by signing up here
Raises ArgumentError on bad arguments
You can use an initializer for example if you're on Rails.
# initializers/noun_project_api.rb
NounProjectApi.configure do |config|
# Will only show public domain icons when running in dev/test envs
config.public_domain = ['development', 'test'].include?(ENV['RAILS_ENV'])
end
Cache setup (needs to be an ActiveSupport::Cache::Store
)
config.cache = Rails.cache
config.cache_ttl = 20 # seconds
Defaults to Null store and 1 week TTL.
Initialize
icon_finder = NounProjectApi::IconRetriever.new(token, secret)
Find an Icon by id source
result = icon_finder.find(1) # Returns a hash of the parsed JSON result.
Find an Icon by slug source
result = icon_finder.find_by_slug('globe') # Returns a hash of the parsed JSON result.
Initialize
icons_finder = NounProjectApi::IconsRetriever.new(token, secret)
Optional arguments for both methods are limit, offset and page
Find Icons source
result = icons_finder.find('cat') # Returns an array of the parsed JSON results.
Get recent Icons source
result = icons_finder.recent_uploads # Returns an array of the parsed JSON results.
Initialize
collection_finder = NounProjectApi::CollectionRetriever.new(token, secret)
Find a Collection by id source
result = collection_finder.find(1) # Returns a hash of the parsed JSON result.
Find a Collection by slug source
result = collection_finder_finder.find_by_slug('national-park-service') # Returns a hash of the parsed JSON result.
The resulting object is either a NounObjectApi::Icon or an array of ones.
result.class # NounProjectApi::Icon
result.id # 1
result.public_domain? # true/false
result.svg_url # url/nil
result.preview_url # 200 size preview url
result.preview_url(42) # 42 size preview url
# You can always access the original Hash at
result.original_hash
This is completely unofficial and is not related to The Noun Project in any way.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request