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_path ⇒ Object
Returns the value of attribute endpoint_path.
-
#message ⇒ Object
Returns the value of attribute message.
-
#to_mid ⇒ Object
Returns the value of attribute to_mid.
Instance Method Summary collapse
- #content ⇒ Object
- #get ⇒ Object
- #header ⇒ Object
- #https ⇒ Object
-
#initialize {|_self| ... } ⇒ Request
constructor
A new instance of Request.
- #payload ⇒ Object
- #post ⇒ Object
- #to ⇒ Object
- #validate_for_getting_message? ⇒ Boolean
- #validate_for_posting_message? ⇒ Boolean
Constructor Details
#initialize {|_self| ... } ⇒ Request
Returns a new instance of Request.
10 11 12 |
# File 'lib/line/bot/request.rb', line 10 def initialize yield(self) if block_given? end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
8 9 10 |
# File 'lib/line/bot/request.rb', line 8 def credentials @credentials end |
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
8 9 10 |
# File 'lib/line/bot/request.rb', line 8 def endpoint_path @endpoint_path end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/line/bot/request.rb', line 8 def @message end |
#to_mid ⇒ Object
Returns the value of attribute to_mid.
8 9 10 |
# File 'lib/line/bot/request.rb', line 8 def to_mid @to_mid end |
Instance Method Details
#content ⇒ Object
25 26 27 |
# File 'lib/line/bot/request.rb', line 25 def content .content end |
#get ⇒ Object
50 51 52 53 54 |
# File 'lib/line/bot/request.rb', line 50 def get raise ArgumentError, "Invalid arguments" unless https.get(endpoint_path, header) end |
#header ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/line/bot/request.rb', line 40 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 ⇒ Object
14 15 16 17 18 19 |
# File 'lib/line/bot/request.rb', line 14 def https https = Net::HTTP.new('trialbot-api.line.me', 443) https.use_ssl = true https end |
#payload ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/line/bot/request.rb', line 29 def payload payload = { to: to, toChannel: 1383378250, # Fixed value eventType: .event_type.to_s, content: content } payload.to_json end |
#post ⇒ Object
56 57 58 59 60 |
# File 'lib/line/bot/request.rb', line 56 def post raise ArgumentError, "Invalid arguments" unless https.post(endpoint_path, payload, header) end |
#to ⇒ Object
21 22 23 |
# File 'lib/line/bot/request.rb', line 21 def to to_mid.instance_of?(String) ? [to_mid] : to_mid end |
#validate_for_getting_message? ⇒ Boolean
62 63 64 |
# File 'lib/line/bot/request.rb', line 62 def !endpoint_path.nil? end |
#validate_for_posting_message? ⇒ Boolean
66 67 68 |
# File 'lib/line/bot/request.rb', line 66 def to.size > 0 && .valid? && endpoint_path end |