songkicky 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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README +5 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/lib/artist.rb +26 -0
- data/lib/event.rb +22 -0
- data/lib/json_api.rb +56 -0
- data/lib/metro_area.rb +17 -0
- data/lib/songkicky.rb +13 -0
- data/songkicky.gemspec +52 -0
- metadata +92 -0
data/.document
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Sabrina Leandro
|
|
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
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "songkicky"
|
|
8
|
+
gem.summary = %Q{Wrapper for Songkick's API.}
|
|
9
|
+
gem.description = %Q{Very simple Ruby wrapper for Songkick's API. (http://developer.songkick.com/)}
|
|
10
|
+
gem.email = "saleandro@yahoo.com"
|
|
11
|
+
gem.homepage = "http://github.com/saleandro/songkicky"
|
|
12
|
+
gem.authors = ["Sabrina Leandro"]
|
|
13
|
+
gem.add_development_dependency "json", ">= 0"
|
|
14
|
+
end
|
|
15
|
+
Jeweler::GemcutterTasks.new
|
|
16
|
+
rescue LoadError
|
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
task :test => :check_dependencies
|
|
21
|
+
|
|
22
|
+
task :default => :test
|
|
23
|
+
|
|
24
|
+
require 'rake/rdoctask'
|
|
25
|
+
Rake::RDocTask.new do |rdoc|
|
|
26
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
27
|
+
|
|
28
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
29
|
+
rdoc.title = "songkicky #{version}"
|
|
30
|
+
rdoc.rdoc_files.include('README*')
|
|
31
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
32
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.1
|
data/lib/artist.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'json_api'
|
|
2
|
+
|
|
3
|
+
module Songkicky
|
|
4
|
+
class Artist
|
|
5
|
+
include JsonApi
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def find_by_mbid(mbid)
|
|
9
|
+
Artist.new(mbid)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(mbid)
|
|
14
|
+
@mbid = mbid
|
|
15
|
+
@upcoming_events = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def upcoming_events
|
|
19
|
+
return @upcoming_events if @upcoming_events
|
|
20
|
+
|
|
21
|
+
events_hash = all("artists/mbid:#{@mbid}/events.json", 'event')
|
|
22
|
+
@upcoming_events = events_hash.map {|hash| Event.new(hash) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/event.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Songkicky
|
|
4
|
+
|
|
5
|
+
class Event
|
|
6
|
+
|
|
7
|
+
attr_accessor :id,
|
|
8
|
+
:name,
|
|
9
|
+
:date,
|
|
10
|
+
:lat, :lng,
|
|
11
|
+
:metro_area
|
|
12
|
+
|
|
13
|
+
def initialize(hash)
|
|
14
|
+
@id = hash['id']
|
|
15
|
+
@name = hash['displayName']
|
|
16
|
+
@date = Date.strptime(hash['start']['date'], '%Y-%m-%d')
|
|
17
|
+
@lat = hash['location']['lat']
|
|
18
|
+
@lng = hash['location']['lng']
|
|
19
|
+
@metro_area = MetroArea.new(hash['venue']['metroArea'])
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/json_api.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Songkicky
|
|
6
|
+
module JsonApi
|
|
7
|
+
|
|
8
|
+
def all(path, thing)
|
|
9
|
+
things = []
|
|
10
|
+
per_page = total = nil
|
|
11
|
+
page = 0
|
|
12
|
+
|
|
13
|
+
while !per_page || (page*per_page) < total
|
|
14
|
+
json_page = json_data_from(append_to_path(path, "page=#{page+1}"))["resultsPage"]
|
|
15
|
+
page = json_page["page"]
|
|
16
|
+
per_page = json_page["perPage"]
|
|
17
|
+
total = json_page["totalEntries"]
|
|
18
|
+
|
|
19
|
+
next unless json_page["results"][thing]
|
|
20
|
+
|
|
21
|
+
things += json_page["results"][thing]
|
|
22
|
+
end
|
|
23
|
+
things
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def json_data_from(path)
|
|
29
|
+
path = path[1..-1] if path[0,1] == '/'
|
|
30
|
+
url = "#{api_root}#{append_to_path(path, api_key_query_string)}"
|
|
31
|
+
JSON.parse(open(url).read)
|
|
32
|
+
rescue URI::InvalidURIError
|
|
33
|
+
return nil
|
|
34
|
+
rescue OpenURI::HTTPError => e
|
|
35
|
+
case e.message
|
|
36
|
+
when /403/
|
|
37
|
+
raise "Are you sure you set your Songkicky.apikey correctly? It's set to: '#{Songkicky.apikey}'"
|
|
38
|
+
else
|
|
39
|
+
raise e
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def append_to_path(path, query_string)
|
|
44
|
+
sep = path && path.match(/\?/) ? '&' : '?'
|
|
45
|
+
"#{path}#{sep}#{query_string}"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def api_key_query_string
|
|
49
|
+
"apikey=#{Songkicky.apikey}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def api_root
|
|
53
|
+
'http://api.songkick.com/api/3.0/'
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/metro_area.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Songkicky
|
|
2
|
+
class MetroArea
|
|
3
|
+
|
|
4
|
+
attr_accessor :id,
|
|
5
|
+
:name,
|
|
6
|
+
:lat, :lng,
|
|
7
|
+
:state,
|
|
8
|
+
:country
|
|
9
|
+
|
|
10
|
+
def initialize(hash)
|
|
11
|
+
@id = hash['id']
|
|
12
|
+
@name = hash['displayName']
|
|
13
|
+
@state = hash['state']['displayName'] if hash['state']
|
|
14
|
+
@country = hash['country']['displayName']
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/songkicky.rb
ADDED
data/songkicky.gemspec
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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{songkicky}
|
|
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 = ["Sabrina Leandro"]
|
|
12
|
+
s.date = %q{2010-08-31}
|
|
13
|
+
s.description = %q{Very simple Ruby wrapper for Songkick's API. (http://developer.songkick.com/)}
|
|
14
|
+
s.email = %q{saleandro@yahoo.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".gitignore",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README",
|
|
24
|
+
"Rakefile",
|
|
25
|
+
"VERSION",
|
|
26
|
+
"lib/artist.rb",
|
|
27
|
+
"lib/event.rb",
|
|
28
|
+
"lib/json_api.rb",
|
|
29
|
+
"lib/metro_area.rb",
|
|
30
|
+
"lib/songkicky.rb",
|
|
31
|
+
"songkicky.gemspec"
|
|
32
|
+
]
|
|
33
|
+
s.homepage = %q{http://github.com/saleandro/songkicky}
|
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
35
|
+
s.require_paths = ["lib"]
|
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
|
37
|
+
s.summary = %q{Wrapper for Songkick's API.}
|
|
38
|
+
|
|
39
|
+
if s.respond_to? :specification_version then
|
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
41
|
+
s.specification_version = 3
|
|
42
|
+
|
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
44
|
+
s.add_development_dependency(%q<json>, [">= 0"])
|
|
45
|
+
else
|
|
46
|
+
s.add_dependency(%q<json>, [">= 0"])
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
s.add_dependency(%q<json>, [">= 0"])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
metadata
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: songkicky
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Sabrina Leandro
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-08-31 00:00:00 +01:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: json
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 3
|
|
30
|
+
segments:
|
|
31
|
+
- 0
|
|
32
|
+
version: "0"
|
|
33
|
+
type: :development
|
|
34
|
+
version_requirements: *id001
|
|
35
|
+
description: Very simple Ruby wrapper for Songkick's API. (http://developer.songkick.com/)
|
|
36
|
+
email: saleandro@yahoo.com
|
|
37
|
+
executables: []
|
|
38
|
+
|
|
39
|
+
extensions: []
|
|
40
|
+
|
|
41
|
+
extra_rdoc_files:
|
|
42
|
+
- LICENSE
|
|
43
|
+
- README
|
|
44
|
+
files:
|
|
45
|
+
- .document
|
|
46
|
+
- .gitignore
|
|
47
|
+
- LICENSE
|
|
48
|
+
- README
|
|
49
|
+
- Rakefile
|
|
50
|
+
- VERSION
|
|
51
|
+
- lib/artist.rb
|
|
52
|
+
- lib/event.rb
|
|
53
|
+
- lib/json_api.rb
|
|
54
|
+
- lib/metro_area.rb
|
|
55
|
+
- lib/songkicky.rb
|
|
56
|
+
- songkicky.gemspec
|
|
57
|
+
has_rdoc: true
|
|
58
|
+
homepage: http://github.com/saleandro/songkicky
|
|
59
|
+
licenses: []
|
|
60
|
+
|
|
61
|
+
post_install_message:
|
|
62
|
+
rdoc_options:
|
|
63
|
+
- --charset=UTF-8
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
hash: 3
|
|
72
|
+
segments:
|
|
73
|
+
- 0
|
|
74
|
+
version: "0"
|
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
|
+
none: false
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
hash: 3
|
|
81
|
+
segments:
|
|
82
|
+
- 0
|
|
83
|
+
version: "0"
|
|
84
|
+
requirements: []
|
|
85
|
+
|
|
86
|
+
rubyforge_project:
|
|
87
|
+
rubygems_version: 1.3.7
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 3
|
|
90
|
+
summary: Wrapper for Songkick's API.
|
|
91
|
+
test_files: []
|
|
92
|
+
|