Class: Glib::JsonCrawler::FormsSubmit
- Inherits:
-
ActionCrawler
- Object
- ActionCrawler
- Glib::JsonCrawler::FormsSubmit
- Defined in:
- lib/glib/json_crawler/action_crawlers/forms_submit.rb
Instance Method Summary collapse
-
#initialize(http, form) ⇒ FormsSubmit
constructor
A new instance of FormsSubmit.
- #submit_update(view, action) ⇒ Object
Methods inherited from ActionCrawler
Constructor Details
#initialize(http, form) ⇒ FormsSubmit
Returns a new instance of FormsSubmit.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/glib/json_crawler/action_crawlers/forms_submit.rb', line 4 def initialize(http, form) super(http) raise 'Submit action needs to be inside a form' unless form @http = http method = form['method'] action = "forms/#{method}" case method when 'patch', 'put' submit_update(form, action) else url = form['url'] http.router.log action, url end end |
Instance Method Details
#submit_update(view, action) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/glib/json_crawler/action_crawlers/forms_submit.rb', line 23 def submit_update(view, action) url = view['url'] fields = [] params = {} @http.router.crawl_multiple view['childViews'], ->(child) do name = child['view'] if name.start_with?('fields/') fields << child include_params = case name when 'fields/check', 'fields/check-v1' child['checkValue'] == child['value'] else true end params[child['name']] = child['value'] if include_params end end json = @http.patch url, action, params perform(json['onResponse']) end |