sakura-cli 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4bd482e0d86c365ea75946bc6831c56d30390b30121e289ad5ccdf7daeab02a
4
- data.tar.gz: e864d3491596ca9919c9a6e5001664e7affdef7281976a50f375bc8817cdbc5d
3
+ metadata.gz: ac03d20a6767f08291cca46ef03c77f8989fd22eb391050e64c6bd2b5cc57412
4
+ data.tar.gz: 06a3b0a39ec785fd73725260d5934a0520e22284e56948b03a1bfc24ac35d3d9
5
5
  SHA512:
6
- metadata.gz: 7594da6f2ca11dae4251fe0aba8d61f3860505adcb7005d5ce631c13e61ed8b2e23e93a5ee61404ec87ec812771f4cf031a228a6ea59e50ce84ac1e278770890
7
- data.tar.gz: '01519f5f2a7aa79001e770700ee4ef6abc80509dc21c405418c565bccc5b6945502ad32fe60f6ac1f3ed767fb088d379d85dec69405b06a5cd18629d8cc9ce3a'
6
+ metadata.gz: 2dfc7bfe8d8ded10cd65b4f37b1dd38e6b6e4fc4590a9ef77e94150390c51a40b75e35d13db0254af64f3d62442daa405bf471643187ee2350c6058398c5c82f
7
+ data.tar.gz: 3ed3c972a146fe265c66ed941c674252da339f7e243a9f75b608e893a277662cab57aefd307247084ce78e8e338e2c97aff86f4753e861f5fe41de3d497fa5dc
@@ -0,0 +1,38 @@
1
+ ---
2
+ exclude: ^bin/(bundle|dev|rails|rake|setup)$
3
+ repos:
4
+ - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
5
+ rev: v9.14.0
6
+ hooks:
7
+ - id: commitlint
8
+ stages: [ commit-msg ]
9
+ additional_dependencies: [ "@commitlint/config-conventional" ]
10
+
11
+ - repo: https://github.com/pre-commit/pre-commit-hooks
12
+ rev: v4.6.0
13
+ hooks:
14
+ - id: check-executables-have-shebangs
15
+ - id: check-merge-conflict
16
+ - id: check-symlinks
17
+ - id: detect-private-key
18
+ - id: check-json
19
+ - id: check-yaml
20
+ - id: check-toml
21
+ - id: pretty-format-json
22
+ args: [ "--autofix", "--no-sort-keys" ]
23
+ - id: debug-statements
24
+ - id: mixed-line-ending
25
+ - id: trailing-whitespace
26
+ - id: end-of-file-fixer
27
+ exclude: ^config/credentials.yml.enc$
28
+
29
+ # ruby
30
+
31
+ - repo: https://github.com/rubocop/rubocop
32
+ rev: v1.62.1
33
+ hooks:
34
+ - id: rubocop
35
+ args:
36
+ - "-A"
37
+ additional_dependencies:
38
+ - rubocop-rails
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/ClassLength:
5
+ Enabled: false
6
+
7
+ Metrics/MethodLength:
8
+ Enabled: false
9
+
10
+ Metrics/BlockLength:
11
+ Enabled: false
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Enabled: false
18
+
19
+ Metrics/PerceivedComplexity:
20
+ Enabled: false
21
+
22
+ AllCops:
23
+ NewCops: enable
24
+ Exclude:
25
+ - gem/**/*
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in sakura-cli.gemspec
4
6
  gemspec
7
+
8
+ group :development do
9
+ gem 'bundler'
10
+ gem 'rake'
11
+ gem 'rubocop'
12
+ end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2022 Shintaro Kojima
3
+ Copyright (c) 2015-2024 Shintaro Kojima
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -181,4 +181,4 @@ dotenv -f ~/.sakura.env sakura
181
181
 
182
182
  ## Copyright and License
183
183
 
184
- Copyright (c) 2015-2022 Shintaro Kojima. Code released under the [MIT license](LICENSE).
184
+ Copyright (c) 2015-2024 Shintaro Kojima. Code released under the [MIT license](LICENSE).
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rake/testtask'
@@ -7,4 +9,4 @@ Rake::TestTask.new do |t|
7
9
  end
