Class: RemoteDroid::Control

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

Instance Method Summary collapse

Constructor Details

#initialize(dev = nil, deviceid: dev, remote_url: nil, debug: false) ⇒ Control

Returns a new instance of Control.



649
650
651
652
653
# File 'lib/remotedroid.rb', line 649

def initialize(dev=nil, deviceid: dev, remote_url: nil, debug: false)
  
  @deviceid, @remote_url, @debug = deviceid, remote_url, debug
  @torch = Torch.new(self)
end

Instance Method Details

#bluetoothObject



655
656
657
# File 'lib/remotedroid.rb', line 655

def bluetooth()
  @bluetooth
end

#camera_flash_light(options = {}) ⇒ Object



659
660
661
# File 'lib/remotedroid.rb', line 659

def camera_flash_light(options={})
  http_exec 'camera-flash-light', options
end

#hotspot(state = nil) ⇒ Object



663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/remotedroid.rb', line 663

def hotspot(state=nil)      
  
  if state then
    http_exec 'hotspot', {enable: state == :enable} 
  else        

    def self.enable()
      http_exec 'hotspot', {enable: true}
    end                
    
    def self.on()
      self.enable
    end                
    
    def self.disable()
      http_exec 'hotspot', {enable: false} 
    end
    
    def self.off()
      self.disable
    end         
    
    self
    
  end
end

#http_exec(command, options = {}) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'lib/remotedroid.rb', line 690

def http_exec(command, options={})
  
  url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command]
  
  if options and options.any? then
    h = options
    url += '?' + \
        URI.escape(h.map {|key,value| "%s=%s" % [key, value]}.join('&'))
  end
  
  s = open(url).read
  
end

#location(options = {}) ⇒ Object



704
705
706
# File 'lib/remotedroid.rb', line 704

def location(options={})
  http_exec 'location'
end

#method_missing2(method_name, *args) ⇒ Object



780
781
782
# File 'lib/remotedroid.rb', line 780

def method_missing2(method_name, *args)
  http_exec(method_name, args.first)
end

#say_current_time(options = {}) ⇒ Object Also known as: say_time



708
709
710
# File 'lib/remotedroid.rb', line 708

def say_current_time(options={})
  http_exec 'say-current-time'
end

#screen(state = nil) ⇒ Object



714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/remotedroid.rb', line 714

def screen(state=nil)      
  
  if state then
    http_exec 'screen', {on: state == :on} 
  else        
    
    def self.on()
      http_exec 'screen', {on: true}
    end
    
    def self.off()
      http_exec 'screen', {on: false} 
    end
    
    self
    
  end
end

#share_location(options = {}) ⇒ Object



733
734
735
# File 'lib/remotedroid.rb', line 733

def share_location(options={})
  http_exec 'share-location'
end

#speak_text(obj) ⇒ Object Also known as: say



737
738
739
740
741
742
743
744
745
746
747
# File 'lib/remotedroid.rb', line 737

def speak_text(obj)
  
  options = case obj
  when String
    {text: obj}
  when Hash
    obj
  end

  http_exec 'speak-text', options
end

#take_picture(options = {}) ⇒ Object Also known as: take_photo



751
752
753
# File 'lib/remotedroid.rb', line 751

def take_picture(options={})
  http_exec :'take-picture', options
end

#toast(options = {}) ⇒ Object



758
759
760
# File 'lib/remotedroid.rb', line 758

def toast(options={})
  http_exec :toast, options
end

#torch(options = {}) ⇒ Object



762
763
764
# File 'lib/remotedroid.rb', line 762

def torch(options={})
  http_exec :torch 
end

#vibrate(options = {}) ⇒ Object



766
767
768
# File 'lib/remotedroid.rb', line 766

def vibrate(options={})
  http_exec :vibrate
end

#write(s) ⇒ Object Also known as: export



771
772
773
774
775
776
# File 'lib/remotedroid.rb', line 771

def write(s)
        
  MacroDroid.new(RD_MACROS, deviceid: @deviceid, 
                 remote_url: @remote_url, debug: @debug).export s
  
end