ehbrs_ruby_utils 0.50.0 → 0.50.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab0154fa6393d2e1f167cae506bdd5fbf7b5a107feb7f059625cb1929c44d3a4
4
- data.tar.gz: a709b36805a65f3d2ecdd69dc1cf7c830536f8a7d1ab9dbd228995a918c19ad4
3
+ metadata.gz: 313577609ee6eb941fe4555a69dd45857adabbe01969cabf59c3fae4021aa07c
4
+ data.tar.gz: d23750e408c10e7724fb7292504a601ff6d8118823f881ff6f41f9febaca4fee
5
5
  SHA512:
6
- metadata.gz: 213af97b1e0ef6399fa12ebb3adfe378a1f192bc63f55b40b00359cd26aba7e1f67921068ff3fab29f2ed039abf0cc24fd9fd0ed63128e8f292f5d678dfa9814
7
- data.tar.gz: '08ff1d66a9ac6a2e09c83090e073295f81dbdfc30adb10d85860e184197b9249465e0bc86dec1e59354e4a0e9edcc65c9aa904509926c84db8b4ce32868ef338'
6
+ metadata.gz: 11dadee80b32212622c880e31c379cae640df69cb101b77d51fe5de0e89753ce879705615f2bc1c4e0eda9a4c7e0b3bd9e6ef68482817642d41a77c6bad06256
7
+ data.tar.gz: 7e1628e39e81cfc507bf1151cd7ae89e9c5a28ecf4a7187971cc1a7f00eed40cc153ce22abb5dc25153d52ecb07eda21eef1150b5c72cd73de528efec48c5ca5
@@ -69,7 +69,7 @@ module EhbrsRubyUtils
69
69
  # @param prices [Enumerable<Float, nil>]
70
70
  # @return [Float]
71
71
  def build_price(*prices)
72
- prices.reject(&:blank?).min
72
+ prices.reject(&:blank?).min # rubocop:disable Rails/CompactBlank
73
73
  end
74
74
 
75
75
  # @param text [String]
@@ -7,6 +7,7 @@ module EhbrsRubyUtils
7
7
  DEFAULT_STATUS = 'asyncplay'
8
8
  ID_PARSER = /table=(\d+)/.to_parser { |m| m[1].to_i }
9
9
  ITEMS_XPATH = '//*[@id = "section-play"]//a[contains(@href, "table=")]'
10
+ NO_TABLES_XPATH = '//p[normalize-space(text()) = "Nenhum jogo em andamento"]'
10
11
  STATUS_CLASS_PATTERN = /\Agametable_status_(.+)\z/
11
12
  STATUS_CLASS_PARSER = STATUS_CLASS_PATTERN.to_parser { |m| m[1] }
12
13
  TABLE_COUNT_XPATH =
@@ -37,7 +38,17 @@ module EhbrsRubyUtils
37
38
 
38
39
  # @return [Integer]
39
40
  def table_count
40
- nokogiri.at_xpath(TABLE_COUNT_XPATH).if_present(-1) { |v| v.text.to_i }
41
+ nokogiri.at_xpath(TABLE_COUNT_XPATH).if_present(no_tables_count) { |v| v.text.to_i }
42
+ end
43
+
44
+ # @return [Integer]
45
+ def no_tables_count
46
+ no_tables? ? 0 : -1
47
+ end
48
+
49
+ # @return [Boolean]
50
+ def no_tables?
51
+ nokogiri.at_xpath(NO_TABLES_XPATH).present?
41
52
  end
42
53
  end
43
54
  end
@@ -15,7 +15,8 @@ module EhbrsRubyUtils
15
15
  field :name, :string, './div[@class = "name"]/a/text()'
16
16
  field :score, :integer_optional, './div[@class = "score"]'
17
17
  field :elo_increment, :string, './/*[starts-with(@id, "winpoints_value_")]/text()'
18
- field :elo_reached, :integer_optional, './/*[@class = "gamerank_value"]/text()'
18
+ field :elo_reached, :integer_optional,
19
+ './/*[normalize-space(@class) = "gamerank_value"]/text()'
19
20
  field :penalty_clock, :boolean,
20
21
  './/*[@class = "clockpenalty" and @style = "display: inline;"]'
21
22
  field :penalty_leave, :boolean,
