Class: Pepito::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/pepito/adapter.rb

Overview

Parent class for any adapter Adapters allow to communicate with the bot from differente platforms.

Constant Summary collapse

REQUIRED_METHODS =

List of required methods for adapters

%i(
  run
  send_messages
  topic
  stop
).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot, config) ⇒ void

Initializes the Adapter class

Parameters:

  • robot (Pepito::Robot)

    The currently running robot

  • config (Hash<String,String>)

    The config for the adapter



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/pepito/adapter.rb', line 59

def initialize(robot, config)
  @robot = robot
  @config = config

  begin
    missing_methods
    missing_configuration_values
  rescue => e
    raise e
  end
end

Instance Attribute Details

#configHash<String,String> (readonly)

Config hash for the adapter

Returns:

  • (Hash<String,String>)


53
54
55
# File 'lib/pepito/adapter.rb', line 53

def config
  @config
end

#robotPepito::Robot (readonly)

The currently running robot

Returns:



49
50
51
# File 'lib/pepito/adapter.rb', line 49

def robot
  @robot
end

Class Method Details

.configsArray<Hash>

Configs for the adapter, override this method in the adapter

Returns:

  • (Array<Hash>)

    Array of strings with the config parameters



11
12
13
# File 'lib/pepito/adapter.rb', line 11

def configs
  [{}]
end

Instance Method Details

#runvoid

This method is abstract.

This should be implemented by the adapter

This method returns an undefined value.

Runs the adapter



# File 'lib/pepito/adapter.rb', line 24

#send_messagesvoid

This method is abstract.

This should be implemented by the adapter

This method returns an undefined value.

Sends a message to the service

Parameters:

  • target (Pepito::Source)

    The target to send the message to

  • strings (Array<String>)

    Array of strings to send



# File 'lib/pepito/adapter.rb', line 29

#stopvoid

This method is abstract.

This should be implemented by the adapter

This method returns an undefined value.

Stops the adapter



# File 'lib/pepito/adapter.rb', line 42

#topicvoid

This method is abstract.

This should be implemented by the adapter

This method returns an undefined value.

Sets the topic of the channel

Parameters:

  • topic (String)

    the new topic



# File 'lib/pepito/adapter.rb', line 36