Class: Glib::JsonCrawler::WindowsOpen

Inherits:
ActionCrawler show all
Defined in:
lib/glib/json_crawler/action_crawlers/windows_open.rb

Instance Method Summary collapse

Methods inherited from ActionCrawler

#click, #crawl, #perform

Constructor Details

#initialize(http, args, action) ⇒ WindowsOpen

Returns a new instance of WindowsOpen.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/glib/json_crawler/action_crawlers/windows_open.rb', line 4

def initialize(http, args, action)
  @http = http

  if (url = args['url'])
    json = @http.get(url, action, args.except('url'))

    unless json.nil?
      @http.router.begin_page(json, url)

      crawl json['header']&.[]('childViews')
      crawl json['body']&.[]('childViews')
      crawl json['footer']&.[]('childViews')

      json['rightButtons']&.each do |button|
        if button['buttons'].present?
          button['buttons'].each do |inner_button|
            click inner_button
          end
        else
          click button
        end
      end

      if (on_load = args.fetch('onLoad', nil))
        perform(on_load)
      end

      @http.router.end_page(json)
    end
  end
end