Crystal HTTP Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> crystal --version | |
Crystal 0.23.1 [e2a1389] (2017-07-13) LLVM 3.8.1 | |
> ./songsearch radiohead | |
#<HTTP::Client::Response:0x8384ea8> | |
HTTP::Headers{"Server" => "nginx", "Date" => "Thu, 24 Aug 2017 19:29:09 GMT", "Content-Type" => "text/html", "Content-Length" => "178", "Connection" => "keep-alive", "Location" => "https://www.azlyrics.com/r/radiohead"} | |
301 | |
Unexpected end of http response (Exception) | |
0x80c2279: *CallStack::unwind:Array(Pointer(Void)) at ?? | |
0x8188a00: exec_internal at /opt/crystal/src/http/client.cr 498:0 | |
0x81853ca: exec at /opt/crystal/src/http/client.cr 483:5 | |
0x818508b: exec at /opt/crystal/src/http/client.cr 586:5 | |
0x8184864: exec at /opt/crystal/src/http/client.cr 612:7 | |
0x8184598: get at /opt/crystal/src/http/client.cr 329:3 | |
0x818454d: request at /home/**/dev/songsearch/src/songsearch/http.cr 9:5 | |
0x80a5c39: __crystal_main at /home/**/dev/songsearch/src/songsearch.cr 10:1 | |
0x80b8bfd: main at /opt/crystal/src/main.cr 12:15 | |
0xb7371533: __libc_start_main at ?? | |
0x80a51a1: ??? at ?? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./songsearch/*" | |
module SongSearch | |
extend self | |
end | |
artist = ARGV[0] | |
puts SongSearch.request("https://azlyrics.com/#{artist[0]}/#{artist}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "http/client" | |
module SongSearch | |
def request(url) | |
resp = HTTP::Client.get(url) | |
resp = HTTP::Client.get(resp.headers["Location"]) if resp.status_code == 301 | |
resp | |
end # request | |
end # SongSearch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment