yesradio 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ doc/*
3
+ pkg/**/*
data/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ Copyright (c) 2009 Claudio Baccigalupo
2
+
3
+ Copying and distribution of this file, with or without modification,
4
+ are permitted in any medium without royalty provided the copyright
5
+ notice and this notice are preserved. This file is offered as-is,
6
+ without any warranty.
@@ -0,0 +1,78 @@
1
+ # YesRadio #
2
+
3
+ Ruby gem to access Yes.com API
4
+
5
+ ## Installation ##
6
+
7
+ sudo gem install claudiob-yesradio -s http://gems.github.com
8
+
9
+ ## Documentation ##
10
+
11
+ http://rdoc.info/projects/claudiob/yesradio
12
+
13
+ ## Examples ##
14
+
15
+ ### To show a list of 'Rock' stations ###
16
+
17
+ require 'yesradio'
18
+ Yesradio::search_stations :match => "Rock"
19
+
20
+ ### To show details of 'WFNX' radio ###
21
+
22
+ require 'yesradio'
23
+ Yesradio::get_station :name => "WFNX"
24
+
25
+ ### To show log of tracks played on 'WFNX' radio ###
26
+
27
+ require 'yesradio'
28
+ Yesradio::get_log :name => "WFNX"
29
+
30
+ ### To show recent tracks played on 'WFNX' radio ###
31
+
32
+ require 'yesradio'
33
+ Yesradio::get_recent :name => "WFNX"
34
+
35
+ ### To show a chart of popular Rock songs ###
36
+
37
+ require 'yesradio'
38
+ Yesradio::get_chart :genre => "Rock"
39
+
40
+ ### To show a list of songs by artist Rihanna ###
41
+
42
+ require 'yesradio'
43
+ Yesradio::get_media :aid => 610471
44
+
45
+ ### To show a list of songs related to Umbrella (Rihanna) ###
46
+
47
+ require 'yesradio'
48
+ Yesradio::get_related :mid => 11586843
49
+
50
+
51
+ ## History ##
52
+
53
+ v0.1.3 2009/09/29
54
+ Fixed wrong example in README
55
+
56
+ v0.1.2 2009/09/17
57
+ Changed REXML with Nokogiri for XML parsing
58
+
59
+ v0.1.1 2009/09/15
60
+ Fixed bug that made gem unusable (required inexistent file)
61
+
62
+ v0.1.0 2009/09/15
63
+ First release with all the actions and documentation on rdoc.info
64
+
65
+ v0.0.2 2009/09/15
66
+ Added support for actions: chart, media, related.
67
+ Added documentation through RDoc.
68
+ Added cucumber features for listing stations.
69
+
70
+ v0.0.1 2009/09/15
71
+ Added support for actions: log, recent.
72
+
73
+ v0.0.0 2009/09/14
74
+ Added support for actions: station, stations
75
+
76
+ ## Copyright ##
77
+
78
+ Copyright (c) 2009 Claudio Baccigalupo. See LICENSE for details.
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "yesradio"
8
+ gem.summary = %Q{Ruby library for Yes.com radio Web Services (http://api.yes.com).}
9
+ gem.description = %Q{YesRadio makes available as a ruby gem the method exposed by Yes.com API to retrieve songs broadcast by thousands of radios.}
10
+ gem.email = "claudiob@gmail.com"
11
+ gem.homepage = "http://github.com/claudiob/yesradio"
12
+ gem.authors = ["Claudio Baccigalupo"]
13
+ gem.rubyforge_project = "yesradio"
14
+ gem.add_development_dependency "cucumber"
15
+ gem.add_dependency "nokogiri", ">=1.3.2"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::RubyforgeTasks.new do |rubyforge|
19
+ rubyforge.doc_task = "rdoc"
20
+ end
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/*_test.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/*_test.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ begin
48
+ require 'cucumber/rake/task'
49
+ Cucumber::Rake::Task.new(:features)
50
+
51
+ task :features => :check_dependencies
52
+ rescue LoadError
53
+ task :features do
54
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
55
+ end
56
+ end
57
+
58
+ task :default => :test
59
+
60
+ require 'rake/rdoctask'
61
+ Rake::RDocTask.new do |rdoc|
62
+ if File.exist?('VERSION')
63
+ version = File.read('VERSION')
64
+ else
65
+ version = ""
66
+ end
67
+
68
+ rdoc.rdoc_dir = 'rdoc'
69
+ rdoc.title = "yesradio #{version}"
70
+ rdoc.rdoc_files.include('README*')
71
+ rdoc.rdoc_files.include('lib/**/*.rb')
72
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,17 @@
1
+ Given /^nothing$/ do
2
+
3
+ end
4
+
5
+ When /^I look for ([0-9]+) stations called "([^\"]*)"$/ do |max, match|
6
+ @stations = Yesradio::search_stations :match => match, :max => max
7
+ end
8
+
9
+ Then /^I should see a radio with name "([^\"]*)" and market "([^\"]*)"$/ do |name, market|
10
+ @stations.collect do |station|
11
+ station.name == name && station.market == market
12
+ end.inject{ |sum, el| sum || el }.should be_true
13
+ end
14
+
15
+ Then /^I should see nothing$/ do
16
+ @stations.should be_nil
17
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'yesradio'
3
+
4
+ require 'test/unit/assertions'
5
+
6
+ World(Test::Unit::Assertions)
@@ -0,0 +1,14 @@
1
+ Feature: Call Yes.com API using Ruby
2
+ In order to retrieve Yes.com data in Ruby code
3
+ programmers
4
+ want a Ruby interface to Yes.com API
5
+
6
+ Scenario: List Stations
7
+ Given nothing
8
+ When I look for 10 stations called "KEXP"
9
+ Then I should see a radio with name "KEXP" and market "Seattle - Tacoma, WA"
10
+
11
+ Scenario: List Stations Empty
12
+ Given nothing
13
+ When I look for 10 stations called "ABCDEFGH"
14
+ Then I should see nothing
@@ -0,0 +1,36 @@
1
+ # Author:: Claudio Baccigalupo
2
+ # Copyright:: Copyright (c) 2009 - see LICENSE file
3
+
4
+ require 'date'
5
+
6
+ module Yesradio
7
+ class Item
8
+ class << self
9
+ attr_accessor :elements
10
+ end
11
+
12
+ def initialize(element = nil)
13
+ self.class.elements.each do |name, type|
14
+ new_value = get_element_child element, name.gsub('_', '/'), type
15
+ self.instance_variable_set("@#{name}", new_value) unless new_value.nil?
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def get_element_child(element, child, type = :text)
22
+ return if element.nil? || element.xpath(child).empty?
23
+ child = element.xpath(child).text.to_s
24
+ return case type
25
+ when :int then child.to_i
26
+ when :float then child.to_f
27
+ when :datetime then DateTime.parse(child)
28
+ else child
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,7 @@
1
+ # Author:: Claudio Baccigalupo
2
+ # Copyright:: Copyright (c) 2009 - see LICENSE file
3
+
4
+ require 'yesradio'
5
+
6
+ # TODO: a file that prompts the user for the action to take
7
+ # and the parameters, and returns the result (as a shell command)
@@ -0,0 +1,15 @@
1
+ # Author:: Claudio Baccigalupo
2
+ # Copyright:: Copyright (c) 2009 - see LICENSE file
3
+
4
+ require 'item'
5
+ module Yesradio
6
+ class Song < Item
7
+ @elements = {'at' => :datetime, 'by' => :text, 'title' => :text,
8
+ 'id' => :int, 'type' => :text, 'rank' => :int,
9
+ 'cover' => :text, 'video' => :text, 'link' => :text,
10
+ 'ago' => :int}
11
+ attr_accessor *@elements.keys
12
+ end
13
+ end
14
+
15
+
@@ -0,0 +1,16 @@
1
+ # Author:: Claudio Baccigalupo
2
+ # Copyright:: Copyright (c) 2009 - see LICENSE file
3
+
4
+ require 'item'
5
+ module Yesradio
6
+ class Station < Item
7
+ @elements = {'name' => :text, 'desc' => :text, 'genre' => :text,
8
+ 'market' => :text, 'type' => :text, 'id' => :int,
9
+ 'tz' => :text, 'stream' => :text, 'yes' => :text,
10
+ 'relay' => :text, 'audiostream' => :text, 'array_id' => :int,
11
+ 'array_song' => :text, 'array_artist' => :text}
12
+ attr_accessor *@elements.keys
13
+ end
14
+ end
15
+
16
+
@@ -0,0 +1,148 @@
1
+ # Author:: Claudio Baccigalupo
2
+ # Copyright:: Copyright (c) 2009 - see LICENSE file
3
+
4
+ require 'cgi'
5
+ require 'net/http'
6
+ require 'nokogiri'
7
+
8
+ require 'station'
9
+ require 'song'
10
+
11
+ module Yesradio
12
+
13
+ YESRADIO_VERSION = 1
14
+ YESRADIO_SERVER = "http://api.yes.com/#{YESRADIO_VERSION}"
15
+
16
+ # Get current information about a single station including now playing song,
17
+ # slogan, frequency, market, and links to any known webcast stream or site.
18
+ #
19
+ # == Parameters
20
+ # [+name+] The station name (for AM/FM it is just the call letters).
21
+ #
22
+ # == Examples
23
+ # get_station :name => "KEXP"
24
+ #--
25
+ def self.get_station(query_hash)
26
+ array = self.search('Station', "station", "//api", query_hash)
27
+ array[0] unless array.nil? || array[0].name.nil?
28
+ end
29
+
30
+ # Search and find a list of stations by name, frequency, genre, artist,
31
+ # or location.
32
+ #
33
+ # == Parameters
34
+ # [+match+] [optional] Used to search station names, call letters, slogans, frequency, or cities/states.
35
+ # [+freq+] [optional] Also match an exact AM/FM frequency.
36
+ # [+mid+] [optional] Also match only stations that have this media id (see #media call) in their top 100 charts.
37
+ # [+genre+] [optional] Also match any genre keywords like pop, rock, etc.
38
+ # [+loc+] [optional] Also match stations within 60 miles of the given zip code, "lat,lon", or city/state names.
39
+ # [+max+] [optional] Defaults to 10 stations returned.
40
+ #
41
+ # == Examples
42
+ # search_stations :match => "KEX"
43
+ #--
44
+ def self.search_stations(query_hash)
45
+ self.search('Station', "stations", "//api/array/stations", query_hash)
46
+ end
47
+
48
+ # Get the log of all the songs played on the given station in a selected day
49
+ # within the last week.
50
+ #
51
+ # == Parameters
52
+ # [+name+] The station name.
53
+ # [+ago+] [optional] The days ago from now for the given date you want, an integer from 0-6 and defaults to 0 (the log today so far).
54
+ #
55
+ # == Examples
56
+ # get_log :name => "KEXP", :ago => 3
57
+ #--
58
+ def self.get_log(query_hash)
59
+ self.search('Song', "log", "//api/array/songs", query_hash)
60
+ end
61
+
62
+ # Get the most recent songs played on any station.
63
+ #
64
+ # == Parameters
65
+ # [+name+] The station name.
66
+ # [+max+] How many recent songs to return (default is 10).
67
+ #
68
+ # == Examples
69
+ # get_recent :name => "KEXP", :max => 3
70
+ #--
71
+ def self.get_recent(query_hash)
72
+ self.search('Song', "recent", "//api/array/songs", query_hash)
73
+ end
74
+
75
+ # Get the current top 100 songs for any station based on number of times
76
+ # played and user voting (calculated daily).
77
+ #
78
+ # == Parameters
79
+ # [+name+] [optional] The station name, defaults to US national top 100 if none given.
80
+ # [+date+] [optional] Return just the charts from a specific date in the format year-mm-dd (April 2008 and newer).
81
+ # [+genre+] [optional] Filter any request to a specific Genre ( Americana Blues Christian Classical Country Electronica Hip-Hop Jazz Latin Metal New Age Pop Punk R&B/Soul Rock Smooth Jazz World ).
82
+ # [+hot+] [optional] Alternative sorting, must be either "fresh" (by most increase in charts day-to-day, not supported in combination with date field) or "vote" (most votes via yes.com).
83
+ # [+max+] How many songs to return (default is 10).
84
+ #
85
+ # == Examples
86
+ # get_chart :genre => "Rock"
87
+ #--
88
+ def self.get_chart(query_hash)
89
+ self.search('Song', "chart", "//api/array/songs", query_hash)
90
+ end
91
+
92
+ # Get a list of any matching artist names or song titles based on airtime
93
+ # popularity.
94
+ #
95
+ # == Parameters
96
+ # [+q+] The string to search with, can be partial (used for autocomplete) or full names.
97
+ # [+aid+] [optional] Instead of a general query, a known Artist ID can be passed to return just media from that artist.
98
+ # [+mid+] [optional] Instead of a general query, a known Media ID can be passed to return extra information (lyrics from Lyric Wiki and matching videos from YouTube and MTV) about just that song.
99
+ # [+max+] How many songs to return (default is 10, max is 50).
100
+ #
101
+ # == Examples
102
+ # get_media :aid => 610471
103
+ #--
104
+ # Run test with http://api.yes.com/1/media?mid=12812281&type=xml
105
+ # which returns an XML error (Yes.com's fault)
106
+ def self.get_media(query_hash)
107
+ self.search('Song', "media", "//api/array/songs", query_hash)
108
+ end
109
+
110
+ # Given a song, return a list of related songs based on airtime in the last
111
+ # week.
112
+ #
113
+ # == Parameters
114
+ # [+mid+] The media ID (use media call to search for IDs).
115
+ # [+max+] Maximum number of related songs to return (default is 20).
116
+ #
117
+ # == Examples
118
+ # get_related :mid => 11586843
119
+ #--
120
+ def self.get_related(query_hash)
121
+ self.search('Song', "related", "//api/array/songs", query_hash)
122
+ end
123
+
124
+ protected
125
+
126
+ def self.search(item_class, action, xml_element, query_hash)
127
+ url = create_url(action, query_hash)
128
+ uri = URI.parse(url)
129
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
130
+ res = Net::HTTP.start(uri.host, uri.port) { |http|
131
+ http.request(req)
132
+ }
133
+ doc = Nokogiri::XML res.body
134
+ return if doc.xpath(xml_element).empty?
135
+ doc.xpath(xml_element).collect do |element|
136
+ eval "Yesradio::#{item_class}.new(element)"
137
+ end
138
+ end
139
+
140
+ def self.create_url(action, query_hash)
141
+ url = Yesradio::YESRADIO_SERVER + "/#{action}?type=xml"
142
+ query_hash.each do |name, value|
143
+ url = url + "&#{name}=" + CGI::escape(value.to_s) unless value.nil?
144
+ end
145
+ url
146
+ end
147
+
148
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'yesradio'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class YesradioTest < Test::Unit::TestCase
4
+ def test_something_for_real
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{yesradio}
8
+ s.version = "0.1.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Claudio Baccigalupo"]
12
+ s.date = %q{2009-09-29}
13
+ s.description = %q{YesRadio makes available as a ruby gem the method exposed by Yes.com API to retrieve songs broadcast by thousands of radios.}
14
+ s.email = %q{claudiob@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "features/step_definitions/yesradio_steps.rb",
26
+ "features/support/env.rb",
27
+ "features/yesradio.feature",
28
+ "lib/item.rb",
29
+ "lib/main.rb",
30
+ "lib/song.rb",
31
+ "lib/station.rb",
32
+ "lib/yesradio.rb",
33
+ "test/test_helper.rb",
34
+ "test/yesradio_test.rb",
35
+ "yesradio.gemspec"
36
+ ]
37
+ s.has_rdoc = true
38
+ s.homepage = %q{http://github.com/claudiob/yesradio}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubyforge_project = %q{yesradio}
42
+ s.rubygems_version = %q{1.3.1}
43
+ s.summary = %q{Ruby library for Yes.com radio Web Services (http://api.yes.com).}
44
+ s.test_files = [
45
+ "test/test_helper.rb",
46
+ "test/yesradio_test.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 2
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
55
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.2"])
56
+ else
57
+ s.add_dependency(%q<cucumber>, [">= 0"])
58
+ s.add_dependency(%q<nokogiri>, [">= 1.3.2"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<cucumber>, [">= 0"])
62
+ s.add_dependency(%q<nokogiri>, [">= 1.3.2"])
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yesradio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Baccigalupo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-29 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cucumber
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.2
34
+ version:
35
+ description: YesRadio makes available as a ruby gem the method exposed by Yes.com API to retrieve songs broadcast by thousands of radios.
36
+ email: claudiob@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - VERSION
50
+ - features/step_definitions/yesradio_steps.rb
51
+ - features/support/env.rb
52
+ - features/yesradio.feature
53
+ - lib/item.rb
54
+ - lib/main.rb
55
+ - lib/song.rb
56
+ - lib/station.rb
57
+ - lib/yesradio.rb
58
+ - test/test_helper.rb
59
+ - test/yesradio_test.rb
60
+ - yesradio.gemspec
61
+ has_rdoc: true
62
+ homepage: http://github.com/claudiob/yesradio
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: yesradio
85
+ rubygems_version: 1.3.5
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: Ruby library for Yes.com radio Web Services (http://api.yes.com).
89
+ test_files:
90
+ - test/test_helper.rb
91
+ - test/yesradio_test.rb