Class: Line::Bot::Certentials

Inherits:
Object
  • Object
show all
Defined in:
lib/line/bot/certentials.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Certentials

Returns a new instance of Certentials.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
# File 'lib/line/bot/certentials.rb', line 9

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  yield(self) if block_given?
end

Instance Attribute Details

#channel_idObject

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_midObject

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_secretObject

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

#payloadObject



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

Returns:

  • (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