next-big-sound 0.1.0
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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/config.yml +1 -0
- data/lib/artist.rb +48 -0
- data/lib/base.rb +25 -0
- data/lib/hash_extension.rb +17 -0
- data/lib/search.rb +34 -0
- data/next-big-sound.gemspec +58 -0
- data/test/helper.rb +10 -0
- data/test/test_search.rb +31 -0
- metadata +88 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 jeff durand
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= next-big-sound
|
2
|
+
|
3
|
+
This is the start of a ruby api wrapper for nextbigsound.com. This gem will provide a reasonable ruby wrapper for all methods in the public API.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 jeff durand. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "next-big-sound"
|
8
|
+
gem.summary = %Q{Next Big Sound}
|
9
|
+
gem.description = %Q{A simple wrapper class for the Next Big Sound api. docs for the api can be found at api.nextbigsound.com}
|
10
|
+
gem.email = "jeff.durand@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/johnnyiller/next-big-sound"
|
12
|
+
gem.authors = ["jeff durand"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "next-big-sound #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
base_url: "http://api.nextbigsound.com/v1_1/"
|
data/lib/artist.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module NBS
|
2
|
+
class Artist
|
3
|
+
|
4
|
+
attr_accessor :artist_id, :name, :xml, :options
|
5
|
+
|
6
|
+
def initialize(artist_id, name="",options={})
|
7
|
+
self.artist_id=artist_id
|
8
|
+
self.name = name
|
9
|
+
self.options = {"artistID"=>self.artist_id,"apiKey"=>$nbs_api_key,"format"=>"xml"}.merge(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch_profile
|
13
|
+
self.xml=Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getProfilesForArtist?#{self.options.to_url_params}")).to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
# return a hash of urls keyed by the service.
|
17
|
+
def profiles
|
18
|
+
####
|
19
|
+
profs = {}
|
20
|
+
self.to_hash["Profiles"][0]["Profile"].each do |item|
|
21
|
+
profs[item["service"]]=item["url"]
|
22
|
+
end
|
23
|
+
return profs
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_xml
|
27
|
+
self.xml ||= fetch_profile
|
28
|
+
end
|
29
|
+
def to_hash
|
30
|
+
Hash.from_xml(self.to_xml)
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(method_name,*args)
|
34
|
+
if splits = method_name.to_s.split("_")
|
35
|
+
puts args.inspect
|
36
|
+
sdate = Date.parse(args[0].to_s)
|
37
|
+
edate = Date.parse(args[1].to_s)
|
38
|
+
opts = options.merge({"service"=>splits[0],"metric"=>splits[1],"start"=>sdate.to_s,"end"=>edate.to_s})
|
39
|
+
puts opts.inspect
|
40
|
+
puts "http://api.nextbigsound.com/v1_1/getDataForArtist?#{opts.to_url_params}"
|
41
|
+
return Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{opts.to_url_params}")).to_s
|
42
|
+
else
|
43
|
+
raise "Sorry that method does not exist. The proper format for finding data is service_metric(start,end)"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/base.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module NBS
|
2
|
+
|
3
|
+
$LOAD_PATH << './lib'
|
4
|
+
require 'yaml'
|
5
|
+
require 'hash_extension'
|
6
|
+
require 'search'
|
7
|
+
require 'artist'
|
8
|
+
|
9
|
+
NBS_CONFIG = YAML.load_file("config.yml")
|
10
|
+
|
11
|
+
class Base
|
12
|
+
|
13
|
+
def initialize(api_key)
|
14
|
+
$nbs_api_key = api_key
|
15
|
+
end
|
16
|
+
# return a search object that you can manipulate
|
17
|
+
# if you prefer to just use the xml simply type to_xml
|
18
|
+
# this method with actually fetch the result
|
19
|
+
def search(query, options={} )
|
20
|
+
search = Search.new(query,options)
|
21
|
+
search.fetch
|
22
|
+
return search
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'xmlsimple'
|
4
|
+
|
5
|
+
class Hash
|
6
|
+
def to_url_params
|
7
|
+
elements = []
|
8
|
+
keys.size.times do |i|
|
9
|
+
elements << "#{CGI::escape(keys[i])}=#{CGI::escape(values[i])}"
|
10
|
+
end
|
11
|
+
elements.join('&')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_xml(xml_data)
|
15
|
+
XmlSimple.xml_in(xml_data)
|
16
|
+
end
|
17
|
+
end
|
data/lib/search.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module NBS
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class Search
|
7
|
+
|
8
|
+
attr_accessor :options, :query, :api_key,:base_url, :xml
|
9
|
+
|
10
|
+
def initialize(query, options={})
|
11
|
+
self.options = {"query"=>query,"apiKey"=>$nbs_api_key,"format"=>"xml"}.merge(options)
|
12
|
+
self.query = query
|
13
|
+
self.api_key = api_key
|
14
|
+
self.base_url = base_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch
|
18
|
+
self.xml=Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}search?#{self.options.to_url_params}")).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def artists
|
22
|
+
hash = Hash.from_xml(self.xml)
|
23
|
+
a = []
|
24
|
+
hash["Results"][0]["Result"].each do |item|
|
25
|
+
a << Artist.new(item["NBSArtistID"][0],item["NBSArtistName"][0])
|
26
|
+
end
|
27
|
+
return a
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_xml
|
31
|
+
self.xml
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{next-big-sound}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["jeff durand"]
|
12
|
+
s.date = %q{2010-03-26}
|
13
|
+
s.description = %q{A simple wrapper class for the Next Big Sound api. docs for the api can be found at api.nextbigsound.com}
|
14
|
+
s.email = %q{jeff.durand@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"config.yml",
|
27
|
+
"lib/artist.rb",
|
28
|
+
"lib/base.rb",
|
29
|
+
"lib/hash_extension.rb",
|
30
|
+
"lib/search.rb",
|
31
|
+
"next-big-sound.gemspec",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_search.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/johnnyiller/next-big-sound}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.6}
|
39
|
+
s.summary = %q{Next Big Sound}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_search.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/test/helper.rb
ADDED
data/test/test_search.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class TestNextBigSound < Test::Unit::TestCase
|
5
|
+
include NBS
|
6
|
+
context "Has Valid api key" do
|
7
|
+
setup do
|
8
|
+
# get the api key from the yaml file
|
9
|
+
YAML.load_file("./test/credentials.yml").each { |key,value| instance_variable_set("@#{key}", value) }
|
10
|
+
@nbs = Base.new(@api_key)
|
11
|
+
end
|
12
|
+
context "Assuming we are able to search for the killers" do
|
13
|
+
setup do
|
14
|
+
@searchobj = @nbs.search("The Killers")
|
15
|
+
end
|
16
|
+
should "Be able to find The Killers ArtistID" do
|
17
|
+
assert_match /<NBSArtistID>\d+<\/NBSArtistID>/i, @searchobj.to_xml
|
18
|
+
end
|
19
|
+
should "have an array of results" do
|
20
|
+
assert !@searchobj.artists.empty?
|
21
|
+
end
|
22
|
+
should "have first result with artist name of The Killers" do
|
23
|
+
assert_equal "The Killers", @searchobj.artists.first.name
|
24
|
+
end
|
25
|
+
should "be able to get some data" do
|
26
|
+
assert @searchobj.artists.first.myspace_plays("4/24/2009","4/24/2010").is_a?(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
#should "have many re"
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: next-big-sound
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- jeff durand
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-26 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
description: A simple wrapper class for the Next Big Sound api. docs for the api can be found at api.nextbigsound.com
|
33
|
+
email: jeff.durand@gmail.com
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.rdoc
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- config.yml
|
49
|
+
- lib/artist.rb
|
50
|
+
- lib/base.rb
|
51
|
+
- lib/hash_extension.rb
|
52
|
+
- lib/search.rb
|
53
|
+
- next-big-sound.gemspec
|
54
|
+
- test/helper.rb
|
55
|
+
- test/test_search.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/johnnyiller/next-big-sound
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Next Big Sound
|
86
|
+
test_files:
|
87
|
+
- test/helper.rb
|
88
|
+
- test/test_search.rb
|