Class: Rapid::Baps::Requests::Requester

Inherits:
Services::HandlerSet show all
Extended by:
Forwardable
Defined in:
lib/ury_rapid/baps/requests/requester.rb

Overview

An object that sends requests to the BAPS server on behalf of Rapid.

The Requester intercepts model changes and converts them to BAPS requests, sending them to BAPS via a requests queue.

The responses from the BAPS server are sent to the Responder, which updates the model accordingly.

The Requester delegates the request generation to several SubRequester objects, which are defined elsewhere.

Constant Summary collapse

HANDLER_MODULE =
Requests::Handlers

Instance Method Summary collapse

Constructor Details

#initialize(queue, logger) ⇒ Requester

Initialises the Requester

Examples:

Initialising a Requester with an EventMachine Queue.

queue = EventMachine::Queue.new
logger = ->(severity, message) { do_something }
requester = Rapid::Baps::Requests::Requester.new(queue, logger)

42
43
44
45
46
47
48
49
# File 'lib/ury_rapid/baps/requests/requester.rb', line 42

def initialize(queue, logger)
  @queue = queue
  @logger = logger

  log(:info, 'Initialising BAPS requester.')

  super()
end

Instance Method Details

#login_authenticate(username, password, seed) ⇒ void

This method returns an undefined value.

Sends credentials to the BAPS server to further log-in

login_initiate MUST have been called previously.

Examples:

Log into BAPS.

requester.('Elvis', 'hunter2', 'abc123')

104
105
106
107
108
109
# File 'lib/ury_rapid/baps/requests/requester.rb', line 104

def (username, password, seed)
  password_hash = Digest::MD5.hexdigest(password.to_s)
  full_hash = Digest::MD5.hexdigest(seed + password_hash)

  request(Codes::System::LOGIN) { string username.to_s, full_hash }
end

#login_initiatevoid

This method returns an undefined value.

Initiates the BAPS login procedure


84
85
86
# File 'lib/ury_rapid/baps/requests/requester.rb', line 84

def 
  request(Codes::System::SET_BINARY_MODE)
end

#login_synchronisevoid

This method returns an undefined value.

Instructs BAPS to synchronise its state with Rapid and start chatting


116
117
118
119
# File 'lib/ury_rapid/baps/requests/requester.rb', line 116

def 
  # Subcode 3: Synchronise and add to chat.
  request(Codes::System::SYNC, 3)
end

#request(code, subcode = 0) {|request| ... } ⇒ void

This method returns an undefined value.

Sends a request to the BAPS server

Examples:

Send a request.

requester.request(Rapid::Baps::Codes::Playlist::LOAD, chan) do |r|
  r.uint32(index)
end

Yield Parameters:

  • request (Request)

    The request that is about to be sent, so that it can have arguments added to it using the #uint32, #string and similar methods.


71
72
73
74
75
# File 'lib/ury_rapid/baps/requests/requester.rb', line 71

def request(code, subcode = 0, &block)
  request = Request.new(code, subcode)
  request.instance_exec(&block) if block
  request.to(@queue)
end