8
10
 
9
11
  desc 'Run tests'
10
- task :default => :test
12
+ task default: :test
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ extends: ["@commitlint/config-conventional"],
3
+ rules: {
4
+ // "scope-case": [1, "always"],
5
+ // "subject-case": [1, "always"],
6
+ // "body-max-line-length": [1, "always", 100],
7
+ },
8
+ };
data/exe/sakura CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
 
5
- $: << File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
6
+ $LOAD_PATH << File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
6
7
 
7
8
  require 'sakura/cli/root'
8
9
  Sakura::Cli::Root.start
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
1
4
  require 'thor'
2
5
  require 'sakura'
3
6
  require 'sakura/client'
@@ -15,7 +18,7 @@ module Sakura
15
18
 
16
19
  puts "# domain: #{Client.current_session.domain}"
17
20
  puts MailAddress.header
18
- addrs.each { |addr| puts addr.to_s }
21
+ addrs.each { |addr| puts addr }
19
22
  end
20
23
 
21
24
  desc 'create LOCAL_PART [PASSWORD]', 'Create a mail address'
@@ -27,9 +30,10 @@ module Sakura
27
30
 
28
31
  begin
29
32
  MailAddress.create local_part, password
30
- rescue
33
+ rescue StandardError
31
34
  raise if options[:verbose]
32
- abort $!
35
+
36
+ abort $ERROR_INFO
33
37
  end
34
38
  end
35
39
 
@@ -40,9 +44,10 @@ module Sakura
40
44
 
41
45
  begin
42
46
  find(local_part).delete
43
- rescue
47
+ rescue StandardError
44
48
  raise if options[:verbose]
45
- abort $!
49
+
50
+ abort $ERROR_INFO
46
51
  end
47
52
  end
48
53
 
@@ -59,9 +64,10 @@ module Sakura
59
64
  else
60
65
  puts mail.quota
61
66
  end
62
- rescue
67
+ rescue StandardError
63
68
  raise if options[:verbose]
64
- abort $!
69
+
70
+ abort $ERROR_INFO
65
71
  end
66
72
  end
67
73
 
@@ -75,9 +81,10 @@ module Sakura
75
81
 
76
82
  begin
77
83
  mail.password = password
78
- rescue
84
+ rescue StandardError
79
85
  raise if options[:verbose]
80
- abort $!
86
+
87
+ abort $ERROR_INFO
81
88
  end
82
89
  end
83
90
 
@@ -99,9 +106,10 @@ module Sakura
99
106
  when nil
100
107
  puts mail.virus_scan
101
108
  end
102
- rescue
109
+ rescue StandardError
103
110
  raise if options[:verbose]
104
- abort $!
111
+
112
+ abort $ERROR_INFO
105
113
  end
106
114
  end
107
115
 
@@ -110,9 +118,7 @@ module Sakura
110
118
  def forward(local_part, operation = nil, mail_to_forward = nil)
111
119
  preprocess
112
120
 
113
- if (operation && operation !~ /add|remove/) || (!mail_to_forward && operation)
114
- self.class.handle_argument_error
115
- end
121
+ self.class.handle_argument_error if (operation && operation !~ /add|remove/) || (!mail_to_forward && operation)
116
122
 
117
123
  mail = find(local_part)
118
124
 
@@ -125,9 +131,10 @@ module Sakura
125
131
  when nil
126
132
  mail.forward_list.each { |m| puts m }
127
133
  end
128
- rescue
134
+ rescue StandardError
129
135
  raise if options[:verbose]
130
- abort $!
136
+
137
+ abort $ERROR_INFO
131
138
  end
132
139
  end
133
140
 
@@ -149,9 +156,10 @@ module Sakura
149
156
  when nil
150
157
  puts mail.keep
151
158
  end
152
- rescue
159
+ rescue StandardError
153
160
  raise if options[:verbose]
154
- abort $!
161
+
162
+ abort $ERROR_INFO
155
163
  end
