Sha256: e8d21be1c8d4accfefe3db4390b8f15a261ea65339e8306285ef04312fc27116

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require 'pleiades/core/client/wrapper'

module Pleiades
  module Client
    def self.included(base)
      include_modules = [Common]

      on_controller_class = ApplicationController.subclasses.include?(base)

      include_modules << Controller if on_controller_class

      include_modules.each do |mod|
        base.include mod
      end
    end

    module Common
      def self.included(base)
        base.class_eval <<~RUBY, __FILE__, __LINE__ + 1
          def client
            return @client if @client

            channel_secret, channel_token = Pleiades::Config.client_keys

            @client = Line::Bot::Client.new do |config|
              config.channel_secret = channel_secret
              config.channel_token = channel_token
            end
          end
        RUBY
      end
    end

    module Controller
      def validate_signature
        client.validate_signature(body, signature)
      end

      def signature
        request.env['HTTP_X_LINE_SIGNATURE']
      end

      def body
        @body ||= request.body.read
      end

      def events
        client.parse_events_from(body)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pleiades-0.1.6 lib/pleiades/core/client.rb
pleiades-0.1.5 lib/pleiades/core/client.rb
pleiades-0.1.4 lib/pleiades/core/client.rb
pleiades-0.1.3 lib/pleiades/core/client.rb
pleiades-0.1.2 lib/pleiades/core/client.rb