module Cwbot::ApiRequest

Public Class Methods

build_request(url) click to toggle source
# File lib/cwbot/api_request.rb, line 7
def self.build_request(url)
  http = Net::HTTP.new(URI.parse(url).host,443)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  return http
end
get_request(url,api_key) click to toggle source
# File lib/cwbot/api_request.rb, line 24
def get_request(url,api_key)
  http = build_request(url)
  req = Net::HTTP::Get.new(URI.parse(url).path, {"X-ChatWorkToken" => api_key})
  http.start do |h|
    @response = h.request(req)
  end
  return @response
end
post_request(url,body,api_key) click to toggle source
# File lib/cwbot/api_request.rb, line 14
def post_request(url,body,api_key)
  http = build_request(url)
  req = Net::HTTP::Post.new(URI.parse(url).path, {"X-ChatWorkToken" => api_key})
  req.body = "body=#{body}"
  http.start do |h|
    @response = h.request(req)
  end
  return @response
end

Private Instance Methods

get_request(url,api_key) click to toggle source
# File lib/cwbot/api_request.rb, line 24
def get_request(url,api_key)
  http = build_request(url)
  req = Net::HTTP::Get.new(URI.parse(url).path, {"X-ChatWorkToken" => api_key})
  http.start do |h|
    @response = h.request(req)
  end
  return @response
end
post_request(url,body,api_key) click to toggle source
# File lib/cwbot/api_request.rb, line 14
def post_request(url,body,api_key)
  http = build_request(url)
  req = Net::HTTP::Post.new(URI.parse(url).path, {"X-ChatWorkToken" => api_key})
  req.body = "body=#{body}"
  http.start do |h|
    @response = h.request(req)
  end
  return @response
end