class OpenWebPageAction

Category: Applications

Public Class Methods

new(obj={}, macro=nil) click to toggle source
Calls superclass method ApplicationAction::new
# File lib/ruby-macrodroid/actions.rb, line 207
def initialize(obj={}, macro=nil)

  $debug = true    
  puts ('obj: ' + obj.inspect).debug if $debug
  
  h = if obj.is_a? Hash then
  
    obj.merge({macro: macro}) #unless obj and obj[:macro]
    
  elsif obj.is_a? Array
    
    puts ('obj: ' + obj.inspect).debug if $debug
    e, macro, h3 = obj
    
    a = e.xpath('item/*')

    h2 = if a.any? then
    
      a.map do |node|
        
        if node.name == 'description' then
          if node.text.to_s =~ /: / then
            node.text.to_s.split(/: +/,2).map(&:strip)
          else
            [:url, node.text.to_s]
          end
        else
          [node.name.to_sym, node.text.to_s.strip]
        end
        
      end.to_h
      
    else
      txt = e.text('item/description')
      {url: (txt || e.text)}
    end      
    
    h2.merge(macro: macro).merge(h3)

  end

  puts ('h:' + h.inspect).debug if $debug
  
  #h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1

  options = {
    #variable_to_save_response: {:string_value=>"", :name=>"coords",
    #decimal_value: 0.0, isLocal: true, m_boolean_value: false,
    #excludeFromLog: false, int_value: 0, type: 2},
    url_to_open: '',
    http_get: true,
    disable_url_encode: false,
    block_next_action: false
  }
  
  return super(options.merge h) if h[:url_to_open]
  
  if h[:macro].remote_url.nil? and (h[:url].nil? or h[:url].empty?) then
    raise OpenWebPageActionError, 'remote_url not found'
  end
  
  url = if h[:url] and h[:url].length > 1 then
  
    h[:url]      

  elsif h2 and h[:macro].remote_url and h[:identifier]
    
    "%s/%s" % [h[:macro].remote_url.sub(/\/$/,''), h[:identifier]]
    
  elsif (h[:identifier].nil? or h[:identifier].empty?)         
    
    h[:url_to_open] = h[:macro].remote_url.sub(/\/$/,'') + '/' + 
        h[:macro].title.downcase.gsub(/ +/,'-')            
    
  end        
  puts 'url: ' + url.inspect if $debug
  
  if h2 then
    
    h2.delete :identifier
    h2.delete :url
    
    if h2.any? then
      url += '?' + \
          URI.escape(h2.map {|key,value| "%s=%s" % [key, value]}.join('&'))
    end
    
  end
  
  h[:url_to_open] = url    
  super(options.merge h)

end

Public Instance Methods

invoke() click to toggle source
Calls superclass method Action#invoke
# File lib/ruby-macrodroid/actions.rb, line 301
def invoke()
  serverside = @h[:serverside].to_s.downcase == 'true'
  super(url_to_open: @h[:url_to_open], serverside: serverside)
end
to_s(colour: false, indent: 0) click to toggle source
Calls superclass method MacroObject#to_s
# File lib/ruby-macrodroid/actions.rb, line 306
def to_s(colour: false, indent: 0)
  s = @h[:http_get] ? '' : 'Open Website / '
  @s = s + "HTTP GET\nurl: " + @h[:url_to_open]
  super()
end