portal_scraper 1.1.2 → 1.2.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: 482837b19f398e53105bbff8bff9dba223a563da10db64f0a8b44a26e7ff7ace
4
- data.tar.gz: e3ba79a2d1b42e5e76b1d56142440b88b26c8fa76884ff3e6c3425a3bd2f9bf1
3
+ metadata.gz: 64ff22e3f3fc86f6db06fbee7fcef9f81e671c487eb9970eb200854b35d632ab
4
+ data.tar.gz: 95bd91bbbc537a433a0d0c9f8be8a772c12df3bd94d9663fbf46e1f253fb5549
5
5
  SHA512:
6
- metadata.gz: 4e977caf1916e017478fca710350ad31fb6f25b4511a10c396200aabc0e634cb3cefc54155f80458a09d79168ae266c716e942ac682a67d9f277e560cdedf56d
7
- data.tar.gz: a341421ec6f0ca479137673bfb1eebba78531ab99f2e30a7a1e78030f3880b0eb995d5c30aeb7eb805a8a697c49b9d8ce1d8da2489d1ee77e840cb3825b7c0a0
6
+ metadata.gz: 291bad49b4ea5774b82bccbb00668789e902b20939d41888961f72c739bf75a68e29d4055b03983cdd2ba6feb7de0d85410ceb848972c4f5c81e2cd30214d09a
7
+ data.tar.gz: 98e73d79dff179d8be8f5a02c6d671c2a9e60040dae0464f5ed0a05d0f85c6f59d861b8ed6e8310cefd3a40ade43a7276e0d0274ac226e2ab699e719c1dd182b
@@ -11,26 +11,6 @@ module PortalScraper
11
11
  raise BadRootUrl unless config.root_url =~ URI::regexp
12
12
  end
13
13
 
14
- def try_form_fields(form, fields, value)
15
- fields.each do |field|
16
- if form.has_field?(field)
17
- form[field] = value
18
- break
19
- end
20
- end
21
- end
22
-
23
- def login
24
- raise BadLoginUrl if config.login_url.nil?
25
- app.get(url_for(config.login_url)) do |login_page|
26
- form = login_page.form_with(name: /login/i) || login_page.forms[0]
27
- try_form_fields(form, %w(username login), app_id)
28
- try_form_fields(form, %w(password secret), secret)
29
- form.submit
30
- end
31
- app.get(url_for(config.token_url)) unless config.token_url.nil?
32
- end
33
-
34
14
  def get_accounts_balance
35
15
  login
36
16
  accounts_data = { accounts: [] }
@@ -45,6 +25,26 @@ module PortalScraper
45
25
  accounts_data
46
26
  end
47
27
 
28
+ def create_account(user)
29
+ login
30
+ app.get(url_for('/appTiersCreation.do')) do |create_page|
31
+ create_page.form_with(name: /(create|creation)/i) do |form|
32
+ form.fields.each { |f| try_form_fields(form, [f.name], user[f.name.to_sym]) }
33
+ fill_commune(app, form, user[:codePostal], user[:ville])
34
+ form['modeContact'] = ''
35
+ form['creerTiers'] = 'Créer'
36
+ form.submit
37
+ result_page = app.post(url_for('/appTiersCreation.do'), { confirmer: 'Confirmer' })
38
+ if result_page.uri.path =~ /error.do/
39
+ return { error: 'Missing data' }
40
+ else
41
+ return { client_ref: result_page.search('td.ZMSG').text.split(':')[1].strip }
42
+ end
43
+ end
44
+ end
45
+ nil
46
+ end
47
+
48
48
  private
49
49
 
50
50
  def app
@@ -55,6 +55,33 @@ module PortalScraper
55
55
  [config.root_url, path].join
56
56
  end
57
57
 
58
+ def login
59
+ raise BadLoginUrl if config.login_url.nil?
60
+ app.get(url_for(config.login_url)) do |login_page|
61
+ form = login_page.form_with(name: /login/i) || login_page.forms[0]
62
+ try_form_fields(form, %w(username login), app_id)
63
+ try_form_fields(form, %w(password secret), secret)
64
+ form.submit
65
+ end
66
+ app.get(url_for(config.token_url)) unless config.token_url.nil?
67
+ end
68
+
69
+ def try_form_fields(form, fields, value)
70
+ fields.each do |field|
71
+ if form.has_field?(field)
72
+ form[field] = value
73
+ break
74
+ end
75
+ end
76
+ end
77
+
78
+ def fill_commune(app, form, postal_code, city)
79
+ app.post(url_for('/tiersCommunes.do'), { codPos: postal_code }).tap do |mappings|
80
+ code = mappings.search('td.t').find { |c| c.text.strip == city }.parent.search('a.PL_LST').text.strip
81
+ form['commune'] = code
82
+ end
83
+ end
84
+
58
85
  def find_table_value(node, column_name)
59
86
  node.search('td.CA_LABEL').find { |column| column.text.strip == column_name }.parent.search('td.CA_LIB').text.strip
60
87
  end
@@ -1,8 +1,8 @@
1
1
  module PortalScraper
2
2
  class Version
3
3
  MAJOR = 1
4
- MINOR = 1
5
- PATCH = 2
4
+ MINOR = 2
5
+ PATCH = 0
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].compact.join('.')
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.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armand Mégrot