156
164
  end
157
165
 
@@ -171,9 +179,10 @@ module Sakura
171
179
  else
172
180
  mail.spam_filter = value.to_sym
173
181
  end
174
- rescue
182
+ rescue StandardError
175
183
  raise if options[:verbose]
176
- abort $!
184
+
185
+ abort $ERROR_INFO
177
186
  end
178
187
  end
179
188
 
@@ -196,6 +205,7 @@ module Sakura
196
205
  mail = MailAddress.find(local_part)
197
206
  rescue Capybara::ElementNotFound
198
207
  raise if options[:verbose]
208
+
199
209
  abort %(No mail address: "#{local_part}")
200
210
  end
201
211
 
@@ -213,7 +223,7 @@ module Sakura
213
223
  end
214
224
 
215
225
  def abort(message)
216
- super "\nERROR: #{message}"
226
+ super("\nERROR: #{message}")
217
227
  end
218
228
  end
219
229
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'sakura/cli/mail'
3
5
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sakura
2
4
  module Cli
3
- VERSION = "0.2.1"
5
+ VERSION = '0.3.0'
4
6
  end
5
7
  end
data/lib/sakura/client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'capybara/dsl'
2
4
  require 'selenium-webdriver'
3
5
 
@@ -11,16 +13,15 @@ module Sakura
11
13
  include Capybara::DSL
12
14
 
13
15
  attr_reader :domain
14
- @@verbose = false
16
+
17
+ @verbose = false
15
18
 
16
19
  class << self
20
+ attr_accessor :verbose
21
+
17
22
  def current_session
18
23
  @current_session ||= new
19
24
  end
20
-
21
- def verbose=(bool)
22
- @@verbose = !!bool
23
- end
24
25
  end
25
26
 
26
27
  def initialize
@@ -32,19 +33,25 @@ module Sakura
32
33
  end
33
34
 
34
35
  def login
35
- $stderr.puts 'login' if @@verbose
36
+ warn 'login' if self.class.verbose
36
37
 
37
38
  visit BASE_URL
38
- fill_in 'login-username', with: @domain
39
- fill_in 'login-password', with: @passwd
39
+ fill_in 'username', with: @domain
40
+ fill_in 'password', with: @passwd
40
41
  find('form button[type=submit]').click
41
42
 
42
- wait_for_loading
43
+ if has_text?('認証コード')
44
+ puts '認証コード:'
45
+ otp = $stdin.gets
43
46
 
44
- if page.text =~ /サーバコントロールパネル ホーム/
45
- @logged_in = true
47
+ fill_in 'login-otp', with: otp
48
+ find('form button[type=submit]').click
46
49
  end
47
50
 
51
+ wait_for_loading
52
+
53
+ @logged_in = true if page.text =~ /サーバーコントロールパネル ホーム/
54
+
48
55
  raise_when_error
49
56
  login?
50
57
  end
@@ -52,23 +59,22 @@ module Sakura
52
59
  def get(url, expected)
53
60
  login unless login?
54
61
 
55
- $stderr.puts "visit #{url}" if @@verbose
62
+ warn "visit #{url}" if self.class.verbose
56
63
  visit url
57
64
  wait_for_loading
58
- unless page.text =~ expected
59
- raise Timeout::Error.new('Timed out')
60
- end
65
+ raise Timeout::Error, 'Timed out' unless page.text =~ expected
61
66
 
62
67
  page
63
68
  end
64
69
 
65
- def process(url, expected, &block)
70
+ def process(url, expected)
66
71
  login unless login?
67
72
 
68
73
  get url, expected
69
74
  yield page
70
75
 
71
76
  raise_when_error
77
+ wait_for_loading
72
78
  page
73
79
  end
74
80
 
@@ -94,11 +100,9 @@ module Sakura
94
100
 
95
101
  def wait_for_loading
96
102
  5.times do
97
- if find_all('読み込み中').empty?
98
- break
99
- else
100
- $stderr.puts 'still loading ...' if @@verbose
101
- end
103
+ break if all('読み込み中').empty?
104
+
105
+ warn 'still loading ...' if self.class.verbose
102
106
  end
