Sha256: e659fb214ae526dac7f185801dcc1652c6695b7f1410805423f1475c2bda50b0
Contents?: true
Size: 1.46 KB
Versions: 4
Compression:
Stored size: 1.46 KB
Contents
require 'forwardable' # Note: this gem only supports the Simple API, since the Advanced API # is still in development module OfficialFM class Client extend Forwardable include Users include Tracks include Playlists attr_reader :api_key def_delegators :web_server def initialize(options={}) @api_key = options[:api_key] || OfficialFM.api_key # Note: Although the default of the API is to return XML, I think # json is more appropriate in the Ruby world # Note: I really don't understand how js_callback_function works, # so I'm not exposing it here. (Is it for AJAX client-side requests?) @format = options[:format] || :json connection end # Raw HTTP connection, either Faraday::Connection # # @return [Faraday::Connection] def connection params = {:key => @api_key, :format => @format} @connection ||= Faraday::Connection.new(:url => api_url, :params => params, :headers => default_headers) do |builder| builder.adapter Faraday.default_adapter builder.use Faraday::Response::ParseJson builder.use Faraday::Response::Mashify end end # @private def default_headers headers = { :accept => 'application/json', :user_agent => 'officialfm Ruby gem' } end # Provides the URL for accessing the API # # @return [String] def api_url "http://api.official.fm" end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
officialfm-0.0.4 | lib/officialfm/client.rb |
officialfm-0.0.3 | lib/officialfm/client.rb |
officialfm-0.0.2 | lib/officialfm/client.rb |
officialfm-0.0.1 | lib/officialfm/client.rb |