portal_scraper 1.4.3 → 1.5.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: 8fe0c3b20498468f4f56baacec71d686cace1aae23ad6b1898f61da8e9d3ce9c
4
- data.tar.gz: 7e0f1d3b2072b61a40c9520a0c69c45a520073342b76523599b4d2cae08f5522
3
+ metadata.gz: 8825ed756349c40d08302537a67c019f92eacdbb9765f9e29175839216cb7a60
4
+ data.tar.gz: 15a5c317d86916cdcf36d28db34060582f23ebbdbf79b36cbc82ebf02b24ac45
5
5
  SHA512:
6
- metadata.gz: 419806c515b49957b154fd27a5a32efbb3e04ff5a66d0203950766d3a713e6e16246b2951507c2f293f2be9d839dbe7a02b1240fc33a49902f05561be7190976
7
- data.tar.gz: 8f5220886703936463c30ce27b1fa5979fe79a76930ea67408a2c9dc890fef5a2f4f2e59aecaaecdbe80e0faaa839f3672b6133345c58801735e2da28d1dec8e
6
+ metadata.gz: df5de7debdf23d19ae2d502fdae82c76842dea86452b70202d177bac631799199cc3d7bbebf2287b7d66897ffeb80a935b6f7b2c72b70c2607e696cff8f83979
7
+ data.tar.gz: f9aeca9291c8a5c57b0cd56fc5a9879b11d18e4c2f889136711011a633f8863d9181292d6c0a3cec1e5d3495c0e1bd64bcd0d33ec1e7bde5ae0befbe43e3d355
@@ -1,8 +1,11 @@
1
1
  require 'mechanize'
2
+ require 'active_support/all'
3
+ require_relative '../city_names_helper'
2
4
 
3
5
  module PortalScraper
4
6
  module Accounts
5
7
  class Client
8
+ include CityNamesHelper
6
9
  attr_accessor :app_id, :secret
7
10
 
8
11
  CODE_TO_COUNTRY_MAPPING = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'code_to_country.json')))
@@ -37,7 +40,7 @@ module PortalScraper
37
40
  form['commune'] = user[:codeInsee]
38
41
  form['libCommune'] = user[:ville]
39
42
  else
40
- fill_commune(app, form, user[:codePostal], user[:ville].gsub('-', ' ').upcase.sub('SAINT', 'ST'))
43
+ fill_commune(app, form, user[:codePostal], format_city_name(user[:ville]))
41
44
  end
42
45
  fill_birth_place(form, user[:paysNaissance])
43
46
  form['modeContact'] = ''
@@ -118,10 +121,10 @@ module PortalScraper
118
121
 
119
122
  def fill_commune(app, form, postal_code, city)
120
123
  app.post(url_for('/tiersCommunes.do'), { codPos: postal_code }).tap do |mappings|
121
- mapping = mappings.search('td.t').find { |c| c.text.strip.include?(city) }
122
- code = mapping&.parent.search('a.PL_LST').text.strip
123
- form['commune'] = code
124
- form['libCommune'] = mapping&.text.strip
124
+ cities = mappings.search('td.t').map { |c| { code: c.parent.search('a.PL_LST').text.strip, name: c.text.strip } }
125
+ matched_city = cities.find(-> { cities.first }) { |c| c[:name].include?(city) }
126
+ form['commune'] = matched_city[:code]
127
+ form['libCommune'] = matched_city[:name]
125
128
  end
126
129
  end
127
130
 
@@ -0,0 +1,8 @@
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 +1,8 @@
1
1
  module PortalScraper
2
2
  class Version
3
3
  MAJOR = 1
4
- MINOR = 4
5
- PATCH = 3
4
+ MINOR = 5
5
+ PATCH = 0
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].compact.join('.')
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = '>= 2.5.3'
24
24
 
25
25
  spec.add_dependency 'mechanize', '~> 2.7'
26
+ spec.add_dependency 'activesupport', '~> 5.2'
26
27
 
27
28
  spec.add_development_dependency 'rspec', '~> 3.2'
28
29
  spec.add_development_dependency 'bundler', '~> 1.16'
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.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armand Mégrot
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-21 00:00:00.000000000 Z
12
+ date: 2019-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '5.2'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rspec
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,7 @@ files:
108
122
  - lib/portal_scraper/accounts/code_to_country.json
109
123
  - lib/portal_scraper/bad_login_url.rb
110
124
  - lib/portal_scraper/bad_root_url.rb
125
+ - lib/portal_scraper/city_names_helper.rb
111
126
  - lib/portal_scraper/portal_scraper_error.rb
112
127
  - lib/portal_scraper/version.rb
113
128
  - portal-scraper.gemspec