claudiob-yesradio 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
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.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # YesRadio #
2
+
3
+ Ruby gem to access Yes.com API
4
+
5
+ <a name="rubygem_install" />
6
+ ## Installation ##
7
+
8
+ sudo gem install yesradio -s http://gems.github.com
9
+
10
+ ## Examples ##
11
+
12
+ ### To show a list of 'Rock' stations ###
13
+
14
+ require 'yesradio'
15
+ query = Yesradio::StationsSearchCriteria.new
16
+ query.match = "KWOF"
17
+ result = Yesradio::search_stations query
18
+
19
+ ### To show details of 'WFNX' radio ###
20
+
21
+ require 'yesradio'
22
+ Yesradio::match_station "WFNX"
data/Rakefile ADDED
@@ -0,0 +1,71 @@
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 is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::RubyforgeTasks.new do |rubyforge|
18
+ rubyforge.doc_task = "rdoc"
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ begin
47
+ require 'cucumber/rake/task'
48
+ Cucumber::Rake::Task.new(:features)
49
+
50
+ task :features => :check_dependencies
51
+ rescue LoadError
52
+ task :features do
53
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
54
+ end
55
+ end
56
+
57
+ task :default => :test
58
+
59
+ require 'rake/rdoctask'
60
+ Rake::RDocTask.new do |rdoc|
61
+ if File.exist?('VERSION')
62
+ version = File.read('VERSION')
63
+ else
64
+ version = ""
65
+ end
66
+
67
+ rdoc.rdoc_dir = 'rdoc'
68
+ rdoc.title = "yesradio #{version}"
69
+ rdoc.rdoc_files.include('README*')
70
+ rdoc.rdoc_files.include('lib/**/*.rb')
71
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
File without changes
@@ -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,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
data/lib/main.rb ADDED
@@ -0,0 +1,24 @@
1
+ #=============================================================================
2
+ #
3
+ # 2009 Claudio Baccigalupo
4
+ #
5
+ # Licensed under the Ruby License
6
+ #
7
+ #=============================================================================
8
+
9
+ require 'yesradio'
10
+
11
+ # get the list of radio stations
12
+ query = Yesradio::StationsSearchCriteria.new
13
+ query.match = "KWOF"
14
+ stations = Yesradio::search_stations query
15
+ p stations
16
+
17
+ # get the details of a radio station
18
+ Yesradio::match_station "WFNX"
19
+
20
+ # get the log of songs played on a radio
21
+ Yesradio::get_log "KEXP"
22
+
23
+ # get the recent songs played on a radio
24
+ Yesradio::get_recent "KEXP"
data/lib/song.rb ADDED
@@ -0,0 +1,21 @@
1
+ #=============================================================================
2
+ #
3
+ # 2009 Claudio Baccigalupo
4
+ #
5
+ # Licensed under the Ruby License
6
+ #
7
+ #=============================================================================
8
+
9
+ module Yesradio
10
+ class Song
11
+ @@elements = {'at' => :datetime, 'by' => :text, 'title' => :text,
12
+ 'id' => :int, 'type' => :text, 'rank' => :int,
13
+ 'cover' => :text, 'video' => :text, 'ago' => :int}
14
+ attr_accessor *@@elements.keys
15
+ def elements
16
+ @@elements
17
+ end
18
+ end
19
+ end
20
+
21
+
data/lib/station.rb ADDED
@@ -0,0 +1,23 @@
1
+ #=============================================================================
2
+ #
3
+ # 2009 Claudio Baccigalupo
4
+ #
5
+ # Licensed under the Ruby License
6
+ #
7
+ #=============================================================================
8
+
9
+ module Yesradio
10
+ class Station
11
+ @@elements = {'name' => :text, 'desc' => :text, 'genre' => :text,
12
+ 'market' => :text, 'type' => :text, 'id' => :int,
13
+ 'tz' => :text, 'stream' => :text, 'yes' => :text,
14
+ 'relay' => :text, 'audiostream' => :text, 'array_id' => :int,
15
+ 'array_song' => :text, 'array_artist' => :text}
16
+ attr_accessor *@@elements.keys
17
+ def elements
18
+ @@elements
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,33 @@
1
+ #=============================================================================
2
+ #
3
+ # 2009 Claudio Baccigalupo
4
+ #
5
+ # Licensed under the Ruby License
6
+ #
7
+ #=============================================================================
8
+
9
+ module Yesradio
10
+ class StationsSearchCriteria
11
+
12
+ attr_accessor :match, :freq, :mid, :genre, :loc, :max
13
+
14
+ def initialize(options = {})
15
+ options.each do |key, value|
16
+ eval("@#{key} = '#{value.to_s}'")
17
+ end
18
+ end
19
+
20
+ def to_query_params_string
21
+ url = ''
22
+ url = url + "&match=" + CGI::escape(@match) if !@match.nil?
23
+ url = url + "&freq=" + CGI::escape(@freq) if !@freq.nil?
24
+ url = url + "&mid=" + CGI::escape(@mid.to_s) if !@mid.nil?
25
+ url = url + "&genre=" + CGI::escape(@genre) if !@genre.nil?
26
+ url = url + "&loc=" + CGI::escape(@loc) if !@loc.nil?
27
+ url = url + "&max=" + CGI::escape(@max.to_s) if !@max.nil?
28
+ url
29
+ end
30
+ end
31
+ end
32
+
33
+
data/lib/yesradio.rb ADDED
@@ -0,0 +1,122 @@
1
+ #=============================================================================
2
+ #
3
+ # 2009 Claudio Baccigalupo
4
+ #
5
+ # Licensed under the Ruby License
6
+ #
7
+ #=============================================================================
8
+
9
+ require 'cgi'
10
+ require 'net/http'
11
+ require 'rexml/document'
12
+ require 'date'
13
+
14
+ require 'station'
15
+ require 'stations_search_criteria'
16
+ require 'song'
17
+
18
+ module Yesradio
19
+
20
+ YESRADIO_VERSION = 1
21
+ YESRADIO_SERVER = "http://api.yes.com/#{YESRADIO_VERSION}"
22
+
23
+ def self.element_to_station(element)
24
+ station = Station.new
25
+ station.elements.each do |name, type|
26
+ new_value = get_element_child element, name.gsub('_', '/'), type
27
+ station.instance_variable_set("@#{name}", new_value) unless new_value.nil?
28
+ end
29
+ station
30
+ end
31
+
32
+ # TO DO, dry with the previous function
33
+ def self.element_to_song(element)
34
+ song = Song.new
35
+ song.elements.each do |name, type|
36
+ new_value = get_element_child element, name.gsub('_', '/'), type
37
+ song.instance_variable_set("@#{name}", new_value) unless new_value.nil?
38
+ end
39
+ song
40
+ end
41
+
42
+ def self.search_stations(search_criteria)
43
+ stations = Array.new
44
+
45
+ url = Yesradio::YESRADIO_SERVER + "/stations?type=xml"
46
+ url = url + search_criteria.to_query_params_string
47
+ uri = URI.parse(url)
48
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
49
+ res = Net::HTTP.start(uri.host, uri.port) { |http|
50
+ http.request(req)
51
+ }
52
+ doc = REXML::Document.new res.body
53
+ doc.elements.each("//api/array/stations") do |element|
54
+ stations << element_to_station(element)
55
+ end
56
+ stations
57
+ end
58
+
59
+ def self.get_station(station_name)
60
+ url = Yesradio::YESRADIO_SERVER + "/station?type=xml"
61
+ url = url + "&name=" + CGI::escape(station_name)
62
+ uri = URI.parse(url)
63
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
64
+ res = Net::HTTP.start(uri.host, uri.port) { |http|
65
+ http.request(req)
66
+ }
67
+ doc = REXML::Document.new res.body
68
+ element_to_station(doc.elements["//api"])
69
+ end
70
+
71
+ def self.get_log(station_name, ago = nil)
72
+ songs = Array.new
73
+
74
+ url = Yesradio::YESRADIO_SERVER + "/log?type=xml"
75
+ url = url + "&name=" + CGI::escape(station_name)
76
+ url = url + "&ago=" + CGI::escape(ago.to_s) unless ago.nil?
77
+ uri = URI.parse(url)
78
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
79
+ res = Net::HTTP.start(uri.host, uri.port) { |http|
80
+ http.request(req)
81
+ }
82
+ doc = REXML::Document.new res.body
83
+ doc.elements.each("//api/array/songs") do |element|
84
+ songs << element_to_song(element)
85
+ end
86
+ songs
87
+ end
88
+
89
+ def self.get_recent(station_name, max = nil)
90
+ songs = Array.new
91
+
92
+ url = Yesradio::YESRADIO_SERVER + "/recent?type=xml"
93
+ url = url + "&name=" + CGI::escape(station_name)
94
+ url = url + "&max=" + CGI::escape(max.to_s) unless max.nil?
95
+ uri = URI.parse(url)
96
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
97
+ res = Net::HTTP.start(uri.host, uri.port) { |http|
98
+ http.request(req)
99
+ }
100
+ doc = REXML::Document.new res.body
101
+ doc.elements.each("//api/array/songs") do |element|
102
+ songs << element_to_song(element)
103
+ end
104
+ songs
105
+ end
106
+
107
+ protected
108
+
109
+ def self.get_element_child(element, child, type = :text)
110
+ return if element.elements[child].nil?
111
+ child = element.elements[child][0].to_s
112
+ return case type
113
+ when :int then child.to_i
114
+ when :float then child.to_f
115
+ when :datetime then DateTime.parse(child)
116
+ else child
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
@@ -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
data/yesradio.gemspec ADDED
@@ -0,0 +1,61 @@
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.0.1"
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-15}
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/main.rb",
29
+ "lib/song.rb",
30
+ "lib/station.rb",
31
+ "lib/stations_search_criteria.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
+ else
56
+ s.add_dependency(%q<cucumber>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<cucumber>, [">= 0"])
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: claudiob-yesradio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Baccigalupo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-15 00:00:00 -07: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
+ description: YesRadio makes available as a ruby gem the method exposed by Yes.com API to retrieve songs broadcast by thousands of radios.
26
+ email: claudiob@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.md
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - VERSION
40
+ - features/step_definitions/yesradio_steps.rb
41
+ - features/support/env.rb
42
+ - features/yesradio.feature
43
+ - lib/main.rb
44
+ - lib/song.rb
45
+ - lib/station.rb
46
+ - lib/stations_search_criteria.rb
47
+ - lib/yesradio.rb
48
+ - test/test_helper.rb
49
+ - test/yesradio_test.rb
50
+ - yesradio.gemspec
51
+ has_rdoc: true
52
+ homepage: http://github.com/claudiob/yesradio
53
+ licenses:
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project: yesradio
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: Ruby library for Yes.com radio Web Services (http://api.yes.com).
78
+ test_files:
79
+ - test/test_helper.rb
80
+ - test/yesradio_test.rb