Module: PlatformLib::WebHelper

Defined in:
lib/platform_lib/web_helper.rb

Class Method Summary collapse

Class Method Details

.get(uri, auth) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/platform_lib/web_helper.rb', line 6

def self.get(uri, auth)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == "https"
    http.use_ssl = true
  end

  request = Net::HTTP::Get.new(uri.request_uri)
  set_auth(request, auth)

  response = http.request(request)
  if block_given?
    yield(response.body)
  else
    response.body
  end
end

.post(uri, body) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/platform_lib/web_helper.rb', line 36

def self.post(uri, body)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == "https"
    http.use_ssl = true
  end

  request = Net::HTTP::Post.new(uri.request_uri)
  request.content_type = "application/json"
  request.body = body

  http.request(request)
end

.put(uri, body) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/platform_lib/web_helper.rb', line 23

def self.put(uri, body)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == "https"
    http.use_ssl = true
  end

  request = Net::HTTP::Put.new(uri.request_uri)
  request.content_type = "application/json"
  request.body = body
  
  http.request(request)
end