Project

General

Profile

« Previous | Next » 

Revision e321ca6f

Added by Marc Dequènes over 13 years ago

  • ID e321ca6f2a16f3d882f0c1008a71b3f55cf9e102

[evol] created a DSL for client-side calls (several conditions (calls only at the moment) can be joined together in order to exploit parallel tasks via asynchronous calls)

View differences:

bin/mapmaker_client
include BotNet
def start_work
contact_peer("MapMaker") do |conv|
if conv
logger.info "Yo ! Conversation ready with MapMaker (#{conv.peer_name}) !"
conv.thread("plop") do |conv_thread|
conv_thread.call("/api_version", 2) do |reply|
case reply[:status]
when :ok
puts "Result:"
pp reply[:result]
when :decline
puts "Declined: #{reply[:reason]}"
when :error
exception = reply[:exception]
puts "EXCEPTION: [#{exception.severity} - #{exception.category}] #{exception.message}"
pp exception.inspect
else
puts "???"
end
# to test the closure through the inner instance_eval calls
toto = true
conversation_with "MapMaker" do
on_error do
puts "Halalalala !"
end
thread "super taiste" do
call :ver, "/api_version"
call :zones, "/DNS/Zones" if toto
on_error do
puts "Sniff !"
pp reply
end
on_success do
puts "Yahou !"
pp reply
call :gogogo, "/DNS"
on_error do
pp "Plouf"
pp reply
end
on_success do
pp "Hop!"
pp reply
end
end
else
logger.error "Could not connect to MapMaker"
stop
end
# in contact loop, in order to wait for conversation registration to happen
# or the bot would stop before contact is done
try_stop
#stop_bot :at_once
stop_bot :when_finished
end
end
end

Also available in: Unified diff