Class: OpenWebPageAction

Inherits:
ApplicationAction show all
Defined in:
lib/ruby-macrodroid/actions.rb

Overview

Category: Applications

Instance Attribute Summary

Attributes inherited from Action

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods included from ObjectX

#action_to_object, #object_create, #varify

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = {}, macro = nil) ⇒ OpenWebPageAction

Returns a new instance of OpenWebPageAction.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/ruby-macrodroid/actions.rb', line 147

def initialize(obj={}, macro=nil)
  
 # puts 'obj: ' + obj[0].xml.inspect
  
  h = if obj.is_a? Hash then
  
    obj
    
  elsif obj.is_a? Array
    
    puts 'obj: ' + obj.inspect if $debug
    e, macro = obj
    
    a = e.xpath('item/*')

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

  end

  puts 'h:' + h.inspect 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        
  
  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

Instance Method Details

#invokeObject



225
226
227
# File 'lib/ruby-macrodroid/actions.rb', line 225

def invoke()
  super(url: @h[:url_to_open])
end

#to_s(colour: false, indent: 0) ⇒ Object



229
230
231
232
# File 'lib/ruby-macrodroid/actions.rb', line 229

def to_s(colour: false, indent: 0)
  @s = "HTTP GET\nurl: " + @h[:url_to_open]
  super()
end