portal_scraper 1.9.0 → 1.9.1

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: 1645a898b4d02cea25387829c4aa64cbba4079548e4a3071c2dd36e38890e3a8
4
- data.tar.gz: 8d5ef9cc5da93c985773a63de9fcfdf196909357bcd69db414ccec45daab864d
3
+ metadata.gz: d3fb1ca99f014e8e2b70a56e0a5e5d85946854c59362025407366eb3c2fcf2cf
4
+ data.tar.gz: 385ced44a825c3c23fe963a27d666685df4943a69c25dd92e7d99d8d4f50f297
5
5
  SHA512:
6
- metadata.gz: bd9db17c4112d4247fe21cd37d71acde3da046ec54be8fd91d2977a14f55312ff1117b2f20c12eb20be5caa6dffc4c31f3e4d0ef2863bbc4e0336a2606700736
7
- data.tar.gz: 276da5c4531e01f87149e8e703658a9a0140c2808ec4c27e112445dd91e0556a88f3250048499c73d37bc012bc2b00d0fc6709d0f8360cf08eaa708478c1e571
6
+ metadata.gz: ce42252c1c6fc81ae34df080a3859e30070a5ceb1afff3363149a501d41172bdcf570005e217218ca60675d32aae33c24aac23b53479e6be5c91bf691add02d2
7
+ data.tar.gz: b1aff4808f6fd405b5a9f1a5eff0571954d0c5462fbf183c399eb398bae9b2b2f7e974f80ba0da405044240c712ace23c6f890543869530f07046d0213dad334
@@ -6,12 +6,11 @@ module PortalScraper
6
6
  Config = Struct.new(:root_url, :app_id, :secret, :login_url, :token_url)
7
7
 
8
8
  def self.configure
9
- raise ArgumentError.new('No block given') unless block_given?
9
+ raise ArgumentError, 'No block given' unless block_given?
10
+
10
11
  yield config
11
12
  end
12
13
 
13
- private
14
-
15
14
  def self.config
16
15
  @config ||= Config.new
17
16
  end
@@ -1,13 +1,11 @@
1
1
  require 'mechanize'
2
2
  require 'active_support/all'
3
- require_relative '../city_names_helper'
4
- require_relative '../number_helper'
3
+ require_relative '../parsing_helper'
5
4
 
6
5
  module PortalScraper
7
6
  module Accounts
8
7
  class Client
9
- include CityNamesHelper
10
- include NumberHelper
8
+ include ParsingHelper
11
9
  attr_accessor :app_id, :secret
12
10
 
13
11
  CODE_TO_COUNTRY_MAPPING = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'code_to_country.json')))
@@ -16,10 +14,10 @@ module PortalScraper
16
14
  def initialize(app_id = nil, secret = nil)
17
15
  @app_id = app_id || config.app_id
18
16
  @secret = secret || config.secret
19
- raise BadRootUrl unless config.root_url =~ URI::regexp
17
+ raise BadRootUrl unless config.root_url =~ URI::DEFAULT_PARSER.make_regexp
20
18
  end
21
19
 
22
- def get_accounts_balance
20
+ def scrap_accounts_balance
23
21
  login
24
22
  accounts_data = { accounts: [] }
25
23
 
@@ -32,19 +30,19 @@ module PortalScraper
32
30
  result = transfer.click
33
31
  result.search('table#operation tbody tr').each do |row|
34
32
  transfers << {
35
- operation_date: row.search('td[1]').text.strip.match(/\d{2}\/\d{2}\/\d{4}/).to_s,
36
- nature: row.search('td[2]').text.strip.gsub(/[\n,\t,'']/, ''),
37
- value_date: row.search('td[3]').text.strip.match(/\d{2}\/\d{2}\/\d{4}/).to_s,
38
- debit: format_number(row.search('td[4]')),
39
- credit: format_number(row.search('td[5]')),
33
+ operation_date: parse_date(row.search('td[1]')),
34
+ nature: row.search('td[2]').text.strip.gsub(/[\n,\t,'']/, ''),
35
+ value_date: parse_date(row.search('td[3]')),
36
+ debit: parse_number(row.search('td[4]')),
37
+ credit: parse_number(row.search('td[5]')),
40
38
  }
