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.
-
#message ⇒ Object
Returns the value of attribute message.
-
#to_channel_id ⇒ Object
Returns the value of attribute to_channel_id.
-
#to_mid ⇒ Object
Returns the value of attribute to_mid.
Instance Method Summary collapse
- #content ⇒ Line::Bot::Message::Base#content
-
#get ⇒ Net::HTTPResponse
Get content of specified URL.
- #header ⇒ Hash
- #https ⇒ Net::HTTP
-
#initialize {|_self| ... } ⇒ LINE::Bot::Request
constructor
Initializes a new Request.
- #payload ⇒ Hash
-
#post ⇒ Net::HTTPResponse
Post content of specified URL.
- #to ⇒ Array
- #validate_for_getting_message ⇒ Object
- #validate_for_posting_message ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ LINE::Bot::Request
Initializes a new Request
14 15 16 |
# File 'lib/line/bot/request.rb', line 14 def initialize yield(self) if block_given? end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
9 10 11 |
# File 'lib/line/bot/request.rb', line 9 def credentials @credentials end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/line/bot/request.rb', line 9 def endpoint @endpoint end |
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
9 10 11 |
# File 'lib/line/bot/request.rb', line 9 def endpoint_path @endpoint_path end |
#message ⇒ Object
Returns the value of attribute message.
9 10 11 |
# File 'lib/line/bot/request.rb', line 9 def end |
#to_channel_id ⇒ Object
Returns the value of attribute to_channel_id.
9 10 11 |
# File 'lib/line/bot/request.rb', line 9 def to_channel_id @to_channel_id end |
#to_mid ⇒ Object
Returns the value of attribute to_mid.
9 10 11 |
# File 'lib/line/bot/request.rb', line 9 def to_mid @to_mid end |
Instance Method Details
#content ⇒ Line::Bot::Message::Base#content
40 41 42 |
# File 'lib/line/bot/request.rb', line 40 def content .content end |
#get ⇒ Net::HTTPResponse
Get content of specified URL.
72 73 74 75 |
# File 'lib/line/bot/request.rb', line 72 def get https.get(endpoint_path, header) end |
#header ⇒ Hash
57 58 59 60 61 62 63 64 65 |
# File 'lib/line/bot/request.rb', line 57 def header header = { 'Content-Type' => 'application/json; charset=UTF-8', 'User-Agent' => "LINE-BotSDK/#{Line::Bot::API::VERSION}", } hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h } header.merge(hash) end |
#https ⇒ Net::HTTP
19 20 21 22 23 24 25 26 27 |
# File 'lib/line/bot/request.rb', line 19 def https uri = URI(endpoint) https = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" https.use_ssl = true end https end |
#payload ⇒ Hash
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/line/bot/request.rb', line 45 def payload payload = { to: to, toChannel: to_channel_id, eventType: .event_type.to_s, content: content } payload.to_json end |
#post ⇒ Net::HTTPResponse
Post content of specified URL.
82 83 84 85 |
# File 'lib/line/bot/request.rb', line 82 def post https.post(endpoint_path, payload, header) end |
#to ⇒ Array
30 31 32 33 34 35 36 37 |
# File 'lib/line/bot/request.rb', line 30 def to raise ArgumentError, 'Wrong argument type `to_mid`' unless to_mid.instance_of?(String) || to_mid.instance_of?(Array) to = to_mid.instance_of?(String) ? [to_mid] : to_mid raise ArgumentError, 'Wrong argument type `to_mid`' unless to.size > 0 && to.reject {|item| item.instance_of?(String) } to end |
#validate_for_getting_message ⇒ Object
87 88 89 |
# File 'lib/line/bot/request.rb', line 87 def raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.instance_of?(String) end |
#validate_for_posting_message ⇒ Object
91 92 93 94 |
# File 'lib/line/bot/request.rb', line 91 def raise ArgumentError, 'Invalid argument `message`' unless .valid? raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.instance_of?(String) end |