Commit f02b824

mo <mo.khan@gmail.com>
2018-06-14 16:13:21
lookup user info.
1 parent 8f871b2
Changed files (2)
exe
lib
ghetto
blaster
exe/ghetto-blaster
@@ -3,4 +3,5 @@
 
 require 'ghetto/blaster/cli'
 
+Net::Hippie.logger = Logger.new('/dev/null')
 Ghetto::Blaster::CLI.start(ARGV)
lib/ghetto/blaster/cli.rb
@@ -8,8 +8,12 @@ module Ghetto
 
       desc "play", "play music"
       def play
-        Net::Hippie.logger = Logger.new('/dev/null')
-        say client.get(build_uri("tracks?client_id=#{client_id}")).body
+        say client.get(build_uri("/tracks?client_id=#{client_id}")).body
+      end
+
+      desc "user username", "fetch user info"
+      def user(username)
+        say client.get(resolve(username)[:location]).body
       end
 
       desc "version", "print version"
@@ -28,7 +32,11 @@ module Ghetto
       end
 
       def build_uri(path)
-        "https://api.soundcloud.com/#{path}"
+        URI.join("https://api.soundcloud.com", path)
+      end
+
+      def resolve(username)
+        JSON.parse(client.get(build_uri("/resolve?url=https://soundcloud.com/#{username}&client_id=#{client_id}")).body, symbolize_names: true)
       end
     end
   end