Class: Line::Bot::Request

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

Constant Summary

BASE_URL =
'https://trialbot-api.line.me'.freeze

Instance Method Summary (collapse)

Constructor Details

- (Request) initialize(client, request_method, path, options = {})

Returns a new instance of Request



11
12
13
14
15
16
17
# File 'lib/line/bot/request.rb', line 11

def initialize(client, request_method, path, options = {})
  @client         = client
  @request_method = request_method
  @uri            = URI(BASE_URL + path)
  @path           = @uri.path
  @options        = options
end

Instance Method Details

- (Object) perform



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/line/bot/request.rb', line 19

def perform
  response = http_client.send(@request_method) do |req|
    req.url @path
    req.headers = Line::Bot::Headers.new(@client, @request_method, @uri).request_headers
    req.params = @options
    if @request_method == :get
      req.params = @options unless @options == {}
    else
      req.body = @options.to_json
    end
  end

  {
    status: response.status,
    body: response.body
  }
end