Class: Oksky::Chat::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/oksky/chat/httpclient.rb

Instance Method Summary collapse

Instance Method Details

#get(url, payload = {}, header = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/oksky/chat/httpclient.rb', line 22

def get(url, payload = {},  header = {})
  uri = URI(url)
  unless payload.empty?
    uri.query = URI.encode_www_form(payload)
  end
  http(uri).get(uri.request_uri, header)
end

#http(uri) ⇒ Net::HTTP

Returns:

  • (Net::HTTP)


11
12
13
14
15
16
17
18
19
20
# File 'lib/oksky/chat/httpclient.rb', line 11

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

  http.set_debug_output($stderr) if ENV["RAILS_ENV"] == "development"

  http
end

#patch(url, payload, header = {}) ⇒ Object



40
41
42
43
# File 'lib/oksky/chat/httpclient.rb', line 40

def patch(url, payload, header = {})
  uri = URI(url)
  http(uri).patch(uri.request_uri, payload, header)
end

#post(url, payload, header = {}) ⇒ Object



30
31
32
33
# File 'lib/oksky/chat/httpclient.rb', line 30

def post(url, payload, header = {})
  uri = URI(url)
  http(uri).post(uri.request_uri, payload, header)
end

#put(url, payload, header = {}) ⇒ Object



35
36
37
38
# File 'lib/oksky/chat/httpclient.rb', line 35

def put(url, payload, header = {})
  uri = URI(url)
  http(uri).put(uri.request_uri, payload, header)
end