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_optionsHash

Returns:

  • (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



63
64
65
66
# 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 = {}) ⇒ Object



48
49
50
51
# 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) ⇒ Net::HTTP

Returns:

  • (Net::HTTP)


35
36
37
38
39
40
41
42
43
44
45
46
# 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 = {}) ⇒ Object



53
54
55
56
# 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 = {}) ⇒ Object



58
59
60
61
# 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