Dada is a ruby library to interface with the OpenDada API. Dada Entertainment is a company specializing in providing their users with mobile and web entertainment. This library was built to make it very simple to use ruby to interface with the API provided by Dada Entertainment. It allows the developer to easily create different API requests without having to know the format that the request should be in. As an example, here is how you would make a request which will find all ringtones by Justin Timberlake, and output each ringtone’s title and sample mp3 url without using the Dada library.
require 'net/http'
require 'uri'
require 'rexml/document'
url = URI.parse('http://api.dada-ent.com/')
response = Net::HTTP.start(url.host) do |http|
http.get('/search/artist/justin+timberlake/',
'API-Key' => 'api-key')
end
xml = REXML::Document.new(response.body)
xml.root.elements.each('results/result') do |result|
puts result.elements['title'].text
puts result.elements['previewURL'].text
end
Now here’s an example of doing the same thing using the Dada library,
require 'dada'
searcher = Dada::DadaSearcher.new('api-key')
results = searcher.search(:artist => 'Justin Timberlake')
results.each do |result|
puts result.title
puts result.preview_url
end
As you can see, using the Dada library greatly simplifies the process of searching for ringtones using the Dada Entertainment API. If you’d like to install this library you can get the newest version using RubyGems.
gem install dada
Relevant Links: