husc 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/husc/version.rb +1 -1
  3. data/lib/husc.rb +42 -41
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2ecc7f13a00dac04cd5ab80ee385bb90e04d730d235225829d749d3c77cac57
4
- data.tar.gz: 6a2e882ca3c00ecd12ebba69c98b72c8317d87226a441236214bd6f3cb25e9d5
3
+ metadata.gz: 432d286c2357f38cbe25dd64354018fcb9f376dd330d352d680f36d0fc8a5f72
4
+ data.tar.gz: d21d5c3b59bd316a1563a6f84f1dc054714a6fb92139de0b82b8b3881816a711
5
5
  SHA512:
6
- metadata.gz: e07266a3fb848360f8c3e8b367773c3fd0881c248d34940f05e549b8944a681ea637833aef4312f75256eeed88e22060d81a80c51516ca71a20ca93d9ea9a9d6
7
- data.tar.gz: 745f8810a558d0ef25a69a7113e987b0c45f70b56127662cfc8774e2d2a79b7925d1315d8daa76fe838ba155925f41040ea0a18bf2c79d002f224fc9bbbcec41
6
+ metadata.gz: 20774f8bb988212e92a8ea29de92bbf5c14a1d1fc7b458a58343b0c69237c61673e1a7dc0d197a436b22e74e86cbed09d4ca243a603aab8cfbb9bdf8d3595f7b
7
+ data.tar.gz: e186641c198e3c05557a1491e77c34b2b542f9b339077981e96f5579f643cac2b15302809162011feaaf4ed65ededaa7225b109cba102d0e0e3d3a2f32844399
data/lib/husc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Husc
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/husc.rb CHANGED
@@ -81,57 +81,58 @@ class Husc
81
81
  # ファイルアップロード => file(String)を指定
82
82
  # ボタンクリック => click(Bool)を指定
83
83
  @params << {}
84
- opts.each {|key, value| @params[-1][key.to_sym] = value}
84
+ opts = opts.map { |k, v| [k.to_sym, v] }.to_h
85
+ opts.each { |k, v| @params[-1][k.to_sym] = v }
85
86
  end
86
87
 
87
- def submit(url = @url, opt)
88
+ def submit(opts)
88
89
  ## -----*----- フォーム送信 -----*----- ##
89
- @agent.get(url) do |page|
90
- # フォーム指定
91
- if opt.kind_of?(Integer)
92
- form = page.forms[opt]
93
- else
94
- form = page.form(**opt)
90
+ # フォーム指定
91
+ opts = opts.map { |k,v| [k.to_sym, v] }.to_h
92
+ if opts.kind_of?(Integer)
93
+ form = @agent.page.forms[opts]
94
+ else
95
+ form = @agent.page.form(**opts)
96
+ end
97
+ return if form.nil?
98
+ button = nil
99
+
100
+ @params.each do |param|
101
+ # テキスト,数値など
102
+ if param.include?(:value) && !param.include?(:check)
103
+ value = param.delete(:value)
104
+ next if value.nil?
105
+ form.field_with(**param).value = value unless form.field_with(**param).nil?
95
106
  end
96
- return if form.nil?
97
-
98
- @params.each do |param|
99
- # テキスト,数値など
100
- if param.include?(:value) && !param.include?(:check)
101
- value = param.delete(:value)
102
- next if value.nil?
103
- form.field_with(**param).value = value unless form.field_with(**param).nil?
104
- end
105
-
106
- # チェックボックス
107
- if param.include?(:check)
108
- check = param.delete(:check)
109
- next if check.nil?
110
- if check
111
- form.checkbox_with(**param).check unless form.checkbox_with(**param).nil?
112
- else
113
- form.checkbox_with(**param).uncheck unless form.checkbox_with(**param).nil?
114
- end
115
- end
116
107
 
117
- # ファイルアップロード
118
- if param.include?(:file)
119
- file = param.delete(:file)
120
- next if file.nil? || !File.exist?(file)
121
- form.file_upload_with(**param).file_name = file unless form.file_upload_with(**param).nil?
108
+ # チェックボックス
109
+ if param.include?(:check)
110
+ check = param.delete(:check)
111
+ next if check.nil?
112
+ if check
113
+ form.checkbox_with(**param).check unless form.checkbox_with(**param).nil?
114
+ else
115
+ form.checkbox_with(**param).uncheck unless form.checkbox_with(**param).nil?
122
116
  end
117
+ end
123
118
 
124
- # ボタンクリック
125
- if param.include?(:click)
126
- click = param.delete(:click)
127
- next unless click
128
- form.button_with(**param) unless form.button_with(**param).nil?
129
- end
119
+ # ファイルアップロード
120
+ if param.include?(:file)
121
+ file = param.delete(:file)
122
+ next if file.nil? || !File.exist?(file)
123
+ form.file_upload_with(**param).file_name = file unless form.file_upload_with(**param).nil?
130
124
  end
131
125
 
132
- form = form.submit
133
- update_params(form.content.toutf8)
126
+ # ボタンクリック
127
+ if param.include?(:click)
128
+ click = param.delete(:click)
129
+ next unless click
130
+ button = form.button_with(**param) unless form.button_with(**param).nil?
131
+ end
134
132
  end
133
+
134
+ form = @agent.submit(form, button)
135
+ update_params(form.content.toutf8)
135
136
  @params = []
136
137
  end
137
138
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: husc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Abe