forked from youpy/ruby-echonest
-
Notifications
You must be signed in to change notification settings - Fork 4
/
console
45 lines (31 loc) · 750 Bytes
/
console
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
require 'rubygems'
require 'irb'
# ensure we use local gem
$LOAD_PATH.unshift('lib')
def consolize &block
yield
IRB.setup(nil)
irb = IRB::Irb.new
IRB.conf[:MAIN_CONTEXT] = irb.context
irb.context.evaluate("require 'irb/completion'", 0)
trap("SIGINT") do
irb.signal_handle
end
catch(:IRB_EXIT) do
irb.eval_input
end
end
consolize do
require 'echonest'
key = nil
locations = ["~/.mreko/echonest_api.key", "~/.echonest/api_key"]
locations.each do |config|
if File.exists?(File.expand_path(config))
key = File.read(File.expand_path(config))
break
end
end
raise "Need an EN key in one of these locations: #{locations.inspect}" unless key
@en = Echonest(key)
def en; @en; end
end