103
107
  end
104
108
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sakura/client'
2
4
 
3
5
  module Sakura
4
6
  class MailAddress
5
- MAIL_URL = BASE_URL + 'users/list/'
7
+ MAIL_URL = "#{BASE_URL}users/list/".freeze
6
8
 
7
9
  attr_reader :address, :usage, :quota, :link
8
10
 
@@ -13,9 +15,10 @@ module Sakura
13
15
 
14
16
  page.find(:xpath, '//label[contains(text(), "ユーザ名")]/..//input')
15
17
  .fill_in with: local_part
16
- page.find_all(:xpath, '//label[contains(text(), "パスワード")]/..//input').each do |e|
18
+ page.all(:xpath, '//label[contains(text(), "パスワード")]/..//input').each do |e|
17
19
  e.fill_in with: password
18
20
  end
21
+ page.find(:xpath, '//label[contains(text(), "メールの受信")]/..//*[contains(text(), "受信する")]/../input').choose
19
22
  page.find(:xpath, '//button[text() = "作成する"]').click
20
23
  end
21
24
 
@@ -24,25 +27,32 @@ module Sakura
24
27
 
25
28
  def all
26
29
  page = Client.current_session.get(MAIL_URL, /メールアドレス一覧/)
27
- page.first('.input-text').select '300件'
30
+ page.find('.input-text.page-limit-selector').select '300件'
31
+ wait_for_loading page
28
32
 
29
- page.all(:css, '.entity-lists .entity-lists-row').map { |element|
33
+ page.all('.entities-item').map do |element|
30
34
  MailAddress.new_from_element(element)
31
- }
35
+ end
32
36
  end
33
37
 
34
38
  def find(local_part)
35
39
  page = Client.current_session.get(MAIL_URL, /メールアドレス一覧/)
36
- page.first('.input-text').select '300件'
37
-
38
- element = page.find(:xpath, "//div[contains(@class, \"entity-lists-row\")]//div[@class=\"username\" and contains(text(), \"#{local_part}\")]/../../..")
40
+ page.find('.input-text.page-limit-selector').select '300件'
41
+ wait_for_loading page
42
+
43
+ element = page.find(
44
+ :xpath,
45
+ # rubocop:disable Layout/LineLength
46
+ "//div[contains(@class, \"entities-item\")]//div[@class=\"username\" and contains(text(), \"#{local_part}\")]/../../.."
47
+ # rubocop:enable Layout/LineLength
48
+ )
39
49
  MailAddress.new_from_element(element)
40
50
  end
41
51
 
42
52
  def new_from_element(element)
43
53
  MailAddress.new(
44
54
  element.find('.username').text.split('@').first,
45
- element.find('.capacity').text
55
+ element.find('.col-usage').text
46
56
  )
47
57
  end
48
58
 
@@ -57,11 +67,21 @@ module Sakura
57
67
  args[2].to_s.rjust(10) <<
58
68
  " (#{args[3].to_s.rjust(3)})"
59
69
  end
70
+
71
+ private
72
+
73
+ def wait_for_loading(page)
74
+ 5.times do
75
+ break if page.all('読み込み中').empty?
76
+
77
+ warn 'still loading ...' if self.class.verbose
78
+ end
79
+ end
60
80
  end
61
81
 
62
82
  def initialize(address, usage)
63
83
  @address = address
64
- @usage, @quota = usage.split(/\s*\/\s*/)
84
+ @usage, @quota = usage.split(%r{\s*/\s*|\s+})
65
85
  end
66
86
 
67
87
  def delete
@@ -80,16 +100,16 @@ module Sakura
80
100
  Client.current_session.process(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/) do |page|
81
101
  case value
82
102
  when /(\d+)\s*GB$/
83
- page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: $1
103
+ page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: ::Regexp.last_match(1)
84
104
  page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//select').select 'GB'
85
105
  when /(\d+)\s*MB$/
