Skip to content

A Ruby API wrapper for The Noun Project API's

License

Notifications You must be signed in to change notification settings

TailorBrands/noun-project-api

Repository files navigation

The Noun Project Ruby API Wrapper

A Ruby API wrapper for The Noun Project API's

Gem Version

gem "noun-project-api", "~> 3.1.0", require: "noun_project_api"

Missing

Current version only wraps the Icon/Icons API's. Feel free to send a pull request with more API's wrapped!

Usage

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

Configuration

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.

Find single icon

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.

Search icons

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.

Find a collection of icons

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.

Resulting objects

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

Disclaimer

This is completely unofficial and is not related to The Noun Project in any way.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About Tailor Brands

Check us out!