Class: Line::Bot::Certentials
- Inherits:
-
Object
- Object
- Line::Bot::Certentials
- Defined in:
- lib/line/bot/certentials.rb
Instance Attribute Summary collapse
-
#channel_id ⇒ Object
Returns the value of attribute channel_id.
-
#channel_mid ⇒ Object
Returns the value of attribute channel_mid.
-
#channel_secret ⇒ Object
Returns the value of attribute channel_secret.
Instance Method Summary collapse
-
#initialize(options = {}) {|_self| ... } ⇒ Certentials
constructor
A new instance of Certentials.
- #payload ⇒ Object
- #valid? ⇒ Boolean
- #validate_signature(body = "", channel_signature) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Certentials
Returns a new instance of Certentials.
9 10 11 12 13 14 15 |
# File 'lib/line/bot/certentials.rb', line 9 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Attribute Details
#channel_id ⇒ Object
Returns the value of attribute channel_id.
7 8 9 |
# File 'lib/line/bot/certentials.rb', line 7 def channel_id @channel_id end |
#channel_mid ⇒ Object
Returns the value of attribute channel_mid.
7 8 9 |
# File 'lib/line/bot/certentials.rb', line 7 def channel_mid @channel_mid end |
#channel_secret ⇒ Object
Returns the value of attribute channel_secret.
7 8 9 |
# File 'lib/line/bot/certentials.rb', line 7 def channel_secret @channel_secret end |
Instance Method Details
#payload ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/line/bot/certentials.rb', line 17 def payload { 'X-Line-ChannelID' => channel_id, 'X-Line-ChannelSecret' => channel_secret, 'X-Line-Trusted-User-With-ACL' => channel_mid } end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/line/bot/certentials.rb', line 25 def valid? payload.values.all? end |
#validate_signature(body = "", channel_signature) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/line/bot/certentials.rb', line 29 def validate_signature(body = "", channel_signature) return false unless !channel_signature.nil? && valid? hash = OpenSSL::HMAC::digest(OpenSSL::Digest::SHA256.new, channel_secret, body) signature = Base64.strict_encode64(hash) variable_secure_compare(channel_signature, signature) end |