86
- page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: $1
106
+ page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: ::Regexp.last_match(1)
87
107
  page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//select').select 'MB'
88
108
  when /(\d+)\s*KB$/
89
- page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: $1
109
+ page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: ::Regexp.last_match(1)
90
110
  page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//select').select 'KB'
91
111
  when /(\d+)\s*B$/
92
- page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: $1
112
+ page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//input').fill_in with: ::Regexp.last_match(1)
93
113
  page.find(:xpath, '//label[contains(text(), "メール容量制限")]/..//select').select 'B'
94
114
  else
95
115
  raise %(Unsupported quota value "#{value}")
@@ -104,7 +124,7 @@ module Sakura
104
124
  def password=(value)
105
125
  # FIXME: The URL won't work when mail addresses are more than 300
106
126
  Client.current_session.process(MAIL_URL + "1/password/#{@address}", /#{@address}のパスワード設定/) do |page|
107
- page.find_all(:xpath, '//label[contains(text(), "パスワード")]/..//input').each do |e|
127
+ page.all(:xpath, '//label[contains(text(), "パスワード")]/..//input').each do |e|
108
128
  e.fill_in with: value
109
129
  end
110
130
  page.find(:xpath, '//button[text() = "変更する"]').click
@@ -115,7 +135,7 @@ module Sakura
115
135
  if @virus_scan.nil?
116
136
  # FIXME: The URL won't work when mail addresses are more than 300
117
137
  page ||= Client.current_session.get(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/)
118
- @virus_scan = page.find('[name="usesVirusCheck"]:checked').value == '1'
138
+ @virus_scan = page.find('[name="usesMailVirusCheck"]:checked').value == '1'
119
139
  end
120
140
 
121
141
  @virus_scan
@@ -124,7 +144,7 @@ module Sakura
124
144
  def virus_scan=(value)
125
145
  # FIXME: The URL won't work when mail addresses are more than 300
126
146
  Client.current_session.process(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/) do |page|
127
- page.find("[name='usesVirusCheck'][value='#{value ? 1 : 0}']").choose
147
+ page.find("[name='usesMailVirusCheck'][value='#{value ? 1 : 0}']").choose
128
148
  page.find(:xpath, '//button[text() = "保存する"]').click
129
149
  end
130
150
 
@@ -132,18 +152,18 @@ module Sakura
132
152
  end
133
153
 
134
154
  def enable_virus_scan
135
- virus_scan = true
155
+ true
136
156
  end
137
157
 
138
158
  def disable_virus_scan
139
- virus_scan = false
159
+ false
140
160
  end
141
161
 
142
162
  def keep(page = nil)
143
163
  if @keep.nil?
144
164
  # FIXME: The URL won't work when mail addresses are more than 300
145
165
  page ||= Client.current_session.get(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/)
146
- @keep = page.find('[name="receiveType"]:checked').value == '1'
166
+ @keep = page.find('[name="mailReceiveType"]:checked').value == '1'
147
167
  end
148
168
 
149
169
  @keep
@@ -152,7 +172,8 @@ module Sakura
152
172
  def keep=(value)
153
173
  # FIXME: The URL won't work when mail addresses are more than 300
154
174
  Client.current_session.process(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/) do |page|
155
- page.find("[name='receiveType'][value='#{value ? 1 : 2}']").choose
175
+ text = value ? '受信する' : '転送専用'
176
+ page.find(:xpath, "//label[contains(text(), \"メールの受信\")]/..//*[contains(text(), \"#{text}\")]/../input").choose
156
177
  page.find(:xpath, '//button[text() = "保存する"]').click
157
178
  end
158
179
 
@@ -160,11 +181,11 @@ module Sakura
160
181
  end
161
182
 
162
183
  def enable_keep
163
- keep = true
184
+ true
164
185
  end
165
186
 
166
187
  def disable_keep
167
- keep = false
188
+ false
168
189
  end
169
190
 
170
191
  def spam_filter(page = nil)
@@ -172,15 +193,20 @@ module Sakura
172
193
  # FIXME: The URL won't work when mail addresses are more than 300
173
194
  page ||= Client.current_session.get(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/)
174
195
 
175
- case page.find(:xpath, '//label[contains(text(), "迷惑メールフィルタ")]/..//select').value
176
- when "0"
196
+ case page.find("[name='spamFilterType']:checked").value
197
+ when '1'
177
198
  @spam_filter = :disable
178
- when "1"
179
- @spam_filter = :quarantine
180
- when "2"
181
- @spam_filter = :discard
182
- when "3"
183
- @spam_filter = :mark
199
+ when '2'
200
+ case page.find("[name='spamFilterAction']").value
201
+ when '1'
202
+ @spam_filter = :quarantine
203
+ when '2'
204
+ @spam_filter = :discard
205
+ when '3'
206
+ @spam_filter = :mark
207
+ end
208
+ when '3'
209
+ @spam_filter = :precise
184
210
  end
185
211
  end
186
212
 
@@ -190,20 +216,27 @@ module Sakura
190
216
  def spam_filter=(value)
191
217
  # FIXME: The URL won't work when mail addresses are more than 300
192
218
  Client.current_session.process(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/) do |page|
193
- select = page.find(:xpath, '//label[contains(text(), "迷惑メールフィルタ")]/..//select')
194
-
195
- value = value.to_sym
196
- case value
219
+ text = nil
220
+ action = nil
221
+ case value.to_sym
197
222
  when :disable
198
- select.select '利用しない'
223
+ text = '利用しない'
199
224
  when :quarantine
200
- select.select '「迷惑メール」フォルダに保存'
225
+ text = '簡易' # "迷惑メールフィルタ" doesn't work
226
+ action = '「迷惑メール」フォルダに保存 [推奨]'
201
227
  when :discard
202
- select.select 'メールを破棄'
228
+ text = '簡易' # "迷惑メールフィルタ" doesn't work
229
+ action = 'メールを破棄'
203
230
  when :mark
204
- select.select 'フィルタの利用'
231
+ text = '簡易' # "迷惑メールフィルタ" doesn't work
232
+ action = 'フィルタの利用'
233
+ when :precise
234
+ '高精度迷惑メールフィルタ'
205
235
  end
206
236
 
237
+ page.find(:xpath,
238
+ "//label[contains(text(), \"迷惑メールフィルタ\")]/..//*[contains(text(), \"#{text}\")]/../input").choose
239
+ page.find("[name='spamFilterAction']").select action if action
207
240
  page.find(:xpath, '//button[text() = "保存する"]').click
208
241
  end
209
242
 
@@ -252,32 +285,32 @@ module Sakura
252
285
  # FIXME: The URL won't work when mail addresses are more than 300
253
286
  page = Client.current_session.get(MAIL_URL + "1/edit/#{@address}", /#{@address}の設定/)
254
287
 
255
- <<-EOS
256
- usage / quota: #{usage} / #{quota} (#{percentage(@usage, @quota)})
257
- forward_to: #{forward_list(page).join(' ')}
258
- keep mail: #{keep(page)}
259
- virus scan: #{virus_scan(page)}
260
- spam filter: #{spam_filter(page)}
261
- EOS
288
+ <<~END_OF_STRING
289
+ usage / quota: #{usage} / #{quota} (#{percentage(@usage, @quota)})
290
+ forward_to: #{forward_list(page).join(' ')}
291
+ keep mail: #{keep(page)}
292
+ virus scan: #{virus_scan(page)}
293
+ spam filter: #{spam_filter(page)}
294
+ END_OF_STRING
262
295
  end
263
296
 
264
297
  private
265
298
 
266
299
  def percentage(usage, quota)
267
- usage, quota = [usage, quota].map { |i|
300
+ usage, quota = [usage, quota].map do |i|
268
301
  case i
269
302
  when /([\d.]+)TB$/
270
- $1.to_f * 1000000000000
303
+ ::Regexp.last_match(1).to_f * 1_000_000_000_000
271
304
  when /([\d.]+)GB$/
272
- $1.to_f * 1000000000
305
+ ::Regexp.last_match(1).to_f * 1_000_000_000
273
306
  when /([\d.]+)MB$/
274
- $1.to_f * 1000000
307
+ ::Regexp.last_match(1).to_f * 1_000_000
275
308
  when /([\d.]+)KB$/
276
- $1.to_f * 1000
309
+ ::Regexp.last_match(1).to_f * 1000
277
310
  when /([\d.]+)B$/
278
- $1.to_i
311
+ ::Regexp.last_match(1).to_i
279
312
  end
280
- }
313
+ end
281
314
 
282
315
  "#{(usage * 100 / quota).to_i}%"
283
316
  end
data/lib/sakura.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module Sakura
data/sakura-cli.gemspec CHANGED
@@ -1,28 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'sakura/cli/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "sakura-cli"
8
+ spec.name = 'sakura-cli'
8
9
  spec.version = Sakura::Cli::VERSION
9
- spec.authors = ["Shintaro Kojima"]
10
- spec.email = ["goodies@codeout.net"]
10
+ spec.authors = ['Shintaro Kojima']
11
+ spec.email = ['goodies@codeout.net']
11
12
 
12
- spec.summary = %q{Command-line tool for Sakura's Rental Server.}
13
- spec.description = %q{Command-line tool and client library to control the dashboard of Sakura Rental Server.}
14
- spec.homepage = "https://github.com/codeout/sakura-cli"
15
- spec.license = "MIT"
13
+ spec.summary = "Command-line tool for Sakura's Rental Server."
14
+ spec.description = 'Command-line tool and client library to control the dashboard of Sakura Rental Server.'
15
+ spec.homepage = 'https://github.com/codeout/sakura-cli'
16
+ spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|test|spec|features)/}) }
18
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
21
22
 
