Created
May 1, 2015 20:42
-
-
Save DougEverly/ebd52f2638a20482146b to your computer and use it in GitHub Desktop.
Crystal calling libcurl
This file contains hidden or 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
| @[Link("curl")] | |
| lib LibCurl | |
| type CURL = Void* | |
| type CURLoption = Int32 | |
| fun create = curl_easy_init(): CURL | |
| fun set_opt = curl_easy_setopt(CURL, Int32, UInt8*) | |
| fun get = curl_easy_perform(CURL) | |
| fun cleanup = curl_easy_cleanup(CURL) | |
| end | |
| class Curl | |
| def initialize | |
| @curl = LibCurl.create | |
| end | |
| def get(url = "http://www.google.com") | |
| if @curl | |
| LibCurl.set_opt(@curl, 10002, url) | |
| res = LibCurl.get(@curl) | |
| end | |
| end | |
| def finalize | |
| LibCurl.cleanup(@curl) | |
| end | |
| end | |
| curl = Curl.new | |
| curl.get | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment