Module: Curlable

Included in:
Spn2
Defined in:
lib/curlable.rb

Overview

namespace

Instance Method Summary collapse

Instance Method Details

#get(url:, headers: {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/curlable.rb', line 7

def get(url:, headers: {})
  Curl::Easy.http_get(url) do |http|
    http.follow_location = true
    headers.each { |k, v| http.headers[k] = v }
  end.body_str
end

#post(url:, headers: {}, params: {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/curlable.rb', line 14

def post(url:, headers: {}, params: {})
  Curl::Easy.http_post("#{url}?#{Curl.postalize(params)}", Curl.postalize(params)) do |http|
    http.follow_location = true
    headers.each { |k, v| http.headers[k] = v }
  end.body_str
end