@@ -4,7 +4,7 @@ module EhbrsRubyUtils
4
4
  module Bga
5
5
  module Parsers
6
6
  class Table < ::Aranha::Parsers::Html::Item
7
- GAME_IMAGE_URL_PARSER = %r{/gamemedia/([^/]+)/box/}.to_parser { |m| m[1] }
7
+ GAME_IMAGE_URL_PARSER = %r{/gamemedia/([^/]+)/}.to_parser { |m| m[1] }
8
8
  ITEM_XPATH = '/'
9
9
  PLAYERS_IDS = {
10
10
  'game_result' => ::EhbrsRubyUtils::Bga::Parsers::Table::EndedPlayers,
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbrsRubyUtils
4
+ module Bga
5
+ class Session < ::SimpleDelegator
6
+ module CookiesConsent
7
+ REJECT_ALL_BUTTON_SELECTOR = { id: 'didomi-notice-disagree-button' }.freeze
8
+ REJECT_ALL_BUTTON_TIMEOUT = 5
9
+
10
+ # @return [void]
11
+ def dismiss_cookies_banner
12
+ wait_for_click(REJECT_ALL_BUTTON_SELECTOR, REJECT_ALL_BUTTON_TIMEOUT)
13
+ rescue ::Selenium::WebDriver::Error::TimeoutError
14
+ nil
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,14 +5,21 @@ module EhbrsRubyUtils
5
5
  class Session < ::SimpleDelegator
6
6
  module Login
7
7
  LOGIN_PATH = 'account'
8
- USERNAME_INPUT_ID = 'username_input'
9
- PASSWORD_INPUT_ID = 'password_input'
10
- SUBMIT_ID = 'login_button'
8
+ STEP1_SELECTOR = { css: '.bga-account-manager-form__step1' }.freeze
9
+ STEP2_SELECTOR = { css: '.bga-account-manager-form__step2' }.freeze
10
+ EMAIL_INPUT_SELECTOR = { css: "#{STEP1_SELECTOR[:css]} input[name=\"email\"]" }.freeze
11
+ NEXT_BUTTON_SELECTOR = { css: "#{STEP1_SELECTOR[:css]} a.bga-button--blue" }.freeze
12
+ PASSWORD_INPUT_SELECTOR = {
13
+ css: "#{STEP2_SELECTOR[:css]} input[type=\"password\"]"
14
+ }.freeze
15
+ LOGIN_BUTTON_SELECTOR = { css: "#{STEP2_SELECTOR[:css]} a.bga-button--blue" }.freeze
16
+ URL_LOGIN_PAGE_COMPONENT = 'page=login'
11
17
 
12
18
  # @return [Boolean]
13
19
  def login # rubocop:disable Naming/PredicateMethod
14
20
  navigate_to_login_page
15
21
  input_username
22
+ submit_username
16
23
  input_password
17
24
  submit_login
18
25
  logged?
@@ -26,18 +33,29 @@ module EhbrsRubyUtils
26
33
 
27
34
  def navigate_to_login_page
28
35
  navigate.to(login_url)
36
+ dismiss_cookies_banner
29
37
  end
30
38
 
31
39
  def input_username
32
- wait_for_element(id: USERNAME_INPUT_ID).send_keys(username)
40
+ wait_for_element(EMAIL_INPUT_SELECTOR).send_keys(username)
41
+ end
42
+
43
+ def submit_username
44
+ wait_for_click(NEXT_BUTTON_SELECTOR)
33
45
  end
34
46
 
35
47
  def input_password
36
- wait_for_element(id: PASSWORD_INPUT_ID).send_keys(password)
48
+ wait_for_element(PASSWORD_INPUT_SELECTOR).send_keys(password)
37
49
  end
38
50
 
51
+ # @return [void]
39
52
  def submit_login
40
- wait_for_click(id: SUBMIT_ID)
53
+ wait_for_click(LOGIN_BUTTON_SELECTOR)
54
+ begin
55
+ wait.until { current_url.exclude?(URL_LOGIN_PAGE_COMPONENT) }
56
+ rescue ::Selenium::WebDriver::Error::TimeoutError
57
+ nil
58
+ end
41
59
  end
42
60
  end
43
61
  end
@@ -17,12 +17,13 @@ module EhbrsRubyUtils
17
17
  e
18
18
  end
19
19
 
20
- def on_skip_trophies(...)
21
- error = on_rescue_timeout(...)
20
+ def on_skip_trophies(&block)
21
+ error = on_rescue_timeout(&block)
22
22
  return unless error
23
23
  raise error unless skip_trophy_overlay?
24
24
 
25
25
  skip_trophies
26
+ block.call
26
27
  end
27
28
 
28
29
  def skip_trophies
@@ -10,9 +10,9 @@ module EhbrsRubyUtils
10
10
  logged_username == username
11
11
  end
12
12
 
13
- # @return [String]
13
+ # @return [String, nil]
14
14
  def logged_username
15
- find_or_not_element(xpath: '//*[@id = "connected_username"]').attribute('innerHTML').strip
15
+ find_or_not_element(xpath: '//*[@id = "real_player_name"]')&.attribute('innerHTML')&.strip
16
16
  end
17
17
 
18
18
  def on_logged(&block)
@@ -8,7 +8,7 @@ module EhbrsRubyUtils
8
8
  enable_simple_cache
9
9
  common_constructor :data
10
10
 
11
- GAME_MODE_KEY = 'Modo de Jogo'
11
+ GAME_MODE_KEYS = ['Modo do jogo', 'Modo de Jogo'].freeze
12
12
  GAME_MODE_FRIENDLY_VALUE = 'Modo Amigável'
13
13
  GAME_MODE_NORMAL_VALUE = 'Modo Normal'
14
14
  SET_ITEMS = %i[options players].freeze
@@ -22,11 +22,11 @@ module EhbrsRubyUtils
22
22
 
23
23
  # @return [Boolean]
24
24
  def friendly?
25
- value = option_value(GAME_MODE_KEY)
25
+ value = game_mode_value
26
26
  return true if value == GAME_MODE_FRIENDLY_VALUE
27
27
  return false if value == GAME_MODE_NORMAL_VALUE
28
28
 
29
- raise "Unknown \"#{GAME_MODE_KEY}\" value: \"#{value}\""
29
+ raise "Unknown value for game mode: \"#{value}\" (Options: #{options_to_s})"
30
30
  end
31
31
 
32
32
  # @return [Boolean]
@@ -34,6 +34,18 @@ module EhbrsRubyUtils
34
34
  game_conceded
35
35
  end
36
36
 
37
+ # @return [String]
38
+ def game_mode_value
39
+ GAME_MODE_KEYS.lazy.map { |k| option_value(k) }.find(&:present?) ||
40
+ raise("No option found with one of the labels #{GAME_MODE_KEYS} " \
41
+ "(Options: #{options_to_s})")
42
+ end
43
+
44
+ # @return [String]
45
+ def options_to_s
46
+ options.map { |o| "#{o.label}=\"#{o.value}\"" }.join(', ')
47
+ end
48
+
37
49
  # @param key [String]
38
50
  # @return [String, nil]
39
51
  def option_value(label)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.50.0'
4
+ VERSION = '0.50.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.50.0
4
+ version: 0.50.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
@@ -49,20 +49,14 @@ dependencies:
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: '0.14'
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: 0.14.1
52
+ version: '0.15'
56
53
  type: :runtime
57
54
  prerelease: false
58
55
  version_requirements: !ruby/object:Gem::Requirement
59
56
  requirements:
60
57
  - - "~>"
61
58
  - !ruby/object:Gem::Version
62
- version: '0.14'
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: 0.14.1
59
+ version: '0.15'
66
60
  - !ruby/object:Gem::Dependency
67
61
  name: avm
68
62
  requirement: !ruby/object:Gem::Requirement
@@ -292,6 +286,7 @@ files:
292
286
  - lib/ehbrs_ruby_utils/bga/parsers/table/options.rb
293
287
  - lib/ehbrs_ruby_utils/bga/player.rb
294
288
  - lib/ehbrs_ruby_utils/bga/session.rb
289
+ - lib/ehbrs_ruby_utils/bga/session/cookies_consent.rb
295
290
  - lib/ehbrs_ruby_utils/bga/session/login.rb
296
291
  - lib/ehbrs_ruby_utils/bga/session/player.rb
297
292
  - lib/ehbrs_ruby_utils/bga/session/player_tables_on_game_in_progress.rb