Class: OpenWebPageAction
- Inherits:
-
ApplicationAction
- Object
- MacroObject
- Action
- ApplicationAction
- OpenWebPageAction
- Defined in:
- lib/ruby-macrodroid/actions.rb
Instance Attribute Summary
Attributes inherited from Action
Attributes inherited from MacroObject
Instance Method Summary collapse
-
#initialize(obj = {}, macro = nil) ⇒ OpenWebPageAction
constructor
A new instance of OpenWebPageAction.
- #invoke ⇒ Object
- #to_s(colour: false, indent: 0) ⇒ Object
Methods included from ObjectX
#action_to_object, #object_create, #varify
Methods inherited from MacroObject
Constructor Details
#initialize(obj = {}, macro = nil) ⇒ OpenWebPageAction
Returns a new instance of OpenWebPageAction.
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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/ruby-macrodroid/actions.rb', line 151 def initialize(obj={}, macro=nil) $debug = false puts ('obj: ' + obj.inspect).debug if $debug h = if obj.is_a? Hash then obj.merge({macro: macro}) elsif obj.is_a? Array puts ('obj: ' + obj.inspect).debug if $debug e, macro = obj a = e.xpath('item/*') h2 = if a.any? then a.map do |node| if node.name == 'description' and node.text.to_s =~ /: / then node.text.to_s.split(/: +/,2).map(&:strip) 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) end puts ('h:' + h.inspect).debug if $debug #h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1 = { #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(.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(.merge h) end |
Instance Method Details
#invoke ⇒ Object
240 241 242 |
# File 'lib/ruby-macrodroid/actions.rb', line 240 def invoke() super(url: @h[:url_to_open]) end |
#to_s(colour: false, indent: 0) ⇒ Object
244 245 246 247 |
# File 'lib/ruby-macrodroid/actions.rb', line 244 def to_s(colour: false, indent: 0) @s = "HTTP GET\nurl: " + @h[:url_to_open] super() end |