Class: Line::Bot::Request
- Inherits:
-
Object
- Object
- Line::Bot::Request
- Defined in:
- lib/line/bot/request.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
-
#httpclient ⇒ Object
Returns the value of attribute httpclient.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#reply_token ⇒ Object
Returns the value of attribute reply_token.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #assert_for_getting_message ⇒ Object
- #assert_for_posting_message ⇒ Object
-
#get ⇒ Net::HTTPResponse
Get content of specified URL.
- #header ⇒ Hash
-
#initialize {|_self| ... } ⇒ Line::Bot::Request
constructor
Initializes a new Request.
- #payload ⇒ Hash
-
#post ⇒ Net::HTTPResponse
Post content of specified URL.
Constructor Details
#initialize {|_self| ... } ⇒ Line::Bot::Request
Initializes a new Request
28 29 30 |
# File 'lib/line/bot/request.rb', line 28 def initialize yield(self) if block_given? end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def credentials @credentials end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def endpoint @endpoint end |
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def endpoint_path @endpoint_path end |
#httpclient ⇒ Object
Returns the value of attribute httpclient.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def httpclient @httpclient end |
#messages ⇒ Object
Returns the value of attribute messages.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def @messages end |
#reply_token ⇒ Object
Returns the value of attribute reply_token.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def reply_token @reply_token end |
#to ⇒ Object
Returns the value of attribute to.
23 24 25 |
# File 'lib/line/bot/request.rb', line 23 def to @to end |
Instance Method Details
#assert_for_getting_message ⇒ Object
72 73 74 |
# File 'lib/line/bot/request.rb', line 72 def raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String) end |
#assert_for_posting_message ⇒ Object
76 77 78 |
# File 'lib/line/bot/request.rb', line 76 def raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String) end |
#get ⇒ Net::HTTPResponse
Get content of specified URL.
57 58 59 60 |
# File 'lib/line/bot/request.rb', line 57 def get httpclient.get(endpoint + endpoint_path, header) end |
#header ⇒ Hash
44 45 46 47 48 49 50 51 52 |
# 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 ⇒ Hash
33 34 35 36 37 38 39 40 41 |
# File 'lib/line/bot/request.rb', line 33 def payload payload = { to: to, replyToken: reply_token, messages: } payload.delete_if{|k, v| v.nil?}.to_json end |
#post ⇒ Net::HTTPResponse
Post content of specified URL.
67 68 69 70 |
# File 'lib/line/bot/request.rb', line 67 def post httpclient.post(endpoint + endpoint_path, payload, header) end |