Sha256: 2a8aead2afccfbd49b7b23dd794f07a02d9699259ee649c7497bd3fdadd63549

Contents?: true

Size: 683 Bytes

Versions: 1

Compression:

Stored size: 683 Bytes

Contents

module Somadic
  class AudioAddict
    def initialize(channel_id)
      @url = "http://api.audioaddict.com/v1/di/track_history/channel/" \
             "#{channel_id}.jsonp?callback=_AudioAddict_TrackHistory_Channel"
    end

    def refresh_playlist
      f = open(@url)
      page = f.read
      data = JSON.parse(page[page.index("(") + 1..-3])

      symbolized_data = []
      data.each { |d| symbolized_data << symbolize_keys(d) }
      @songs = symbolized_data.keep_if { |d| d[:title] }
    end

    private

    def symbolize_keys(hash)
      sym_hash = {}
      hash.each { |k, v| sym_hash[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v }
      sym_hash
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
somadic-0.0.1 lib/somadic/audio_addict.rb