class Line::Bot::HTTPClient

Attributes

http_options[RW]

@return [Hash]

Public Class Methods

new(http_options = {}) click to toggle source

Initialize a new HTTPClient

@param http_options [Hash]

@return [Line::Bot::HTTPClient]

# File lib/line/bot/httpclient.rb, line 30
def initialize(http_options = {})
  @http_options = http_options
end

Public Instance Methods

delete(url, header = {}) click to toggle source
# File lib/line/bot/httpclient.rb, line 63
def delete(url, header = {})
  uri = URI(url)
  http(uri).delete(uri.request_uri, header)
end
get(url, header = {}) click to toggle source
# File lib/line/bot/httpclient.rb, line 48
def get(url, header = {})
  uri = URI(url)
  http(uri).get(uri.request_uri, header)
end
http(uri) click to toggle source

@return [Net::HTTP]

# File lib/line/bot/httpclient.rb, line 35
def http(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == "https"
    http.use_ssl = true
  end

  http_options&.each do |key, value|
    http.send("#{key}=", value)
  end

  http
end
post(url, payload, header = {}) click to toggle source
# File lib/line/bot/httpclient.rb, line 53
def post(url, payload, header = {})
  uri = URI(url)
  http(uri).post(uri.request_uri, payload, header)
end
put(url, payload, header = {}) click to toggle source
# File lib/line/bot/httpclient.rb, line 58
def put(url, payload, header = {})
  uri = URI(url)
  http(uri).put(uri.request_uri, payload, header)
end