41
39
  end
42
40
  end
43
41
  accounts_data[:accounts] << {
44
- client_ref: find_table_value(account, 'Identifiant tiers'),
45
- balance: format_number(account.search('table#contrat th.n')),
46
- opened_on: account.search('table#contrat td').text.gsub(/\d{2}\/\d{2}\/\d{4}/)&.max,
47
- transfers: transfers
42
+ client_ref: find_table_value(account, 'Identifiant tiers'),
43
+ balance: parse_number(account.search('table#contrat th.n')),
44
+ opened_on: parse_dates(account.search('table#contrat td'))&.max,
45
+ transfers: transfers,
48
46
  }
49
47
  end
50
48
 
@@ -65,7 +63,7 @@ module PortalScraper
65
63
  form['commune'] = user[:codeInsee]
66
64
  form['libCommune'] = user[:ville]
67
65
  else
68
- fill_commune(app, form, user[:codePostal], format_city_name(user[:ville]), user[:pays] || user[:libNation])
66
+ fill_commune(app, form, user[:codePostal], parse_city_name(user[:ville]), user[:pays] || user[:libNation])
69
67
  end
70
68
  fill_address(form, user[:numeroVoie])
71
69
  fill_birth_place(form, user[:paysNaissance])
@@ -0,0 +1,19 @@
1
+ module PortalScraper
2
+ module ParsingHelper
3
+ def parse_city_name(node)
4
+ I18n.transliterate(node.upcase).gsub(/[^A-Z]/, ' ').sub(/\bSAINT\b/, 'ST')
5
+ end
6
+
7
+ def parse_number(node)
8
+ node.text.strip.gsub(/[[:space:]]+/, '').tr(',', '.').to_d
9
+ end
10
+
11
+ def parse_date(node)
12
+ parse_dates(node).first
13
+ end
14
+
15
+ def parse_dates(node)
16
+ node.text.strip.gsub(%r(\d{2}/\d{2}/\d{4}))
17
+ end
18
+ end
19
+ end
@@ -2,7 +2,7 @@ module PortalScraper
2
2
  class Version
3
3
  MAJOR = 1
4
4
  MINOR = 9
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].compact.join('.')
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
31
  spec.add_development_dependency 'vcr'
32
32
  spec.add_development_dependency 'webmock'
33
+ spec.add_development_dependency 'rubocop', '~> 0.67.2'
34
+ spec.add_development_dependency 'rubocop-performance'
33
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portal_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armand Mégrot
@@ -109,6 +109,34 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.67.2
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 0.67.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop-performance
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
112
140
  description: Scrapping client for extranet portals.
113
141
  email:
114
142
  - armand.megrot@gmail.com
@@ -122,8 +150,7 @@ files:
122
150
  - lib/portal_scraper/accounts/code_to_country.json
123
151
  - lib/portal_scraper/bad_login_url.rb
124
152
  - lib/portal_scraper/bad_root_url.rb
125
- - lib/portal_scraper/city_names_helper.rb
126
- - lib/portal_scraper/number_helper.rb
153
+ - lib/portal_scraper/parsing_helper.rb
127
154
  - lib/portal_scraper/portal_scraper_error.rb
128
155
  - lib/portal_scraper/version.rb
129
156
  - portal-scraper.gemspec
@@ -1,8 +0,0 @@
1
- module PortalScraper
2
- module CityNamesHelper
3
-
4
- def format_city_name(name)
5
- I18n.transliterate(name.upcase).gsub(/[^A-Z]/, ' ').sub(/\bSAINT\b/, 'ST')
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module PortalScraper
2
- module NumberHelper
3
-
4
- def format_number(number)
5
- number.text.strip.gsub(/[[:space:]]+/, '').tr(',', '.').to_d
6
- end
7
- end
8
- end