Skip to content

Commit

Permalink
Add ability to look up soundcloud users by id.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jan 18, 2017
1 parent 50a493d commit 2f6d914
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,20 @@
end

response = SoundcloudParty.get("/resolve", query: { url: "https://soundcloud.com/#{username}" }, follow_redirects: false)
return "Can't find a user with that name. Sorry." if response.code == 404
raise SoundcloudError.new(response) if response.code != 302
uri = URI.parse response.parsed_response["location"]
return "URL does not resolve to a user." if !uri.path.start_with?("/users/")
id = uri.path[/\d+/]
if response.code == 302
uri = URI.parse response.parsed_response["location"]
return "URL does not resolve to a user." if !uri.path.start_with?("/users/")
id = uri.path[/\d+/]
elsif response.code == 404 && username.numeric?
response = SoundcloudParty.get("/users/#{username}")
return "Can't find a user with that id. Sorry." if response.code == 404
raise SoundcloudError.new(response) if !response.success?
id = response.parsed_response["id"]
elsif response.code == 404
return "Can't find a user with that name. Sorry."
else
raise SoundcloudError.new(response)
end

response = SoundcloudParty.get("/users/#{id}")
raise SoundcloudError.new(response) if !response.success?
Expand Down

0 comments on commit 2f6d914

Please sign in to comment.