Class: Line::Bot::Request
- Inherits:
-
Object
- Object
- Line::Bot::Request
- Defined in:
- lib/line/bot/request.rb
Instance Attribute Summary collapse
-
#certentials ⇒ Object
Returns the value of attribute certentials.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
-
#event_type ⇒ Object
Returns the value of attribute event_type.
-
#message ⇒ Object
Returns the value of attribute message.
-
#to_mid ⇒ Object
Returns the value of attribute to_mid.
Instance Method Summary collapse
- #get ⇒ Object
- #header ⇒ Object
-
#initialize {|_self| ... } ⇒ Request
constructor
A new instance of Request.
- #payload ⇒ Object
- #post ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Request
Returns a new instance of Request.
7 8 9 |
# File 'lib/line/bot/request.rb', line 7 def initialize yield(self) if block_given? end |
Instance Attribute Details
#certentials ⇒ Object
Returns the value of attribute certentials.
5 6 7 |
# File 'lib/line/bot/request.rb', line 5 def certentials @certentials end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/line/bot/request.rb', line 5 def endpoint @endpoint end |
#endpoint_path ⇒ Object
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_type ⇒ Object
Returns the value of attribute event_type.
5 6 7 |
# File 'lib/line/bot/request.rb', line 5 def event_type @event_type end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/line/bot/request.rb', line 5 def @message end |
#to_mid ⇒ Object
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
#get ⇒ Object
36 37 38 |
# File 'lib/line/bot/request.rb', line 36 def get HTTP.get(endpoint + endpoint_path, header) end |
#header ⇒ Object
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 |
#payload ⇒ Object
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: .content }.to_json end |
#post ⇒ Object
40 41 42 |
# File 'lib/line/bot/request.rb', line 40 def post HTTP.post(endpoint + endpoint_path, payload, header) end |
#to ⇒ Object
11 12 13 |
# File 'lib/line/bot/request.rb', line 11 def to to_mid.is_a?(String) ? [to_mid] : to_mid end |