Consume the Freesound.org API with Ruby.
Add this line to your application's Gemfile:
gem 'freesound_ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install freesound_ruby
You will need an API key to use the Freesound gem:
require 'freesound'
Freesound.api_key = "your_api_key"
And a client object:
client = Freesound::Client.new
Freesound exposes three resources: sounds, users, and packs. You can request them directly from the client:
sound = client.sound(17185)
user = client.user("alexgenco")
pack = client.pack(5107)
Resources will respond to any attributes returned by the API:
sound.bitrate # => 1411
user.username # => "alexgenco"
pack.name # => "Iceland"
You can also search for sounds:
client.search("kick") # => (many sounds)
Searches can be filtered as well:
Parameter | Description |
---|---|
p |
The page of the search result to get |
f |
A filter string (see docs for info) |
s |
How to sort the results |
fields |
Fields to return on each sound |
sounds_per_page |
Number of sounds to return in each page |
g |
Group results in packs |
For example, client.search("kick", p: 1, sounds_per_page: 3)
will return the
first 3 results of the search.
See the Freesound API docs for more information on search parameters.
More features to come!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
You will need a Freesound.org API key to run the integration tests. Get one here and assign it to the FREESOUND_KEY environment variable.