class Line::Bot::Request

Attributes

credentials[RW]
endpoint[RW]
endpoint_path[RW]
httpclient[RW]
messages[RW]
reply_token[RW]
to[RW]

Public Class Methods

new() { |self| ... } click to toggle source

Initializes a new Request

@return [Line::Bot::Request]

# File lib/line/bot/request.rb, line 28
def initialize
  yield(self) if block_given?
end

Public Instance Methods

assert_for_getting_message() click to toggle source
# File lib/line/bot/request.rb, line 72
def assert_for_getting_message
  raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
end
assert_for_posting_message() click to toggle source
# File lib/line/bot/request.rb, line 76
def assert_for_posting_message
  raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
end
get() click to toggle source

Get content of specified URL.

@return [Net::HTTPResponse]

# File lib/line/bot/request.rb, line 57
def get
  assert_for_getting_message
  httpclient.get(endpoint + endpoint_path, header)
end
header() click to toggle source

@return [Hash]

# File lib/line/bot/request.rb, line 44
def header
  header = {
    'Content-Type' => 'application/json; charset=UTF-8',
    'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}",
  }
  hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }

  header.merge(hash)
end
payload() click to toggle source

@return [Hash]

# File lib/line/bot/request.rb, line 33
def payload
  payload = {
    to: to,
    replyToken: reply_token,
    messages: messages
  }

  payload.delete_if{|k, v| v.nil?}.to_json
end
post() click to toggle source

Post content of specified URL.

@raise [ArgumentError]

@return [Net::HTTPResponse]

# File lib/line/bot/request.rb, line 67
def post
  assert_for_posting_message
  httpclient.post(endpoint + endpoint_path, payload, header)
end