class Cassia::ResponseHandlers::DiscoverAllServicesAndChars
Public Class Methods
new(access_controller, router: , device_mac: )
click to toggle source
# File lib/cassia/response_handlers/discover_all_services_and_chars.rb, line 4 def initialize(access_controller, router: , device_mac: ) @access_controller = access_controller @router = router @device_mac = device_mac end
Public Instance Methods
handle(response)
click to toggle source
# File lib/cassia/response_handlers/discover_all_services_and_chars.rb, line 10 def handle(response) if response.success? handle_success(response) else handle_failure(response) end response.success? end
Private Instance Methods
handle_failure(response)
click to toggle source
# File lib/cassia/response_handlers/discover_all_services_and_chars.rb, line 36 def handle_failure(response) @access_controller.error = response.body end
handle_success(response)
click to toggle source
# File lib/cassia/response_handlers/discover_all_services_and_chars.rb, line 21 def handle_success(response) device = @router.connected_devices.detect {|device| device.mac == @device_mac} response.body.each do |service| new_service = Service.new(uuid: service["uuid"], primary: service["primary"], handle: service["handle"]) if service["characteristics"] service["characteristics"].each do |char| new_char = Characteristic.new(char) new_service.characteristics << new_char device.characteristics << new_char end end device.services << new_service end end