-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdiorepl
executable file
·87 lines (73 loc) · 1.66 KB
/
rdiorepl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby
# -*- ruby -*-
#
# Repl for exploring rdio.
#
require 'rubygems'
require 'rdio'
require 'lib/treerepl'
include Rdio
include TreeRepl
class SimpleNamedNode < NamedNode
def initialize(o)
super(o,o.name)
end
end
# ----------------------------------------------------------------------
# Adapter classes
# ----------------------------------------------------------------------
class UserNode < NamedNode
def initialize(o)
super(o,"#{o.first_name} #{o.last_name}")
end
def symbols
{'artists' => :artists_in_collection,
'tracks' => :tracks_in_collection,
'albums' => :albums_in_collection}
end
end
class ArtistNode < SimpleNamedNode
def initialize(o)
super(o)
end
def symbols
{'tracks' => :tracks,
'albums' => :albums}
end
end
class AlbumNode < SimpleNamedNode
def initialize(o)
super(o)
end
def symbols
{'tracks' => :tracks_in_collection}
end
end
class TrackNode < SimpleNamedNode
def initialize(o)
super(o)
end
def symbols
{}
end
end
CmdNode.classes2tree_nodes = {
User => UserNode,
Artist => ArtistNode,
Album => AlbumNode,
Track => TrackNode,
}
# ----------------------------------------------------------------------
# Commands
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# Main entry
# ----------------------------------------------------------------------
def main(argv)
user = argv.empty? ? User.current : User.find(argv[0])
repl = Repl.new UserNode
repl.finder = lambda {|name| User.find name}
node = UserNode.new user
repl.main node
end
main ARGV