22
- spec.add_runtime_dependency "capybara"
23
- spec.add_runtime_dependency "selenium-webdriver"
24
- spec.add_runtime_dependency "thor"
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rake"
27
- spec.required_ruby_version = '>= 2.0.0'
23
+ spec.add_runtime_dependency 'capybara'
24
+ spec.add_runtime_dependency 'selenium-webdriver'
25
+ spec.add_runtime_dependency 'thor'
26
+ spec.required_ruby_version = '>= 3.0.0'
27
+ spec.metadata['rubygems_mfa_required'] = 'true'
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakura-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-09 00:00:00.000000000 Z
11
+ date: 2024-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -52,34 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
55
  description: Command-line tool and client library to control the dashboard of Sakura
84
56
  Rental Server.
85
57
  email:
@@ -90,10 +62,13 @@ extensions: []
90
62
  extra_rdoc_files: []
91
63
  files:
92
64
  - ".gitignore"
65
+ - ".pre-commit-config.yaml"
66
+ - ".rubocop.yml"
93
67
  - Gemfile
94
68
  - LICENSE.txt
95
69
  - README.md
96
70
  - Rakefile
71
+ - commitlint.config.cjs
97
72
  - exe/sakura
98
73
  - lib/sakura.rb
99
74
  - lib/sakura/cli/mail.rb
@@ -105,7 +80,8 @@ files:
105
80
  homepage: https://github.com/codeout/sakura-cli
106
81
  licenses:
107
82
  - MIT
108
- metadata: {}
83
+ metadata:
84
+ rubygems_mfa_required: 'true'
109
85
  post_install_message:
110
86
  rdoc_options: []
111
87
  require_paths:
@@ -114,14 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
90
  requirements:
115
91
  - - ">="
116
92
  - !ruby/object:Gem::Version
117
- version: 2.0.0
93
+ version: 3.0.0
118
94
  required_rubygems_version: !ruby/object:Gem::Requirement
119
95
  requirements:
120
96
  - - ">="
121
97
  - !ruby/object:Gem::Version
122
98
  version: '0'
123
99
  requirements: []
124
- rubygems_version: 3.3.7
100
+ rubygems_version: 3.4.1
125
101
  signing_key:
126
102
  specification_version: 4
127
103
  summary: Command-line tool for Sakura's Rental Server.