Class: Line::Bot::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Request

Returns a new instance of Request.

Yields:

  • (_self)

Yield Parameters:



7
8
9
# File 'lib/line/bot/request.rb', line 7

def initialize
  yield(self) if block_given?
end

Instance Attribute Details

#certentialsObject

Returns the value of attribute certentials.



5
6
7
# File 'lib/line/bot/request.rb', line 5

def certentials
  @certentials
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/line/bot/request.rb', line 5

def endpoint
  @endpoint
end

#endpoint_pathObject

Returns the value of attribute endpoint_path.



5
6
7
# File 'lib/line/bot/request.rb', line 5

def endpoint_path
  @endpoint_path
end

#event_typeObject

Returns the value of attribute event_type.



5
6
7
# File 'lib/line/bot/request.rb', line 5

def event_type
  @event_type
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/line/bot/request.rb', line 5

def message
  @message
end

#to_midObject

Returns the value of attribute to_mid.



5
6
7
# File 'lib/line/bot/request.rb', line 5

def to_mid
  @to_mid
end

Instance Method Details

#getObject



36
37
38
# File 'lib/line/bot/request.rb', line 36

def get
  HTTP.get(endpoint + endpoint_path, header)
end

#headerObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/line/bot/request.rb', line 25

def header
  header = {
    'Content-Type' => 'application/json; charset=UTF-8',
    'User-Agent' => "Line-Bot-Lite/#{Line::Bot::VERSION}"
  }
  return header if certentials.nil?
  hash = certentials.payload.inject({}) { |h, (k, v)| h[k] = v.to_s; h }

  header.merge(hash)
end

#payloadObject



15
16
17
18
19
20
21
22
23
# File 'lib/line/bot/request.rb', line 15

def payload
  {
    to: to,
    toChannel: API::MESSAGE_CHANNEL_ID, # Fixed value
    eventType: event_type.to_s,
    content: message.content

  }.to_json
end

#postObject



40
41
42
# File 'lib/line/bot/request.rb', line 40

def post
  HTTP.post(endpoint + endpoint_path, payload, header)
end

#toObject



11
12
13
# File 'lib/line/bot/request.rb', line 11

def to
  to_mid.is_a?(String) ? [to_mid] : to_mid
end