songsterr 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/lib/songsterr.rb +6 -0
- data/lib/songsterr/artist.rb +8 -0
- data/lib/songsterr/data/base.rb +21 -0
- data/lib/songsterr/data/instrument.rb +7 -0
- data/lib/songsterr/data/song_revision.rb +21 -0
- data/lib/songsterr/data/track.rb +28 -0
- data/lib/songsterr/data/track_audio.rb +8 -0
- data/lib/songsterr/data/track_layout_image.rb +9 -0
- data/lib/songsterr/ext/string.rb +20 -0
- data/lib/songsterr/request.rb +14 -0
- data/lib/songsterr/song.rb +49 -0
- metadata +87 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 - Endel Dreyer
|
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/lib/songsterr.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Songsterr
|
2
|
+
module Data
|
3
|
+
class Base
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def info(key)
|
11
|
+
@data[key.to_s.camelize(:lower)]
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args, &block)
|
15
|
+
info(method) or raise NoMethodError, "Method or attribute '#{method}' not exists on #{self.class.name}."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'songsterr/data/track'
|
2
|
+
|
3
|
+
module Songsterr
|
4
|
+
module Data
|
5
|
+
class SongRevision < Base
|
6
|
+
|
7
|
+
def most_popular_track
|
8
|
+
tracks.select {|track| track.id == info(:most_popular_track)['id'] }.first
|
9
|
+
end
|
10
|
+
|
11
|
+
def tracks
|
12
|
+
@tracks ||= info(:tracks).collect {|data| Track.new(data) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def guitar_pro_tab
|
16
|
+
@guitar_pro_url ||= info(:guitar_pro_tab)['attachmentUrl']
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'songsterr/data/instrument'
|
2
|
+
require 'songsterr/data/track_audio'
|
3
|
+
require 'songsterr/data/track_layout_image'
|
4
|
+
|
5
|
+
module Songsterr
|
6
|
+
module Data
|
7
|
+
class Track < Base
|
8
|
+
|
9
|
+
def has_lyrics?
|
10
|
+
info(:with_lyrics)
|
11
|
+
end
|
12
|
+
|
13
|
+
def instrument
|
14
|
+
@instrument ||= Instrument.new(info(:instrument))
|
15
|
+
end
|
16
|
+
|
17
|
+
def audios
|
18
|
+
@audios ||= info(:track_audios).collect {|data| TrackAudio.new(data) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def layout_images
|
22
|
+
@layout_images ||= info(:track_layout_images).collect {|data| TrackLayoutImage.new(data) }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Extend String to support #camelize method.
|
3
|
+
#
|
4
|
+
# "active_record".camelize # => "ActiveRecord"
|
5
|
+
# "active_record".camelize(:lower) # => "activeRecord"
|
6
|
+
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
7
|
+
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
8
|
+
#
|
9
|
+
class String
|
10
|
+
def camelize(first_letter = :upper)
|
11
|
+
parts = self.split('_')
|
12
|
+
i = 0
|
13
|
+
parts.collect! do |p|
|
14
|
+
p = p.capitalize if (i != 0 || (i == 0 && first_letter == :upper))
|
15
|
+
i += 1
|
16
|
+
p
|
17
|
+
end
|
18
|
+
parts.join('')
|
19
|
+
end
|
20
|
+
end unless "".respond_to? :camelize
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'songsterr/data/base'
|
2
|
+
require 'songsterr/data/song_revision'
|
3
|
+
|
4
|
+
module Songsterr
|
5
|
+
class Song < Data::Base
|
6
|
+
#
|
7
|
+
# Class Methods
|
8
|
+
#
|
9
|
+
class << self
|
10
|
+
def find_by_id(id)
|
11
|
+
self.new(Request.get("player/song/#{id}"))
|
12
|
+
end
|
13
|
+
|
14
|
+
def where(data={})
|
15
|
+
if data[:id]
|
16
|
+
return self.find_by_id(data[:id])
|
17
|
+
|
18
|
+
elsif (artists = (data[:artist] || data[:artists]))
|
19
|
+
artists = [artists] unless artists.kind_of? Array
|
20
|
+
artists.collect!{|a| "\"#{a}\"" }
|
21
|
+
songs = Request.get('songs/byartists', :artists => artists.join(','))
|
22
|
+
|
23
|
+
elsif data[:pattern]
|
24
|
+
songs = Request.get('songs', :pattern => data[:pattern])
|
25
|
+
end
|
26
|
+
|
27
|
+
songs.collect {|data| self.new(data) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Instance Methods
|
33
|
+
#
|
34
|
+
def artist
|
35
|
+
@artist ||= Artist.new(info(:artist))
|
36
|
+
end
|
37
|
+
|
38
|
+
def revision
|
39
|
+
@revision ||= begin
|
40
|
+
unless info(:latest_available_revision)
|
41
|
+
self.class.find_by_id(info(:id)).revision
|
42
|
+
else
|
43
|
+
Data::SongRevision.new(info(:latest_available_revision))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: songsterr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Endel Dreyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-13 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.7
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: json
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
description: " A Ruby wrapper for the Songsterr REST API\n"
|
38
|
+
email:
|
39
|
+
- endel.dreyer@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- lib/songsterr/artist.rb
|
49
|
+
- lib/songsterr/data/base.rb
|
50
|
+
- lib/songsterr/data/instrument.rb
|
51
|
+
- lib/songsterr/data/song_revision.rb
|
52
|
+
- lib/songsterr/data/track.rb
|
53
|
+
- lib/songsterr/data/track_audio.rb
|
54
|
+
- lib/songsterr/data/track_layout_image.rb
|
55
|
+
- lib/songsterr/ext/string.rb
|
56
|
+
- lib/songsterr/request.rb
|
57
|
+
- lib/songsterr/song.rb
|
58
|
+
- lib/songsterr.rb
|
59
|
+
homepage: http://github.com/endel/songsterr-api
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.11
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A Ruby wrapper for the Songsterr REST API
|
86
|
+
test_files: []
|
87
|
+
|