Class: Line::Bot::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/line/bot/httpclient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_options = {}) ⇒ Line::Bot::HTTPClient

Initialize a new HTTPClient

Parameters:

  • http_options (Hash) (defaults to: {})


30
31
32
# File 'lib/line/bot/httpclient.rb', line 30

def initialize(http_options = {})
  @http_options = http_options
end

Instance Attribute Details

#http_optionsObject

@return [Hash]



23
24
25
# File 'lib/line/bot/httpclient.rb', line 23

def http_options
  @http_options
end

Instance Method Details

#delete(url, header = {}) ⇒ Object



60
61
62
63
# File 'lib/line/bot/httpclient.rb', line 60

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

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



50
51
52
53
# File 'lib/line/bot/httpclient.rb', line 50

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

#http(uri) ⇒ Net::HTTP

Returns:

  • (Net::HTTP)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

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

  http
end

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



55
56
57
58
# File 'lib/line/bot/httpclient.rb', line 55

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